@Test public void testConvergenceNoReplies() throws Exception { List<List<Rply>> replies = new ArrayList<List<Rply>>(); replies.add(Collections.<Rply>emptyList()); replies.add(Collections.<Rply>emptyList()); Converger<Rply> converger = new TestConverger(replies, null, null); List<Rply> result = converger.converge(new SrvRqst()); assert result.isEmpty(); }
public List<T> converge(Rqst rqst) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence max wait (ms): " + multicastMaxWait); if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence timeouts (ms): " + Arrays.toString(multicastTimeouts)); List<T> result = new ArrayList<T>(); Set<String> previousResponders = new HashSet<String>(); Set<IdentifierExtension> previousResponderIdentifiers = new HashSet<IdentifierExtension>(); DatagramSocket datagramSocket = convergenceBegin(); long start = System.currentTimeMillis(); int noReplies = 0; int timeoutIndex = 0; while (timeoutIndex < multicastTimeouts.length) { long now = System.currentTimeMillis(); if (multicastMaxWait > 0 && now > start + multicastMaxWait) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, timeframe exceeded"); break; } rqst.setPreviousResponders(previousResponders); if (!previousResponderIdentifiers.isEmpty()) { for (IdentifierExtension previousResponderIdentifier : previousResponderIdentifiers) { rqst.addExtension(previousResponderIdentifier); } } byte[] rqstBytes = rqst.serialize(); if (rqstBytes.length > maxTransmissionUnit) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, message bigger than maxTransmissionUnit"); break; } if (logger.isLoggable(Level.FINE)) logger.fine("Multicast convergence sending " + rqst); List<T> rplys = manycastSendAndReceive(datagramSocket, rqstBytes, multicastTimeouts[timeoutIndex]); boolean newMessages = false; for (T rply : rplys) { String responder = rply.getResponder(); if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received reply " + rply + ", responder is " + responder); boolean newResponder = previousResponders.add(responder); boolean newResponderIdentifier = newResponder; IdentifierExtension identifierExtension = IdentifierExtension.findFirst(rply.getExtensions()); if (identifierExtension != null) newResponderIdentifier = previousResponderIdentifiers.add(identifierExtension); if (newResponder) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from new responder " + responder + " (" + (identifierExtension == null ? "" : identifierExtension.getIdentifier()) + ")"); result.add(rply); newMessages = true; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + " (" + (identifierExtension == null ? "" : identifierExtension.getIdentifier()) + ")"); if (identifierExtension != null) { if (newResponderIdentifier) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from new responder " + responder + " (" + identifierExtension.getIdentifier() + ")"); result.add(rply); newMessages = true; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + " (" + identifierExtension.getIdentifier() + "), dropping it"); } } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + ", dropping it"); } } } if (newMessages) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence replies: " + result); noReplies = 0; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received no new replies"); ++timeoutIndex; ++noReplies; if (noReplies > 1) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, two timeouts elapsed"); break; } } } convergenceEnd(datagramSocket); long end = System.currentTimeMillis(); if (logger.isLoggable(Level.FINE)) logger.fine("Multicast convergence lasted (ms): " + (end - start) + ", returning " + result.size() + " results"); return result; }
Converger { public List<T> converge(Rqst rqst) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence max wait (ms): " + multicastMaxWait); if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence timeouts (ms): " + Arrays.toString(multicastTimeouts)); List<T> result = new ArrayList<T>(); Set<String> previousResponders = new HashSet<String>(); Set<IdentifierExtension> previousResponderIdentifiers = new HashSet<IdentifierExtension>(); DatagramSocket datagramSocket = convergenceBegin(); long start = System.currentTimeMillis(); int noReplies = 0; int timeoutIndex = 0; while (timeoutIndex < multicastTimeouts.length) { long now = System.currentTimeMillis(); if (multicastMaxWait > 0 && now > start + multicastMaxWait) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, timeframe exceeded"); break; } rqst.setPreviousResponders(previousResponders); if (!previousResponderIdentifiers.isEmpty()) { for (IdentifierExtension previousResponderIdentifier : previousResponderIdentifiers) { rqst.addExtension(previousResponderIdentifier); } } byte[] rqstBytes = rqst.serialize(); if (rqstBytes.length > maxTransmissionUnit) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, message bigger than maxTransmissionUnit"); break; } if (logger.isLoggable(Level.FINE)) logger.fine("Multicast convergence sending " + rqst); List<T> rplys = manycastSendAndReceive(datagramSocket, rqstBytes, multicastTimeouts[timeoutIndex]); boolean newMessages = false; for (T rply : rplys) { String responder = rply.getResponder(); if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received reply " + rply + ", responder is " + responder); boolean newResponder = previousResponders.add(responder); boolean newResponderIdentifier = newResponder; IdentifierExtension identifierExtension = IdentifierExtension.findFirst(rply.getExtensions()); if (identifierExtension != null) newResponderIdentifier = previousResponderIdentifiers.add(identifierExtension); if (newResponder) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from new responder " + responder + " (" + (identifierExtension == null ? "" : identifierExtension.getIdentifier()) + ")"); result.add(rply); newMessages = true; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + " (" + (identifierExtension == null ? "" : identifierExtension.getIdentifier()) + ")"); if (identifierExtension != null) { if (newResponderIdentifier) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from new responder " + responder + " (" + identifierExtension.getIdentifier() + ")"); result.add(rply); newMessages = true; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + " (" + identifierExtension.getIdentifier() + "), dropping it"); } } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + ", dropping it"); } } } if (newMessages) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence replies: " + result); noReplies = 0; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received no new replies"); ++timeoutIndex; ++noReplies; if (noReplies > 1) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, two timeouts elapsed"); break; } } } convergenceEnd(datagramSocket); long end = System.currentTimeMillis(); if (logger.isLoggable(Level.FINE)) logger.fine("Multicast convergence lasted (ms): " + (end - start) + ", returning " + result.size() + " results"); return result; } }
Converger { public List<T> converge(Rqst rqst) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence max wait (ms): " + multicastMaxWait); if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence timeouts (ms): " + Arrays.toString(multicastTimeouts)); List<T> result = new ArrayList<T>(); Set<String> previousResponders = new HashSet<String>(); Set<IdentifierExtension> previousResponderIdentifiers = new HashSet<IdentifierExtension>(); DatagramSocket datagramSocket = convergenceBegin(); long start = System.currentTimeMillis(); int noReplies = 0; int timeoutIndex = 0; while (timeoutIndex < multicastTimeouts.length) { long now = System.currentTimeMillis(); if (multicastMaxWait > 0 && now > start + multicastMaxWait) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, timeframe exceeded"); break; } rqst.setPreviousResponders(previousResponders); if (!previousResponderIdentifiers.isEmpty()) { for (IdentifierExtension previousResponderIdentifier : previousResponderIdentifiers) { rqst.addExtension(previousResponderIdentifier); } } byte[] rqstBytes = rqst.serialize(); if (rqstBytes.length > maxTransmissionUnit) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, message bigger than maxTransmissionUnit"); break; } if (logger.isLoggable(Level.FINE)) logger.fine("Multicast convergence sending " + rqst); List<T> rplys = manycastSendAndReceive(datagramSocket, rqstBytes, multicastTimeouts[timeoutIndex]); boolean newMessages = false; for (T rply : rplys) { String responder = rply.getResponder(); if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received reply " + rply + ", responder is " + responder); boolean newResponder = previousResponders.add(responder); boolean newResponderIdentifier = newResponder; IdentifierExtension identifierExtension = IdentifierExtension.findFirst(rply.getExtensions()); if (identifierExtension != null) newResponderIdentifier = previousResponderIdentifiers.add(identifierExtension); if (newResponder) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from new responder " + responder + " (" + (identifierExtension == null ? "" : identifierExtension.getIdentifier()) + ")"); result.add(rply); newMessages = true; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + " (" + (identifierExtension == null ? "" : identifierExtension.getIdentifier()) + ")"); if (identifierExtension != null) { if (newResponderIdentifier) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from new responder " + responder + " (" + identifierExtension.getIdentifier() + ")"); result.add(rply); newMessages = true; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + " (" + identifierExtension.getIdentifier() + "), dropping it"); } } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + ", dropping it"); } } } if (newMessages) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence replies: " + result); noReplies = 0; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received no new replies"); ++timeoutIndex; ++noReplies; if (noReplies > 1) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, two timeouts elapsed"); break; } } } convergenceEnd(datagramSocket); long end = System.currentTimeMillis(); if (logger.isLoggable(Level.FINE)) logger.fine("Multicast convergence lasted (ms): " + (end - start) + ", returning " + result.size() + " results"); return result; } Converger(UDPConnector udpConnector, Settings settings); }
Converger { public List<T> converge(Rqst rqst) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence max wait (ms): " + multicastMaxWait); if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence timeouts (ms): " + Arrays.toString(multicastTimeouts)); List<T> result = new ArrayList<T>(); Set<String> previousResponders = new HashSet<String>(); Set<IdentifierExtension> previousResponderIdentifiers = new HashSet<IdentifierExtension>(); DatagramSocket datagramSocket = convergenceBegin(); long start = System.currentTimeMillis(); int noReplies = 0; int timeoutIndex = 0; while (timeoutIndex < multicastTimeouts.length) { long now = System.currentTimeMillis(); if (multicastMaxWait > 0 && now > start + multicastMaxWait) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, timeframe exceeded"); break; } rqst.setPreviousResponders(previousResponders); if (!previousResponderIdentifiers.isEmpty()) { for (IdentifierExtension previousResponderIdentifier : previousResponderIdentifiers) { rqst.addExtension(previousResponderIdentifier); } } byte[] rqstBytes = rqst.serialize(); if (rqstBytes.length > maxTransmissionUnit) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, message bigger than maxTransmissionUnit"); break; } if (logger.isLoggable(Level.FINE)) logger.fine("Multicast convergence sending " + rqst); List<T> rplys = manycastSendAndReceive(datagramSocket, rqstBytes, multicastTimeouts[timeoutIndex]); boolean newMessages = false; for (T rply : rplys) { String responder = rply.getResponder(); if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received reply " + rply + ", responder is " + responder); boolean newResponder = previousResponders.add(responder); boolean newResponderIdentifier = newResponder; IdentifierExtension identifierExtension = IdentifierExtension.findFirst(rply.getExtensions()); if (identifierExtension != null) newResponderIdentifier = previousResponderIdentifiers.add(identifierExtension); if (newResponder) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from new responder " + responder + " (" + (identifierExtension == null ? "" : identifierExtension.getIdentifier()) + ")"); result.add(rply); newMessages = true; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + " (" + (identifierExtension == null ? "" : identifierExtension.getIdentifier()) + ")"); if (identifierExtension != null) { if (newResponderIdentifier) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from new responder " + responder + " (" + identifierExtension.getIdentifier() + ")"); result.add(rply); newMessages = true; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + " (" + identifierExtension.getIdentifier() + "), dropping it"); } } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + ", dropping it"); } } } if (newMessages) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence replies: " + result); noReplies = 0; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received no new replies"); ++timeoutIndex; ++noReplies; if (noReplies > 1) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, two timeouts elapsed"); break; } } } convergenceEnd(datagramSocket); long end = System.currentTimeMillis(); if (logger.isLoggable(Level.FINE)) logger.fine("Multicast convergence lasted (ms): " + (end - start) + ", returning " + result.size() + " results"); return result; } Converger(UDPConnector udpConnector, Settings settings); void setMulticastTimeouts(int[] multicastTimeouts); void setMulticastMaxWait(int multicastMaxWait); void setMaxTransmissionUnit(int maxTransmissionUnit); List<T> converge(Rqst rqst); }
Converger { public List<T> converge(Rqst rqst) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence max wait (ms): " + multicastMaxWait); if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence timeouts (ms): " + Arrays.toString(multicastTimeouts)); List<T> result = new ArrayList<T>(); Set<String> previousResponders = new HashSet<String>(); Set<IdentifierExtension> previousResponderIdentifiers = new HashSet<IdentifierExtension>(); DatagramSocket datagramSocket = convergenceBegin(); long start = System.currentTimeMillis(); int noReplies = 0; int timeoutIndex = 0; while (timeoutIndex < multicastTimeouts.length) { long now = System.currentTimeMillis(); if (multicastMaxWait > 0 && now > start + multicastMaxWait) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, timeframe exceeded"); break; } rqst.setPreviousResponders(previousResponders); if (!previousResponderIdentifiers.isEmpty()) { for (IdentifierExtension previousResponderIdentifier : previousResponderIdentifiers) { rqst.addExtension(previousResponderIdentifier); } } byte[] rqstBytes = rqst.serialize(); if (rqstBytes.length > maxTransmissionUnit) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, message bigger than maxTransmissionUnit"); break; } if (logger.isLoggable(Level.FINE)) logger.fine("Multicast convergence sending " + rqst); List<T> rplys = manycastSendAndReceive(datagramSocket, rqstBytes, multicastTimeouts[timeoutIndex]); boolean newMessages = false; for (T rply : rplys) { String responder = rply.getResponder(); if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received reply " + rply + ", responder is " + responder); boolean newResponder = previousResponders.add(responder); boolean newResponderIdentifier = newResponder; IdentifierExtension identifierExtension = IdentifierExtension.findFirst(rply.getExtensions()); if (identifierExtension != null) newResponderIdentifier = previousResponderIdentifiers.add(identifierExtension); if (newResponder) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from new responder " + responder + " (" + (identifierExtension == null ? "" : identifierExtension.getIdentifier()) + ")"); result.add(rply); newMessages = true; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + " (" + (identifierExtension == null ? "" : identifierExtension.getIdentifier()) + ")"); if (identifierExtension != null) { if (newResponderIdentifier) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from new responder " + responder + " (" + identifierExtension.getIdentifier() + ")"); result.add(rply); newMessages = true; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + " (" + identifierExtension.getIdentifier() + "), dropping it"); } } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received a reply from known responder " + responder + ", dropping it"); } } } if (newMessages) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence replies: " + result); noReplies = 0; } else { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence received no new replies"); ++timeoutIndex; ++noReplies; if (noReplies > 1) { if (logger.isLoggable(Level.FINER)) logger.finer("Multicast convergence exit, two timeouts elapsed"); break; } } } convergenceEnd(datagramSocket); long end = System.currentTimeMillis(); if (logger.isLoggable(Level.FINE)) logger.fine("Multicast convergence lasted (ms): " + (end - start) + ", returning " + result.size() + " results"); return result; } Converger(UDPConnector udpConnector, Settings settings); void setMulticastTimeouts(int[] multicastTimeouts); void setMulticastMaxWait(int multicastMaxWait); void setMaxTransmissionUnit(int maxTransmissionUnit); List<T> converge(Rqst rqst);  }