Exemplo n.º 1
0
 void checkingQuorum(Message msg, Content_AmoebaSequencer ca) {
   long clock = (long) this.getInfra().clock.value();
   // infra.debug("Sequencer: RECEIVING ACKS of p"+msg.sender+" = "+ca.ACKS);
   for (int i = 0; i < ca.ACKS.size(); i++) {
     int numSeq = ca.ACKS.toVector()[i];
     quorum[numSeq]++;
     getInfra().debug("seqpart " + numSeq + ": count " + quorum[numSeq]);
     if (quorum[numSeq] == getInfra().nprocess) {
       DLVS.add(numSeq);
       ca.DLVS.add(DLVS);
       getInfra().debug("being DELIVERING " + ca.DLVS);
       getInfra().debug("seq " + numSeq + ": count " + quorum[numSeq]);
     }
   }
   /*
   *  this.sendGroupMsg(clock, DLV, ca, ca.DLVS.min());
      DLVS.clean();
      DSENT = clock;
   *
   */
   Content_AmoebaSequencer ca1 = new Content_AmoebaSequencer(-1, "");
   ca1.DLVS.add(DLVS);
   if ((clock - DSENT >= ts) && (DLVS.size() > 0)) {
     this.sendGroupMsg(clock, DLV, ca1, ca1.DLVS.min());
     DLVS.clean();
     DSENT = clock;
   } else getInfra().debug("avoid DELIVERING " + DLVS);
 }
Exemplo n.º 2
0
 @Override
 public void execute() {
   long clock = (long) getInfra().clock.value();
   Content_AmoebaSequencer ca = new Content_AmoebaSequencer(LastACK, "stuff");
   if ((r.uniform() <= prob) && !bloquearEntrega && clock < .2 * finalTime) {
     SENT = clock; // Registering clock of the last SENT
     ca.ACKS.add(ACKS);
     this.createMessage(clock, getAgentID(), Leader, REQ_SEQ, ca, -1);
     ACKS.clean();
     count++;
   }
   if ((clock - SENT >= ts) && (ACKS.size() > 0)) {
     ca.ACKS.add(ACKS);
     this.createMessage(clock, getAgentID(), Leader, ACK, ca, -1);
     ACKS.clean();
     SENT = clock;
     getInfra().debug("p" + getAgentID() + " FLUSHED ACKS = " + ACKS.size());
   }
   if ((AmILeader) && (clock - DSENT >= ts) && (DLVS.size() > 0)) {
     ca.DLVS.add(DLVS);
     this.sendGroupMsg(clock, DLV, ca, ca.DLVS.min());
     getInfra().debug("Enviando");
     DLVS.clean();
     DSENT = clock;
   }
 }
 @Override
 protected boolean hasListener(int packetID) {
   return sendingFilters.contains(packetID);
 }
Exemplo n.º 4
0
  @Override
  public void receive(Message msg) {

    Content_AmoebaSequencer ca;
    long clock = (long) getInfra().clock.value();

    switch (msg.type) {
      case REQ_SEQ:
        if (AmILeader) {
          Sequential++;
          ca = (Content_AmoebaSequencer) msg.content;
          /*
           *   PROCESSA OS EMBEDDED ACKS
           */
          ca = (Content_AmoebaSequencer) msg.content;
          this.checkingQuorum(msg, ca);
          /*
           *    ENVIA MSG
           */
          ca.LastDLV = LastDLV;
          ca.LastACK = LastACK;

          msg.logicalClock = Sequential;
          ca.contentMsg = msg;
          ca.ACKS.clean();
          // ca.DLVS.clean();
          ca.DLVS.add(DLVS);

          quorum[Sequential] = 0;
          SENT = clock;
          sendGroupMsg(clock, APP, ca, Sequential, true);
        }
        break;
      case APP:
        ca = (Content_AmoebaSequencer) msg.content;
        msgs.add(msg.logicalClock, ca.getContentMsg());

        // infra.debug("p"+ ID+ " received "+msg.logicalClock + " of
        // p"+msg.sender+"("+msg.physicalClock+" at "+clock+")");
        ca.ACKS.clean();
        ACKS.add(msg.logicalClock);
        ca.ACKS.add(ACKS);
        // infra.debug("p"+msg.sender+" STATE ACKS = "+ca.ACKS);
        if (clock - SENT >= ts) {
          this.createMessage(clock, getAgentID(), Leader, ACK, ca, msg.logicalClock);
          ACKS.clean();
          SENT = clock;
          // infra.debug("p"+msg.sender+" FLUSHED ACKS = "+ACKS.size());
        }
        /* VER EMBEDDED DELIVERIES */

        break;
      case ACK:
        if (AmILeader) {
          ca = (Content_AmoebaSequencer) msg.content;
          this.checkingQuorum(msg, ca);
        }

        break;
      case DLV:
        ca = (Content_AmoebaSequencer) msg.content;
        getInfra().debug("p" + getAgentID() + " DELIVERING MSG = " + msg.logicalClock);
        getInfra().debug("p" + getAgentID() + " DELIVERING = " + ca.DLVS);
        Message m;
        for (int i = 0; i < ca.DLVS.size(); i++) {
          int numSeq = ca.DLVS.toVector()[i];

          if (msgs.checkTime(numSeq)) {
            m = (Message) msgs.getMsgs(numSeq).get(0);
            this.preDeliver(m);
            deliver(m);
          }
        }
        break;
    }
  }