Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0b622fe3e635e7a4e67638a9a43cb4fffc7f1121
[simgrid.git] / examples / java / mutualExclusion / Node.java
1 /* Copyright (c) 2012-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 package mutualExclusion;
8
9 import org.simgrid.msg.Host;
10 import org.simgrid.msg.Msg;
11 import org.simgrid.msg.MsgException;
12 import org.simgrid.msg.Task;
13 import org.simgrid.msg.Process;
14
15 public class Node extends Process {
16     public Node(Host host, String name, String[]args) {
17                 super(host,name,args);
18     } 
19         public void request(double CStime) throws MsgException {
20                 RequestTask req = new RequestTask(this.name);
21            Msg.info("Send a request to the coordinator");
22                 req.send("coordinator");
23            Msg.info("Wait for a grant from the coordinator");
24                 Task.receive(this.name); // FIXME: ensure that this is a grant
25                 Task compute = new Task("CS", CStime, 0);
26                 compute.execute();
27                 ReleaseTask release = new ReleaseTask();
28                 release.send("coordinator");
29         }
30         
31         public void main(String[] args) throws MsgException {
32                 request(Double.parseDouble(args[1]));
33         }
34 }