Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8f79d8e82ef8c1e25907f240a2dea1d2658a91bb
[simgrid.git] / examples / mutualExclusion / centralized / Node.java
1 /*
2  * $Id$
3  *
4  * Copyright 2010. The SimGrid Team. All rights reserved. 
5  *
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. 
8  */
9 package mutualExclusion.centralized;
10
11 import org.simgrid.msg.Msg;
12 import org.simgrid.msg.MsgException;
13 import org.simgrid.msg.Task;
14 import org.simgrid.msg.Process;
15
16 public class Node extends Process {
17         public Node(String hostname, String name) throws HostNotFoundException {
18                 super(hostname, name);
19         }
20         public void request(double CStime) throws MsgException {
21                 RequestTask req = new RequestTask(this.name);
22            Msg.info("Send a request to the coordinator");
23                 req.send("coordinator");
24            Msg.info("Wait for a grant from the coordinator");
25                 Task.receive(this.name); // FIXME: ensure that this is a grant
26                 Task compute = new Task("CS", CStime, 0);
27                 compute.execute();
28                 ReleaseTask release = new ReleaseTask();
29                 release.send("coordinator");
30         }
31         
32         public void main(String[] args) throws MsgException {
33                 request(Double.parseDouble(args[1]));
34         }
35 }