use of org.jgroups.protocols.TCPPING in project JGroups by belaban.
the class ChannelTestBase method makeUnique.
protected void makeUnique(JChannel... channels) throws Exception {
String mcast_addr = Util.getProperty(new String[] { Global.UDP_MCAST_ADDR, "jboss.partition.udpGroup" }, null, "mcast_addr", null);
boolean is_udp = Stream.of(channels).anyMatch(ch -> ch.getProtocolStack().getTransport() instanceof UDP), is_tcp = Stream.of(channels).anyMatch(ch -> ch.getProtocolStack().getTransport() instanceof BasicTCP);
if (is_udp) {
InetAddress mcast = mcast_addr != null ? InetAddress.getByName(mcast_addr) : InetAddress.getByName(ResourceManager.getNextMulticastAddress());
int mcast_port = ResourceManager.getNextMulticastPort(bind_addr);
for (JChannel ch : channels) {
UDP udp = (UDP) ch.getProtocolStack().getTransport();
udp.setBindAddress(bind_addr);
udp.setMulticastAddress(mcast).setMulticastPort(mcast_port);
}
} else if (is_tcp) {
List<Integer> ports = ResourceManager.getNextTcpPorts(bind_addr, channels.length);
Collection<InetSocketAddress> hosts = ports.stream().map(p -> new InetSocketAddress(bind_addr, p)).collect(Collectors.toList());
for (int i = 0; i < channels.length; i++) {
ProtocolStack stack = channels[i].getProtocolStack();
TP tp = stack.getTransport();
tp.setBindPort(ports.get(i));
TCPPING ping = stack.findProtocol(TCPPING.class);
if (ping == null)
throw new IllegalStateException("TCP stack must consist of TCP:TCPPING - other configs are not supported");
ping.setInitialHosts(hosts);
}
} else
throw new IllegalStateException("Only UDP and TCP are supported as transport protocols");
}
Aggregations