X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/49e85177c669d793e84242983a1b1f430e47184e..993ac086676ec73f49a46e389467ed005c2707c3:/examples/java/mutualExclusion/Coordinator.java diff --git a/examples/java/mutualExclusion/Coordinator.java b/examples/java/mutualExclusion/Coordinator.java index 7a0e0a679e..f605279144 100644 --- a/examples/java/mutualExclusion/Coordinator.java +++ b/examples/java/mutualExclusion/Coordinator.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2014. The SimGrid Team. +/* Copyright (c) 2012-2014, 2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -7,45 +7,44 @@ package mutualExclusion; import java.util.LinkedList; -import org.simgrid.msg.Host; import org.simgrid.msg.Msg; -import org.simgrid.msg.MsgException; +import org.simgrid.msg.Host; import org.simgrid.msg.Task; import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; +public class Coordinator extends Process { + public Coordinator(Host host, String name, String[]args) { + super(host,name,args); + } + LinkedList waitingQueue=new LinkedList(); + int CsToServe; -public class Coordinator extends Process { - public Coordinator(Host host, String name, String[]args) { - super(host,name,args); - } - LinkedList waitingQueue=new LinkedList(); - int CsToServe; - - public void main(String[] args) throws MsgException { - CsToServe = Integer.parseInt(args[0]); - Task task; - while (CsToServe >0) { - task = Task.receive("coordinator"); - if (task instanceof RequestTask) { - RequestTask t = (RequestTask) task; - if (waitingQueue.isEmpty()) { - Msg.info("Got a request from "+t.from+". Queue empty: grant it"); - GrantTask tosend = new GrantTask(); - tosend.send(t.from); - } else { - waitingQueue.addFirst(t); - } - } else if (task instanceof ReleaseTask) { - if (!waitingQueue.isEmpty()) { - RequestTask req = waitingQueue.removeLast(); - GrantTask tosend = new GrantTask(); - tosend.send(req.from); - } - CsToServe--; - if (waitingQueue.isEmpty() && CsToServe==0) { - Msg.info("we should shutdown the simulation now"); - } - } - } - } + public void main(String[] args) throws MsgException { + CsToServe = Integer.parseInt(args[0]); + Task task; + while (CsToServe >0) { + task = Task.receive("coordinator"); + if (task instanceof RequestTask) { + RequestTask t = (RequestTask) task; + if (waitingQueue.isEmpty()) { + Msg.info("Got a request from "+t.from+". Queue empty: grant it"); + GrantTask tosend = new GrantTask(); + tosend.send(t.from); + } else { + waitingQueue.addFirst(t); + } + } else if (task instanceof ReleaseTask) { + if (!waitingQueue.isEmpty()) { + RequestTask req = waitingQueue.removeLast(); + GrantTask tosend = new GrantTask(); + tosend.send(req.from); + } + CsToServe--; + if (waitingQueue.isEmpty() && CsToServe==0) { + Msg.info("we should shutdown the simulation now"); + } + } + } + } }