public void handle(Pp2pSend event) { Address destination = event.getDestination(); if (destination.equals(self)) { // deliver locally Pp2pDeliver deliverEvent = event.getDeliverEvent(); trigger(deliverEvent, pp2p); return; } long latency; try { latency = topology.getLatencyMs(self, destination); } catch (NoLinkException e) { // there is no link to the destination, we drop the message return; } // make a DelayLinkMessage to be delivered at the destination DelayLinkMessage message = new DelayLinkMessage(self, destination, event.getDeliverEvent()); if (latency > 0) { // delay the sending according to the latency ScheduleTimeout st = new ScheduleTimeout(latency); st.setTimeoutEvent(new DelayedMessage(st, message)); trigger(st, timer); } else { // send immediately trigger(message, network); } }
public void handle(DelayLinkInit event) { topology = event.getTopology(); self = topology.getSelfAddress(); }