@Override public void findMembers(List<Address> members, boolean initial_discovery, Responses responses) { num_discovery_requests++; List<PingData> retval=(List<PingData>)down_prot.down(new Event(Event.GET_PING_DATA, cluster_name)); if(retval != null) retval.stream().filter(data -> !data.getAddress().equals(local_addr)).forEach(data -> responses.addResponse(data, false)); responses.done(); // so waitFor() doesn't block at all }
protected void addResponse(PingData rsp, boolean overwrite) { if(discovery_rsp_callback != null) { try { discovery_rsp_callback.accept(rsp); } catch(Throwable t) { log.error("%s: failed invoking callback for discovery response: %s", local_addr, t); } } synchronized(ping_responses) { for(Iterator<Map.Entry<Long,Responses>> it=ping_responses.entrySet().iterator(); it.hasNext();) { Map.Entry<Long,Responses> entry=it.next(); long timestamp=entry.getKey(); Responses rsps=entry.getValue(); rsps.addResponse(rsp, overwrite); if(rsps.isDone() || TimeUnit.MILLISECONDS.convert(System.nanoTime() - timestamp, TimeUnit.NANOSECONDS) > discovery_rsp_expiry_time) { it.remove(); rsps.done(); clearRequestFutures(); } } } }
responses.addResponse(data, true); if(local_addr != null && !local_addr.equals(data.getAddress())) addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr());
if(data == null || (members != null && !members.contains(data.getAddress()))) continue; rsps.addResponse(data, false); if(local_addr != null && !local_addr.equals(data.getAddress())) addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr());
protected void readResponse(GetResponse rsp, List<Address> mbrs, Responses responses) { if(rsp.object == null) return; byte[] buf=rsp.object.data; List<PingData> list; if(buf != null && buf.length > 0) { try { list=read(new ByteArrayInputStream(buf)); if(list != null) { for(PingData data : list) { if(mbrs == null || mbrs.contains(data.getAddress())) responses.addResponse(data, data.isCoord()); if(local_addr != null && !local_addr.equals(data.getAddress())) addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr()); } } } catch(Throwable e) { log.error(Util.getMessage("FailedUnmarshallingResponse"), e); } } }
@SuppressWarnings("unchecked") @Override public Object up(Event evt) { switch (evt.getType()) { case Event.FIND_MBRS: List<Address> missing = (List<Address>) evt.getArg(); Responses responses = new Responses(false); for (Address laddr : missing) { try { if (laddr instanceof JGAddress) { PingData pd = new PingData(laddr, true, laddr.toString(), newIpAddress(laddr)); responses.addResponse(pd, false); updateUDPCache(pd); } } catch (RuntimeException e) { logger.warn("Unable to create PingData response", e); throw e; } } return responses; } return up_prot.up(evt); }
@Override protected void readAll(List<Address> members, String clustername, Responses responses) { try { List<String> objects = swiftClient.listObjects(container); for(String object: objects) { List<PingData> list=null; byte[] bytes = swiftClient.readObject(container, object); if((list=read(new ByteArrayInputStream(bytes))) == null) { log.warn("failed reading " + object); continue; } for(PingData data: list) { if(members == null || members.contains(data.getAddress())) responses.addResponse(data, data.isCoord()); if(local_addr != null && !local_addr.equals(data.getAddress())) addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr()); } } } catch (Exception e) { log.error(Util.getMessage("ErrorUnmarshallingObject"), e); } }
@Override protected void readAll(List<Address> members, String clustername, Responses responses) { try { List<String> objects = rackspaceClient.listObjects(container); for(String object: objects) { List<PingData> list=null; byte[] bytes = rackspaceClient.readObject(container, object); if((list=read(new ByteArrayInputStream(bytes))) == null) { log.warn("failed reading " + object); continue; } for(PingData data: list) { if(members == null || members.contains(data.getAddress())) responses.addResponse(data, data.isCoord()); if(local_addr != null && !local_addr.equals(data.getAddress())) addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr()); } } } catch (Exception e) { log.error(Util.getMessage("ErrorUnmarshallingObject"), e); } }
@Override public void findMembers(List<Address> members, boolean initial_discovery, Responses responses) { num_discovery_requests++; List<PingData> retval=(List<PingData>)down_prot.down(new Event(Event.GET_PING_DATA, cluster_name)); if(retval != null) retval.stream().filter(data -> !data.getAddress().equals(local_addr)).forEach(data -> responses.addResponse(data, false)); responses.done(); // so waitFor() doesn't block at all }
protected void addResponse(PingData rsp, boolean overwrite) { if(discovery_rsp_callback != null) { try { discovery_rsp_callback.accept(rsp); } catch(Throwable t) { log.error("%s: failed invoking callback for discovery response: %s", local_addr, t); } } synchronized(ping_responses) { for(Iterator<Map.Entry<Long,Responses>> it=ping_responses.entrySet().iterator(); it.hasNext();) { Map.Entry<Long,Responses> entry=it.next(); long timestamp=entry.getKey(); Responses rsps=entry.getValue(); rsps.addResponse(rsp, overwrite); if(rsps.isDone() || TimeUnit.MILLISECONDS.convert(System.nanoTime() - timestamp, TimeUnit.NANOSECONDS) > discovery_rsp_expiry_time) { it.remove(); rsps.done(); } } } }
responses.addResponse(data, true); if(local_addr != null && !local_addr.equals(data.getAddress())) addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr());
@SuppressWarnings("unchecked") @Override public Object up(Event evt) { switch (evt.getType()) { case Event.FIND_MBRS: List<Address> missing = (List<Address>)evt.getArg(); Responses responses = new Responses(false); for (Address laddr: missing) { try { if (laddr instanceof JGAddress) { PingData pd = new PingData(laddr, true, laddr.toString(), newIpAddress(laddr)); responses.addResponse(pd, false); updateUDPCache(pd); } } catch (RuntimeException e) { logger.warn("Unable to create PingData response", e); throw e; } } return responses; } return up_prot.up(evt); }
if(data == null || (members != null && !members.contains(data.getAddress()))) continue; rsps.addResponse(data, false); if(local_addr != null && !local_addr.equals(data.getAddress())) addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr());
protected void parsePingData(final byte[] pingBytes, final List<Address> members, final Responses responses) { if (pingBytes == null || pingBytes.length <= 0) { return; } List<PingData> list; try { list = read(new ByteArrayInputStream(pingBytes)); if (list != null) { // This is a common piece of logic for all PING protocols copied from org/jgroups/protocols/FILE_PING.java:245 // Maybe could be extracted for all PING impls to share this logic? for (PingData data : list) { if (members == null || members.contains(data.getAddress())) { responses.addResponse(data, data.isCoord()); } if (local_addr != null && !local_addr.equals(data.getAddress())) { addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr()); } } // end copied block } } catch (Exception e) { log.error("Error unmarshalling ping data.", e); } }
protected void parsePingData(final byte[] pingBytes, final List<Address> members, final Responses responses) { if (pingBytes == null || pingBytes.length <= 0) { return; } List<PingData> list; try { list = read(new ByteArrayInputStream(pingBytes)); if (list != null) { // This is a common piece of logic for all PING protocols copied from org/jgroups/protocols/FILE_PING.java:245 // Maybe could be extracted for all PING impls to share this logic? for (PingData data : list) { if (members == null || members.contains(data.getAddress())) { responses.addResponse(data, data.isCoord()); } if (local_addr != null && !local_addr.equals(data.getAddress())) { addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr()); } } // end copied block } } catch (Exception e) { log.error("Error unmarshalling ping data.", e); } }
protected void readResponse(GetResponse rsp, List<Address> mbrs, Responses responses) { if(rsp.object == null) return; byte[] buf=rsp.object.data; List<PingData> list; if(buf != null && buf.length > 0) { try { list=read(new ByteArrayInputStream(buf)); if(list != null) { for(PingData data : list) { if(mbrs == null || mbrs.contains(data.getAddress())) responses.addResponse(data, data.isCoord()); if(local_addr != null && !local_addr.equals(data.getAddress())) addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr()); } } } catch(Throwable e) { log.error(Util.getMessage("FailedUnmarshallingResponse"), e); } } }
protected void readResponse(S3ObjectSummary summary, List<Address> members, Responses responses) { S3Object object = amazonS3.getObject(summary.getBucketName(), summary.getKey()); List<PingData> list; try { list = read(object.getObjectContent()); if (list != null) { for (PingData data : list) { if (members == null || members.contains(data.getAddress())) { responses.addResponse(data, data.isCoord()); } if (local_addr != null && !local_addr.equals(data.getAddress())) { addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr()); } } } } catch (Throwable e) { log.error("failed unmarshalling response", e); } }
@Override protected void readAll(List<Address> members, String clustername, Responses responses) { try { List<String> objects = swiftClient.listObjects(container); for(String object: objects) { List<PingData> list=null; byte[] bytes = swiftClient.readObject(container, object); if((list=read(new ByteArrayInputStream(bytes))) == null) { log.warn("failed reading " + object); continue; } for(PingData data: list) { if(members == null || members.contains(data.getAddress())) responses.addResponse(data, data.isCoord()); if(local_addr != null && !local_addr.equals(data.getAddress())) addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr()); } } } catch (Exception e) { log.error(Util.getMessage("ErrorUnmarshallingObject"), e); } }
@Override protected void readAll(List<Address> members, String clustername, Responses responses) { try { List<String> objects = rackspaceClient.listObjects(container); for(String object: objects) { List<PingData> list=null; byte[] bytes = rackspaceClient.readObject(container, object); if((list=read(new ByteArrayInputStream(bytes))) == null) { log.warn("failed reading " + object); continue; } for(PingData data: list) { if(members == null || members.contains(data.getAddress())) responses.addResponse(data, data.isCoord()); if(local_addr != null && !local_addr.equals(data.getAddress())) addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr()); } } } catch (Exception e) { log.error(Util.getMessage("ErrorUnmarshallingObject"), e); } }
private void addPingRsp(Responses rsps, TEST_PING discovery) { // Rather than relying on transport (PING) or your own multicast channel // (MPING), talk to other discovery instances directly via Java method // calls and discover the other nodes in the cluster. // Add mapping of remote's address -> physical addr to the local cache mapAddrWithPhysicalAddr(this, discovery); // Add mapping of local's address -> physical addr to the remote cache mapAddrWithPhysicalAddr(discovery, this); Address localAddr = discovery.getLocalAddr(); PhysicalAddress physicalAddr = (PhysicalAddress) discovery.down(new Event(Event.GET_PHYSICAL_ADDRESS, localAddr)); String logicalName = NameCache.get(localAddr); PingData pingRsp = new PingData(localAddr, discovery.isServer(), logicalName, physicalAddr).coord(discovery .is_coord); if (log.isTraceEnabled()) log.trace(String.format("Returning ping rsp: %s", pingRsp)); if (rsps != null) { rsps.addResponse(pingRsp, true); addResponse(pingRsp, true); } }