protected void write(List<PingData> list, OutputStream out) throws Exception { try { for(PingData data: list) { String logical_name=data.getLogicalName(); Address addr=data.getAddress(); PhysicalAddress phys_addr=data.getPhysicalAddr(); if(logical_name == null || addr == null || phys_addr == null) continue; out.write(logical_name.getBytes()); out.write(WHITESPACE); out.write(addressAsString(addr).getBytes()); out.write(WHITESPACE); out.write(phys_addr.toString().getBytes()); out.write(WHITESPACE); out.write(data.isCoord()? String.format("T%n").getBytes() : String.format("F%n").getBytes()); } } finally { Util.close(out); } }
protected void handleDiscoveryResponse(PingData data, Address sender) { // add physical address (if available) to transport's cache Address logical_addr=data.getAddress() != null? data.getAddress() : sender; addDiscoveryResponseToCaches(logical_addr, data.getLogicalName(), data.getPhysicalAddr()); boolean overwrite=Objects.equals(logical_addr, sender); addResponse(data, overwrite); }
responses.addResponse(data, true); if(local_addr != null && !local_addr.equals(data.getAddress())) addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr());
rsps.addResponse(data, false); if(local_addr != null && !local_addr.equals(data.getAddress())) addDiscoveryResponseToCaches(data.getAddress(), data.getLogicalName(), data.getPhysicalAddr());
@ManagedOperation(description="Reads logical-physical address mappings and logical name mappings from a " + "file (or URL) and adds them to the local caches") public void addToCache(String filename) throws Exception { InputStream in=ConfiguratorFactory.getConfigStream(filename); List<PingData> list=read(in); if(list != null) for(PingData data: list) 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); } } }
@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); } }
/** * Creates a byte[] representation of the PingData, but DISCARDING the view it contains. * @param data the PingData instance to serialize. * @return */ protected byte[] serializeWithoutView(PingData data) { final PingData clone = new PingData(data.getAddress(), data.isServer(), data.getLogicalName(), data.getPhysicalAddr()).coord(data.isCoord()); try { return Util.streamableToByteBuffer(clone); } catch(Exception e) { log.error(Util.getMessage("ErrorSerializingPingData"), e); return null; } }
addDiscoveryResponseToCaches(logical_addr, data.getLogicalName(), data.getPhysicalAddr()); discoveryRequestReceived(msg.getSrc(), data.getLogicalName(), data.getPhysicalAddr()); addResponse(data, false);
protected void write(List<PingData> list, OutputStream out) throws Exception { try { for(PingData data: list) { String logical_name=data.getLogicalName(); Address addr=data.getAddress(); PhysicalAddress phys_addr=data.getPhysicalAddr(); if(logical_name == null || addr == null || phys_addr == null) continue; out.write(logical_name.getBytes()); out.write(WHITESPACE); out.write(addressAsString(addr).getBytes()); out.write(WHITESPACE); out.write(phys_addr.toString().getBytes()); out.write(WHITESPACE); out.write(data.isCoord()? String.format("T%n").getBytes() : String.format("F%n").getBytes()); } } finally { Util.close(out); } }
protected void handleDiscoveryResponse(PingData data, Address sender) { // add physical address (if available) to transport's cache Address logical_addr=data.getAddress() != null? data.getAddress() : sender; addDiscoveryResponseToCaches(logical_addr, data.getLogicalName(), data.getPhysicalAddr()); boolean overwrite=Objects.equals(logical_addr, sender); addResponse(data, overwrite); }
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); } }
@ManagedOperation(description="Reads logical-physical address mappings and logical name mappings from a " + "file (or URL) and adds them to the local caches") public void addToCache(String filename) throws Exception { InputStream in=ConfiguratorFactory.getConfigStream(filename); List<PingData> list=read(in); if(list != null) for(PingData data: list) 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); } } }
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); } }
/** * Creates a byte[] representation of the PingData, but DISCARDING the view it contains. * @param data the PingData instance to serialize. * @return */ protected byte[] serializeWithoutView(PingData data) { final PingData clone = new PingData(data.getAddress(), data.isServer(), data.getLogicalName(), data.getPhysicalAddr()).coord(data.isCoord()); try { return Util.streamableToByteBuffer(clone); } catch(Exception e) { log.error(Util.getMessage("ErrorSerializingPingData"), e); return null; } }