use of org.jgroups.stack.IpAddress in project JGroups by belaban.
the class SimpleTCP method sendTo.
protected void sendTo(Address dest, byte[] buffer, int offset, int length) throws Exception {
SocketAddress physical_dest = null;
if (dest instanceof IpAddress) {
IpAddress ip_addr = (IpAddress) dest;
physical_dest = new InetSocketAddress(ip_addr.getIpAddress(), ip_addr.getPort());
} else
physical_dest = addr_table.get(dest);
if (physical_dest == null)
throw new Exception(String.format("physical address for %s not found", dest));
Connection conn = getConnection(physical_dest);
conn.send(buffer, offset, length);
}
use of org.jgroups.stack.IpAddress in project JGroups by belaban.
the class SimpleTCP method down.
public Object down(Event evt) {
Object retval = super.down(evt);
switch(evt.type()) {
case Event.ADD_PHYSICAL_ADDRESS:
Tuple<Address, PhysicalAddress> tuple = evt.arg();
IpAddress val = (IpAddress) tuple.getVal2();
addr_table.put(tuple.getVal1(), new InetSocketAddress(val.getIpAddress(), val.getPort()));
break;
case Event.VIEW_CHANGE:
for (Iterator<Map.Entry<Address, SocketAddress>> it = addr_table.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<Address, SocketAddress> entry = it.next();
if (!view.containsMember(entry.getKey())) {
SocketAddress sock_addr = entry.getValue();
it.remove();
Connection conn = connections.remove(sock_addr);
Util.close(conn);
}
}
break;
}
return retval;
}
use of org.jgroups.stack.IpAddress in project JGroups by belaban.
the class TCPPING method setInitialHosts.
public <T extends TCPPING> T setInitialHosts(Collection<InetSocketAddress> hosts) {
if (hosts == null || hosts.isEmpty())
return (T) this;
initial_hosts = hosts.stream().map(h -> new IpAddress(h.getAddress(), h.getPort())).collect(Collectors.toList());
initial_hosts_str = hostsToStr(initial_hosts);
initial_hosts_set_programmatically = true;
return (T) this;
}
use of org.jgroups.stack.IpAddress in project JGroups by belaban.
the class UDP method createSockets.
/**
* Creates the UDP sender and receiver sockets
*/
protected void createSockets() throws Exception {
if (bind_addr == null)
throw new IllegalArgumentException("bind_addr cannot be null");
Util.checkIfValidAddress(bind_addr, getName());
if (log.isDebugEnabled())
log.debug("sockets will use interface " + bind_addr.getHostAddress());
if (bind_port > 0)
sock = createMulticastSocketWithBindPort();
else
sock = createMulticastSocket("jgroups.udp.sock", 0);
setTimeToLive(ip_ttl, sock);
if (tos > 0) {
try {
sock.setTrafficClass(tos);
} catch (SocketException e) {
log.warn(Util.getMessage("TrafficClass"), tos, e);
}
}
// 3. Create socket for receiving IP multicast packets
if (ip_mcast) {
// This acts like a filter, dropping multicasts to different multicast addresses
if (Util.can_bind_to_mcast_addr)
mcast_sock = Util.createMulticastSocket(getSocketFactory(), "jgroups.udp.mcast_sock", mcast_group_addr, mcast_port, log);
else
mcast_sock = getSocketFactory().createMulticastSocket("jgroups.udp.mcast_sock", mcast_port);
if (disable_loopback) {
mcast_sock.setLoopbackMode(true);
sock.setLoopbackMode(true);
}
mcast_addr = new IpAddress(mcast_group_addr, mcast_port);
// check that we're not using the same mcast address and port as the diagnostics socket
if (diag_handler.isEnabled() && diag_handler.getMcastAddress().equals(mcast_group_addr) && diag_handler.getPort() == mcast_port)
throw new IllegalArgumentException("diagnostics_addr:diagnostics_port and mcast_addr:mcast_port " + "have to be different");
if (tos > 0) {
try {
mcast_sock.setTrafficClass(tos);
} catch (SocketException e) {
log.warn(Util.getMessage("TrafficClass"), tos, e);
}
}
if (receive_on_all_interfaces || (receive_interfaces != null && !receive_interfaces.isEmpty())) {
List<NetworkInterface> interfaces;
if (receive_interfaces != null)
interfaces = receive_interfaces;
else
interfaces = Util.getAllAvailableInterfaces();
bindToInterfaces(interfaces, mcast_sock, mcast_addr.getIpAddress());
} else {
if (bind_addr != null)
// not strictly needed for receiving, only for sending of mcasts
setNetworkInterface(bind_addr, mcast_sock);
mcast_sock.joinGroup(new InetSocketAddress(mcast_group_addr, mcast_port), bind_addr == null ? null : NetworkInterface.getByInetAddress(bind_addr));
}
}
setBufferSizes();
log.debug("socket information:\n%s", dumpSocketInfo());
}
use of org.jgroups.stack.IpAddress in project JGroups by belaban.
the class SHARED_LOOPBACK method init.
public void init() throws Exception {
super.init();
physical_addr = new IpAddress(InetAddress.getLoopbackAddress(), port++);
}
Aggregations