@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 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; } }