Пример #1
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;
    }
  }