MCPcopy Create free account
hub / github.com/akeranen/the-one / update

Method update

routing/ActiveRouter.java:580–632  ·  view source on GitHub ↗

Checks out all sending connections to finalize the ready ones and abort those whose connection went down. Also drops messages whose TTL <= 0 (checking every one simulated minute). @see #addToSendingConnections(Connection)

()

Source from the content-addressed store, hash-verified

578 * @see #addToSendingConnections(Connection)
579 */
580 @Override
581 public void update() {
582 super.update();
583
584 /* in theory we can have multiple sending connections even though
585 currently all routers allow only one concurrent sending connection */
586 for (int i=0; i<this.sendingConnections.size(); ) {
587 boolean removeCurrent = false;
588 Connection con = sendingConnections.get(i);
589
590 /* finalize ready transfers */
591 if (con.isMessageTransferred()) {
592 if (con.getMessage() != null) {
593 transferDone(con);
594 con.finalizeTransfer();
595 } /* else: some other entity aborted transfer */
596 removeCurrent = true;
597 }
598 /* remove connections that have gone down */
599 else if (!con.isUp()) {
600 if (con.getMessage() != null) {
601 transferAborted(con);
602 con.abortTransfer();
603 }
604 removeCurrent = true;
605 }
606
607 if (removeCurrent) {
608 // if the message being sent was holding excess buffer, free it
609 if (this.getFreeBufferSize() < 0) {
610 this.makeRoomForMessage(0);
611 }
612 sendingConnections.remove(i);
613 }
614 else {
615 /* index increase needed only if nothing was removed */
616 i++;
617 }
618 }
619
620 /* time to do a TTL check and drop old messages? Only if not sending */
621 if (SimClock.getTime() - lastTtlCheck >= TTL_CHECK_INTERVAL &&
622 sendingConnections.size() == 0) {
623 dropExpiredMessages();
624 lastTtlCheck = SimClock.getTime();
625 }
626
627 if (energy != null) {
628 /* TODO: add support for other interfaces */
629 NetworkInterface iface = getHost().getInterface(1);
630 energy.update(iface, getHost().getComBus());
631 }
632 }
633
634 /**
635 * Method is called just before a transfer is aborted at {@link #update()}

Callers

nothing calls this directly

Calls 15

isMessageTransferredMethod · 0.95
getMessageMethod · 0.95
transferDoneMethod · 0.95
finalizeTransferMethod · 0.95
isUpMethod · 0.95
transferAbortedMethod · 0.95
abortTransferMethod · 0.95
makeRoomForMessageMethod · 0.95
getTimeMethod · 0.95
dropExpiredMessagesMethod · 0.95
getFreeBufferSizeMethod · 0.80
getInterfaceMethod · 0.80

Tested by

no test coverage detected