private void handleLeaveEvent(LeaveEvent ev) { try { ev.go(); } catch (AppiaEventException e) { e.printStackTrace(); } }
/** @param event */ private void handleBCast(SendableEvent event) { try { event.go(); } catch (AppiaEventException e) { e.printStackTrace(); } }
private void allCorrect() { int reg; for (reg = 0; reg < NUM_REGISTERS; reg++) { boolean allAcks = true; int i; for (i = 0; (i < correct.getSize()) && allAcks; i++) { SampleProcess p = correct.getProcess(i); if (p.isCorrect() && !writeSet.get(reg).contains(p)) allAcks = false; } if (allAcks) { writeSet.get(reg).clear(); try { SharedWriteReturn ev = new SharedWriteReturn(mainchannel, Direction.UP, this); ev.reg = reg; ev.go(); debug("Sent WriteReturn"); } catch (AppiaEventException ex) { ex.printStackTrace(); } } } }
/** Sets a timer to delay a message that came from the network. */ private void setTimer(ListContainer container, long timeout, ViewID vid) { try { log.debug("TIME Container: " + container.header.getTime()); SETOTimer timer = new SETOTimer( timeout / 1000, container.event.getChannel(), Direction.DOWN, this, EventQualifier.ON, container, vid); timer.go(); if (log.isDebugEnabled()) log.debug( "Setting new timer. NOW is " + timeProvider.currentTimeMillis() + " timer to " + timer.getTimeout()); } catch (AppiaEventException e) { e.printStackTrace(); } catch (AppiaException e) { e.printStackTrace(); } }
/** Tries to deliver Uniform messages. */ private void deliverUniform() { log.debug("Trying to deliver FINAL messages!"); ListIterator it = G.listIterator(); while (it.hasNext()) { ListSEQContainer nextMsg = (ListSEQContainer) it.next(); if (isUniform(nextMsg.header)) { ListContainer msgContainer = getRemoveMessage(nextMsg.header, R); log.debug("Resending message to Appl: " + msgContainer.event); log.debug( "[" + ls.my_rank + "] Delivering final " + msgContainer.header.id + ":" + msgContainer.header.sn + " timestamp " + timeProvider.currentTimeMillis()); try { // deliver uniform notification UniformServiceEvent use = new UniformServiceEvent( msgContainer.event.getChannel(), Direction.UP, this, msgContainer.event.getMessage()); use.go(); } catch (AppiaEventException e) { e.printStackTrace(); } it.remove(); } } }
private void handleGroupSendableEvent(GroupSendableEvent ev) { if (ev instanceof Send) { try { ev.go(); } catch (AppiaEventException ex) { ex.printStackTrace(); } return; } if (ev.getDir() == Direction.DOWN) { last_recv[ls.my_rank] = round; if (debugFull) log.debug("Sent msg (" + ev + ") in round " + round); } else { last_recv[ev.orig] = round; if (debugFull) log.debug("Recv msg from " + ev.orig + " in round " + round); } if (ev instanceof Alive) return; try { ev.go(); } catch (AppiaEventException ex) { ex.printStackTrace(); } }
/** * Deliver a DATA event received from the network. * * @param event the event received from the network. */ private void reliableDATADeliver(GroupSendableEvent event) { Message msg = event.getMessage(); long[] uniformInfo = new long[vs.view.length]; for (int i = uniformInfo.length; i > 0; i--) uniformInfo[i - 1] = msg.popLong(); mergeUniformInfo(uniformInfo); DATAHeader header = DATAHeader.pop(event.getMessage()); log.debug( "Received DATA message: " + header.id + ":" + header.sn + " timestpamp is " + timeProvider.currentTimeMillis()); header.setTime(delay[header.id] + timeProvider.currentTimeMillis()); ListContainer container = new ListContainer(event, header); // add the event to the RECEIVED list... R.addLast(container); // ... and set a timer to be delivered later, according to the delay that came with the message setTimer(container, delay[header.id], vs.id); // Deliver event to the upper layer (spontaneous order) try { event.go(); } catch (AppiaEventException e) { e.printStackTrace(); } }
private void deliverPendingView() { try { pendingView.go(); } catch (AppiaEventException e) { e.printStackTrace(); } if (!pendingMessages.isEmpty()) { log.debug("Delivering " + pendingMessages.size() + " pending messages"); for (GroupSendableEvent event : pendingMessages) { reliableDATADeliver(event); } pendingMessages.clear(); } if (!utSet) { try { UniformTimer ut = new UniformTimer( UNIFORM_INFO_PERIOD, pendingView.getChannel(), Direction.DOWN, this, EventQualifier.ON); ut.go(); utSet = true; } catch (AppiaEventException e) { e.printStackTrace(); } catch (AppiaException e) { e.printStackTrace(); } } pendingView = null; }
private void handleFIFOUndeliveredEvent(FIFOUndeliveredEvent ev) { try { ev.go(); } catch (AppiaEventException ex) { ex.printStackTrace(); } if (vs == null) return; if (!(ev.getEvent() instanceof GroupSendableEvent)) return; final GroupSendableEvent event = (GroupSendableEvent) ev.getEvent(); if (!vs.group.equals(event.group)) { log.debug("Ignored FIFOUndelivered due to wrong group"); return; } if (!vs.id.equals(event.view_id)) { log.debug("Ignored FIFOUndelivered due to wrong view id"); return; } if (event.dest instanceof InetSocketAddress) undelivered((InetSocketAddress) event.dest, ev.getChannel()); else if (event.dest instanceof AppiaMulticast) { Object[] dests = ((AppiaMulticast) event.dest).getDestinations(); for (int i = 0; i < dests.length; i++) { if (dests[i] instanceof InetSocketAddress) undelivered((InetSocketAddress) dests[i], ev.getChannel()); } } else log.debug("Received FIFOUndelivered with unknown destination address. Ignoring it."); }
private void handleView(View ev) { vs = ev.vs; ls = ev.ls; try { ev.go(); } catch (AppiaEventException ex) { ex.printStackTrace(); } if (round == 0) { try { SuspectTimer periodic = new SuspectTimer("Suspect Timer", suspect_sweep, ev.getChannel(), this); periodic.go(); } catch (AppiaException ex) { ex.printStackTrace(); System.err.println( "appia:group:SuspectSession: impossible to set SuspectTimer, SuspectSession will be idle"); } } if (vs.view.length != last_recv.length) { last_recv = new long[vs.view.length]; } round = 1; Arrays.fill(last_recv, round); }
/** @param init */ private void handleChannelInit(ChannelInit init) { try { init.go(); } catch (AppiaEventException e) { e.printStackTrace(); } channel = init.getChannel(); try { // sends this event to open a socket in the layer that is used has // perfect // point to point // channels or unreliable point to point channels. RegisterSocketEvent rse = new RegisterSocketEvent(channel, Direction.DOWN, this); rse.port = ((InetSocketAddress) processes.getSelfProcess().getSocketAddress()).getPort(); rse.localHost = ((InetSocketAddress) processes.getSelfProcess().getSocketAddress()).getAddress(); rse.go(); ProcessInitEvent processInit = new ProcessInitEvent(channel, Direction.DOWN, this); processInit.setProcessSet(processes); processInit.go(); } catch (AppiaEventException e1) { e1.printStackTrace(); } System.out.println("Channel is open."); }
private void handleChannelClose(ChannelClose close) { log.warn("Channel is closing!"); try { close.go(); } catch (AppiaEventException e) { e.printStackTrace(); } }
/** @param close */ private void handleChannelClose(ChannelClose close) { channels.put(close.getChannel(), null); try { close.go(); } catch (AppiaEventException e) { e.printStackTrace(); } }
/* * handles ChannelInit * @param init */ private void handleChannelInit(ChannelInit init) { try { init.go(); } catch (AppiaEventException e) { e.printStackTrace(); } time = init.getChannel().getTimeProvider(); }
/** @param init */ private void handleChannelInit(ChannelInit init) { channels.put(init.getChannel(), null); try { init.go(); } catch (AppiaEventException e) { e.printStackTrace(); } }
/** Delivers a message to the layer above. */ private void delivery(GroupSendableEvent event) { try { event.setSource(this); event.init(); event.go(); } catch (AppiaEventException e) { e.printStackTrace(); } }
private void handleProcessInit(ProcessInitEvent event) { correct = event.getProcessSet(); init(); try { event.go(); } catch (AppiaEventException ex) { ex.printStackTrace(); } }
private void sendFail(boolean[] failed, Channel channel) { try { Fail ev = new Fail(failed, vs.group, vs.id); EchoEvent echo = new EchoEvent(ev, channel, Direction.DOWN, this); echo.go(); } catch (AppiaEventException ex) { ex.printStackTrace(); System.err.println("appia:group:SuspectSession: impossible to inform locally of failure"); } }
private void handleSharedRead(SharedRead event) { try { SharedReadReturn ev = new SharedReadReturn(mainchannel, Direction.UP, this); ev.reg = event.reg; ev.value = value[event.reg]; ev.go(); } catch (AppiaEventException ex) { ex.printStackTrace(); } }
private void sendAlive(Channel channel) { if (vs.view.length < 2) return; try { Alive alive = new Alive(channel, Direction.DOWN, this, vs.group, vs.id); alive.go(); } catch (AppiaEventException ex) { ex.printStackTrace(); log.warn("Impossible to send alive"); } }
private void sendSuspect(boolean[] failed, Channel channel) { try { Suspect ev = new Suspect(failed, channel, Direction.DOWN, this, vs.group, vs.id); ArrayOptimized.pushArrayBoolean(ls.failed, ev.getMessage()); // ev.getObjectsMessage().push(ls.failed); ev.go(); } catch (AppiaEventException ex) { ex.printStackTrace(); log.warn("Impossible to send Suspect"); } }
private void handleCrash(Crash event) { correct.setCorrect(event.getCrashedProcess(), false); try { event.go(); } catch (AppiaEventException ex) { ex.printStackTrace(); } allCorrect(); }
/** @param ok */ private void handleBlockOk(BlockOk ok) { log.debug("Collecting blockok events :: counter = " + blockOkCounter); if ((--blockOkCounter) == 0) { try { log.debug("Delivering blockok on channel: " + ok.getChannel().getChannelID()); ok.go(); } catch (AppiaEventException e) { e.printStackTrace(); } } }
/** * The group os blocked. It is going to change view. * * @param ok */ private void handleBlockOk(BlockOk ok) { log.debug("The group is blocked."); log.debug("Impossible to send messages. Waiting for a new View"); isBlocked = true; try { ok.go(); } catch (AppiaEventException e) { e.printStackTrace(); } }
private void handleTcpUndeliveredEvent(TcpUndeliveredEvent ev) { try { ev.go(); } catch (AppiaEventException ex) { ex.printStackTrace(); } if (vs == null) return; undelivered((InetSocketAddress) ev.getFailedAddress(), ev.getChannel()); }
/** * This is the protocol's main event handler. It accepts the following events: * * <ul> * <li>net.sf.appia.protocols.group.leave.LeaveEvent * <li>net.sf.appia.protocols.group.events.GroupSendableEvent * <li>net.sf.appia.protocols.group.intra.View * </ul> * * @param event the event to handle. * @see net.sf.appia.core.Session#handle(net.sf.appia.core.Event) */ public void handle(Event event) { if (event instanceof View) handleView((View) event); else if (event instanceof LeaveEvent) handleLeaveEvent((LeaveEvent) event); else if (event instanceof GroupSendableEvent) handleGroupSendableEvent((GroupSendableEvent) event); else try { event.go(); } catch (AppiaEventException e) { e.printStackTrace(); } }
private void handleSharedWrite(SharedWrite event) { debug("received SharedWrite"); try { WriteEvent ev = new WriteEvent(mainchannel, Direction.DOWN, this); ev.getMessage().pushObject(event.value); ev.getMessage().pushInt(event.reg); ev.go(); } catch (AppiaEventException ex) { ex.printStackTrace(); } }
private void ackView(Channel ch) { try { AckViewEvent ack = new AckViewEvent(ch, Direction.DOWN, this, vs.group, vs.id); // int dest[] = new int[survivors.length]; // for (int i = 0; i < dest.length; i++) // dest[i] = vs.getRank(survivors[i]); // ack.dest = dest; ack.go(); } catch (AppiaEventException e) { e.printStackTrace(); } ackCounter = 0; }
public void handle(Event e) { if (e instanceof GroupSendableEvent) handleGroupSendable((GroupSendableEvent) e); else if (e instanceof EchoEvent) handleEchoEvent((EchoEvent) e); else if (e instanceof View) handleView((View) e); else if (e instanceof BlockOk) handleBlockOk((BlockOk) e); else if (e instanceof ChannelInit) handleChannelInit((ChannelInit) e); else if (e instanceof ChannelClose) handleChannelClose((ChannelClose) e); else try { e.go(); } catch (AppiaEventException e1) { e1.printStackTrace(); } }
/** * Handles all received event * * @param ev */ public void handle(Event ev) { if (ev instanceof TextEvent || ev instanceof DrawEvent || ev instanceof ImageEvent || ev instanceof ClearWhiteBoardEvent || ev instanceof MouseButtonEvent) handleInterestingEvent((GroupSendableEvent) ev); else { try { ev.go(); } catch (AppiaEventException ex) { ex.printStackTrace(); } } }