Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
511a95d96a3ef9bcf46577582458fc6b7d07bd97
[simgrid.git] / examples / java / app / centralizedmutex / Node.java
1 /* Copyright (c) 2012-2014, 2016. 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 app.centralizedmutex;
8
9 import org.simgrid.msg.Msg;
10 import org.simgrid.msg.Host;
11 import org.simgrid.msg.Task;
12 import org.simgrid.msg.Process;
13 import org.simgrid.msg.MsgException;
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(getName());
21     GrantTask grant= new GrantTask();;
22     Msg.info("Send a request to the coordinator");
23     req.send("coordinator");
24     Msg.info("Wait for a grant from the coordinator");
25     grant.receive(getName());
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 }