Пример #1
0
 public void start_ping() {
   for (int i = 0; i < Network.size(); i++) {
     if (i != this.nodeId)
       EDSimulator.add(
           this.ping_frequency,
           new Message(Message.PING_SCHED, "PING_SCHED " + i),
           Network.get(this.nodeId),
           this.mypid);
   }
 }
Пример #2
0
 public HelloWorld(String prefix) {
   this.prefix = prefix;
   // initialisation des identifiants a partir du fichier de configuration
   this.transportPid = Configuration.getPid(prefix + ".transport");
   this.mypid = Configuration.getPid(prefix + ".myself");
   this.ping_timeout = Configuration.getLong(prefix + ".ping_timeout");
   this.ping_frequency = Configuration.getLong(prefix + ".ping_frequency");
   this.transport = null;
   this.state = 0;
   this.last_pong = new long[Network.size()];
   this.nodes_alive = new boolean[Network.size()];
   for (int i = 0; i < Network.size(); i++) {
     nodes_alive[i] = true;
   }
 }
Пример #3
0
 // 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);
   }
 }
Пример #4
0
 // retourne le noeud courant
 private Node getMyNode() {
   return Network.get(this.nodeId);
 }
Пример #5
0
 // liaison entre un objet de la couche applicative et un
 // objet de la couche transport situes sur le meme noeud
 public void setTransportLayer(int nodeId) {
   this.nodeId = nodeId;
   this.transport = (MatrixTransport) Network.get(this.nodeId).getProtocol(this.transportPid);
 }