X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5b3677b425b9cc6949c1573d59ac772540cbf4b2..4a6b0a991a67e6f2f67c03fed43529e078da7115:/examples/java/async/Slave.java diff --git a/examples/java/async/Slave.java b/examples/java/async/Slave.java index 1d4f5679cc..3d32d2a0e2 100644 --- a/examples/java/async/Slave.java +++ b/examples/java/async/Slave.java @@ -1,67 +1,64 @@ -/* Copyright (c) 2006-2007, 2010, 2013-2014. The SimGrid Team. +/* Copyright (c) 2006-2007, 2010, 2013-2014, 2016. 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. */ package async; +import org.simgrid.msg.Msg; import org.simgrid.msg.Comm; import org.simgrid.msg.Host; -import org.simgrid.msg.HostFailureException; -import org.simgrid.msg.Msg; -import org.simgrid.msg.Process; import org.simgrid.msg.Task; +import org.simgrid.msg.Process; +import org.simgrid.msg.HostFailureException; import org.simgrid.msg.TaskCancelledException; import org.simgrid.msg.TimeoutException; import org.simgrid.msg.TransferFailureException; public class Slave extends Process { - public Slave(Host host, String name, String[]args) { - super(host,name,args); - } - public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException { - if (args.length < 1) { - Msg.info("Slave needs 1 argument (its number)"); - System.exit(1); - } + public Slave(Host host, String name, String[]args) { + super(host,name,args); + } + + public void main(String[] args) throws TransferFailureException, HostFailureException, TimeoutException { + if (args.length < 1) { + Msg.info("Slave needs 1 argument (its number)"); + System.exit(1); + } + int num = Integer.valueOf(args[0]).intValue(); + Comm comm = null; + boolean slaveFinished = false; + while(!slaveFinished) { + try { + if (comm == null) { + Msg.info("Receiving on 'slave_" + num + "'"); + comm = Task.irecv("slave_" + num); + } else { + if (comm.test()) { + Task task = comm.getTask(); - int num = Integer.valueOf(args[0]).intValue(); - Comm comm = null; - boolean slaveFinished = false; - while(!slaveFinished) { - try - { - if (comm == null) { - Msg.info("Receiving on 'slave_" + num + "'"); - comm = Task.irecv("slave_" + num); - } - else { - if (comm.test()) { - Task task = comm.getTask(); - - if (task instanceof FinalizeTask) { - comm = null; - break; - } - Msg.info("Received a task"); - Msg.info("Received \"" + task.getName() + "\". Processing it."); - try { - task.execute(); - } catch (TaskCancelledException e) { - - } - comm = null; - } - else { - waitFor(1); - } - } - } - catch (Exception e) { - e.printStackTrace(); - } - } - Msg.info("Received Finalize. I'm done. See you!"); - waitFor(20); - } + if (task instanceof FinalizeTask) { + comm = null; + break; + } + Msg.info("Received a task"); + Msg.info("Received \"" + task.getName() + "\". Processing it."); + try { + task.execute(); + } catch (TaskCancelledException e) { + + } + comm = null; + } else { + waitFor(1); + } + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + Msg.info("Received Finalize. I'm done. See you!"); + waitFor(20); + } } \ No newline at end of file