コード例 #1
0
ファイル: EDMongering.java プロジェクト: naser-ayat/bol1
 ProtocolData(String prefix) {
   pid = CommonState.getPid();
   lid = Configuration.getPid(prefix + "." + PAR_LINKABLE);
   tid = Configuration.getPid(prefix + "." + PAR_TRANSPORT);
   period = Configuration.getInt(prefix + "." + PAR_PERIOD);
   prob = Configuration.getDouble(prefix + "." + PAR_PROB);
 }
コード例 #2
0
ファイル: HelloWorld.java プロジェクト: JEC2000/Projet_ARA
 // methode appelee lorsqu'un message est recu par le protocole HelloWorld du noeud
 public void processEvent(Node node, int pid, Object event) {
   if (((Message) event).getType() == Message.APP_UPDATE) {
     this.state++;
     this.log("APP Update " + this.state);
     if (CommonState.r.nextInt(10) < 5) { // On envoie un message a un noeud aleatoire
       this.send(
           new Message(Message.APP_MSG, "APP MSG " + this.nodeId + "-" + this.state),
           Network.get(CommonState.r.nextInt(Network.size())));
     }
     if (CommonState.r.nextInt(1000) < 5) { // On broadcast
       for (int i = 0; i < Network.size(); i++)
         this.send(
             new Message(Message.APP_MSG, "APP BROADCAST MSG " + this.nodeId + "-" + this.state),
             Network.get(i));
     }
     // On ajoute le prochain APP update
     EDSimulator.add(
         10 + CommonState.r.nextInt(10),
         new Message(Message.APP_UPDATE, "APP Update"),
         Network.get(this.nodeId),
         this.mypid);
   } else if (((Message) event).getType() == Message.APP_MSG) {
     this.receive((Message) event);
   } else if (((Message) event).getType() == Message.PING_SCHED) {
     // On doit envoyer un ping
     int from = Integer.parseInt(((Message) event).getContent().split(" ")[1]);
     this.send(new Message(Message.PING, "PING " + this.nodeId), Network.get(from));
     // On ajoute le prochain ping timeout
     EDSimulator.add(
         this.ping_timeout,
         new Message(Message.PING_TIMEOUT, "PING_TIMEOUT " + from),
         Network.get(this.nodeId),
         this.mypid);
   } else if (((Message) event).getType() == Message.PING) {
     this.receive((Message) event);
     // On a reçu un ping, on renvoie un pong
     int from = Integer.parseInt(((Message) event).getContent().split(" ")[1]);
     this.send(new Message(Message.PONG, "PONG " + this.nodeId), Network.get(from));
   } else if (((Message) event).getType() == Message.PONG) {
     this.receive((Message) event);
     // On a reçu un pong, on enregistre la reception du pong
     int from = Integer.parseInt(((Message) event).getContent().split(" ")[1]);
     this.last_pong[from] = CommonState.getTime();
     if (!this.nodes_alive[from]) {
       this.log("\033[22;32mFalse Failure Detection on " + from + "\033[22;0m");
       this.nodes_alive[from] = true;
     }
     // On ajoute le prochain ping
     EDSimulator.add(
         this.ping_frequency,
         new Message(Message.PING_SCHED, "PING_SCHED " + from),
         Network.get(this.nodeId),
         this.mypid);
   } else if (((Message) event).getType() == Message.PING_TIMEOUT) {
     this.receive((Message) event);
     // On a reçu un ping timeout, le processus est peut etre mort
     int from = Integer.parseInt(((Message) event).getContent().split(" ")[1]);
     long time_ping = CommonState.getTime() - this.ping_timeout;
     if (this.nodes_alive[from] && this.last_pong[from] < time_ping) {
       this.log("\033[22;31mFailure Detection on " + from + "\033[22;0m");
       this.nodes_alive[from] = false;
     }
   } else {
     this.log("Crash !");
     Network.get(this.nodeId).setFailState(Fallible.DEAD);
   }
 }
コード例 #3
0
ファイル: HelloWorld.java プロジェクト: JEC2000/Projet_ARA
 public void log(String what) {
   System.out.println(CommonState.getTime() + " : " + this + " -> " + what);
 }
コード例 #4
0
ファイル: EDMongering.java プロジェクト: naser-ayat/bol1
 private EDMongering(ProtocolData p) {
   this.p = p;
   node = CommonState.getNode();
   status = SUSCEPTIBLE;
 }
コード例 #5
0
ファイル: EDMongering.java プロジェクト: naser-ayat/bol1
 public EDMongering(String prefix) {
   p = new ProtocolData(prefix);
   node = CommonState.getNode();
   status = SUSCEPTIBLE;
 }