From 3c1ff15bb85c72dfc067d6da8da2e0ccc799e09d Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 21 Mar 2017 11:26:30 +0100 Subject: [PATCH] java example simplification + reindent + cosmetics --- examples/java/app/pingpong/PingPongTask.java | 11 ++--- examples/java/app/pingpong/Sender.java | 51 +++++++------------- 2 files changed, 22 insertions(+), 40 deletions(-) diff --git a/examples/java/app/pingpong/PingPongTask.java b/examples/java/app/pingpong/PingPongTask.java index c41512779d..45d85bd108 100644 --- a/examples/java/app/pingpong/PingPongTask.java +++ b/examples/java/app/pingpong/PingPongTask.java @@ -1,5 +1,4 @@ -/* Copyright (c) 2006-2014, 2016. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -14,12 +13,10 @@ public class PingPongTask extends Task { this.timeVal = 0; } - public PingPongTask(String name, double computeDuration, double messageSize) { + public PingPongTask(String name, double computeDuration, double messageSize, double timeVal) { super(name,computeDuration,messageSize); - } - - public void setTime(double timeVal) { - this.timeVal = timeVal; + + this.timeVal = timeVal; } public double getTime() { diff --git a/examples/java/app/pingpong/Sender.java b/examples/java/app/pingpong/Sender.java index d3520690ac..d6ec213709 100644 --- a/examples/java/app/pingpong/Sender.java +++ b/examples/java/app/pingpong/Sender.java @@ -1,5 +1,4 @@ - /* Copyright (c) 2006-2014, 2016. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -12,43 +11,29 @@ import org.simgrid.msg.MsgException; import org.simgrid.msg.Process; public class Sender extends Process { - private static final double COMM_SIZE_LAT = 1; + private static final double COMM_SIZE_LAT = 1; - public Sender(String hostname, String name, String[] args) throws HostNotFoundException { - super(hostname,name,args); - } + public Sender(String hostname, String name, String[] args) throws HostNotFoundException { + super(hostname,name,args); + } - public void main(String[] args) throws MsgException { - Msg.info("hello!"); + public void main(String[] args) throws MsgException { + Msg.info("hello!"); - int hostCount = args.length; + Msg.info("host count: " + args.length); - Msg.info("host count: " + hostCount); - String[] mailboxes = new String[hostCount]; - double time; - double computeDuration = 0; - PingPongTask task; + for(int pos = 0; pos < args.length ; pos++) { + String hostname = Host.getByName(args[pos]).getName(); // Make sure that this host exists + + double time = Msg.getClock(); - for(int pos = 0; pos < args.length ; pos++) { - try { - mailboxes[pos] = Host.getByName(args[pos]).getName(); - } catch (HostNotFoundException e) { - e.printStackTrace(); - Msg.info("Invalid deployment file: " + e.toString()); - } - } + Msg.info("sender time: " + time); - for (int pos = 0; pos < hostCount; pos++) { - time = Msg.getClock(); + PingPongTask task = new PingPongTask("no name", /* Duration: 0 flops */ 0, COMM_SIZE_LAT, time); - Msg.info("sender time: " + time); + task.send(hostname); + } - task = new PingPongTask("no name",computeDuration,COMM_SIZE_LAT); - task.setTime(time); - - task.send(mailboxes[pos]); - } - - Msg.info("goodbye!"); - } + Msg.info("goodbye!"); + } } \ No newline at end of file -- 2.20.1