@Override protected void execute() { if (masterNode.isPresent()) { ChordRoutingTable routingTable = (ChordRoutingTable) masterNode.getChordRoutingTable(); updatePredecessor = routingTable.getNextUpdatePredecessor(); log.debug( "check predecessor node " + masterNode + " update pred = " + updatePredecessor + " simTime = " + Simulator.getCurrentTime() / Simulator.SECOND_UNIT); msg = new RetrievePredecessorMsg(masterNode.getLocalOverlayContact(), updatePredecessor); if (updatePredecessor.equals(masterNode.getLocalOverlayContact())) { // catch exception that the first host has itself as predecessor predOfPredecessor = routingTable.getPredecessor(); operationFinished(true); ((ChordRoutingTable) masterNode.getChordRoutingTable()) .updateDistantPredecessor(updatePredecessor, predOfPredecessor); } else { sendRetrievePredecessorMsg(); } } else { operationFinished(false); } }
private int sendRetrievePredecessorMsg() { if (masterNode.getOverlayID().compareTo(updatePredecessor.getOverlayID()) == 0) { return -1; } log.debug("sendRetrievePredecessorMsg " + msg + " times = " + resendCounter); return masterNode .getTransLayer() .sendAndWait( msg, updatePredecessor.getTransInfo(), masterNode.getPort(), ChordConfiguration.TRANSPORT_PROTOCOL, this, ChordConfiguration.MESSAGE_TIMEOUT); }
@Override protected void refreshFingertable(Host fromNode) { AbstractChordRoutingTable crt = ((AbstractChordNode) fromNode.getOverlay(AbstractChordNode.class)).getChordRoutingTable(); if (crt == null) { return; } AbstractChordContact[] ft = crt.copyFingerTable(); LinkedHashSet<AbstractChordContact> ft_set = new LinkedHashSet<AbstractChordContact>(Arrays.asList(ft)); if (ft_set.contains(null)) { ft_set.remove(null); } if (ft != null) { Map<NetID, EdgeHandle> edgeHandles = fingerEdges.get(netID(fromNode)); if (edgeHandles == null) { edgeHandles = new LinkedHashMap<NetID, EdgeHandle>(); fingerEdges.put(netID(fromNode), edgeHandles); } Set<NetID> vis_ft = fingertables.get(netID(fromNode)); if (vis_ft == null) { vis_ft = new LinkedHashSet<NetID>(); fingertables.put(netID(fromNode), vis_ft); } boolean ft_changed = false; // add new edges for (AbstractChordContact con : ft_set) { NetID newNetID = con.getTransInfo().getNetId(); if (con != null && !vis_ft.contains(newNetID)) { EdgeHandle h = this.addEdge(netID(fromNode), newNetID, Color.LIGHT_GRAY, "finger"); edgeHandles.put(newNetID, h); vis_ft.add(newNetID); ft_changed = true; } } // remove unused edges: if (vis_ft != null) { for (NetID nId : vis_ft) { boolean inUse = false; for (AbstractChordContact con : ft_set) { if (con.getTransInfo().getNetId().toString().equals(nId.toString())) { inUse = true; break; } } if (!inUse && edgeHandles.containsKey(nId)) { // remove edge. edgeHandles.get(nId).remove(); edgeHandles.remove(nId); } } } if (ft_changed) { this.getTranslator() .nodeAttributeChanged(fromNode.getNetLayer().getNetID(), "ft_hosts", ft_set.size()); } } }
private void refreshRingEdgesForNetId(NetID netid, AbstractChordRoutingTable crt) { if (crt == null) { return; } AbstractChordContact[] ue = ((ChordRoutingTable) crt).getRingEdgesAsArray(); LinkedHashSet<AbstractChordContact> ue_set = new LinkedHashSet<AbstractChordContact>(Arrays.asList(ue)); if (ue_set.contains(null)) { ue_set.remove(null); } if (ue != null) { Set<EdgeHandle> vis_ue = ringEdges.get(netid); if (vis_ue == null) { vis_ue = new LinkedHashSet<EdgeHandle>(); ringEdges.put(netid, vis_ue); } // delete all edges that do not exist nomore. for (EdgeHandle h : vis_ue) { if (h == null) { continue; } boolean stillInUse = false; for (AbstractChordContact con : ue_set) { NetID newNetID; if (((ChordContact) con).isRealNode()) { newNetID = con.getTransInfo().getNetId(); } else { newNetID = virtualNodes.get(con.getOverlayID()); } if (h.getTo() == newNetID) { stillInUse = true; } } if (!stillInUse) { h.remove(); } } // add all edges that are new for (AbstractChordContact con : ue_set) { NetID newNetID; if (((ChordContact) con).isRealNode()) { newNetID = con.getTransInfo().getNetId(); } else { newNetID = virtualNodes.get(con.getOverlayID()); } boolean inSet = false; for (EdgeHandle h : vis_ue) { if (h == null) { continue; } if (newNetID == h.getTo()) { inSet = true; } } if (!inSet) { EdgeHandle e = this.addEdge(netid, newNetID, Color.MAGENTA, "ringEdges"); vis_ue.add(e); } } } }