4 * Copyright 2010. The SimGrid Team. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package.
10 import java.util.LinkedList;
12 import simgrid.msg.Msg;
13 import simgrid.msg.MsgException;
14 import simgrid.msg.Task;
16 public class Coordinator extends simgrid.msg.Process {
18 LinkedList<RequestTask> waitingQueue=new LinkedList<RequestTask>();
21 public void main(String[] args) throws MsgException {
22 CsToServe = Integer.parseInt(args[0]);
24 while (CsToServe >0) {
25 task = Task.receive("coordinator");
26 if (task instanceof RequestTask) {
27 RequestTask t = (RequestTask) task;
28 if (waitingQueue.isEmpty()) {
29 Msg.info("Got a request from "+t.from+". Queue empty: grant it");
30 GrantTask tosend = new GrantTask();
35 } else if (task instanceof ReleaseTask) {
36 if (!waitingQueue.isEmpty()) {
37 RequestTask req = waitingQueue.removeLast();
38 GrantTask tosend = new GrantTask();
39 tosend.send(req.from);
42 if (waitingQueue.isEmpty() && CsToServe==0) {
43 Msg.info("we should shutdown the simulation now");