use of org.jgroups.stack.IpAddress in project JGroups by belaban.
the class TUNNEL method handleDownEvent.
public Object handleDownEvent(Event evt) {
Object retEvent = super.handleDownEvent(evt);
switch(evt.getType()) {
case Event.CONNECT:
case Event.CONNECT_WITH_STATE_TRANSFER:
case Event.CONNECT_USE_FLUSH:
case Event.CONNECT_WITH_STATE_TRANSFER_USE_FLUSH:
String group = evt.getArg();
Address local = local_addr;
if (stubManager != null)
stubManager.destroyStubs();
PhysicalAddress physical_addr = getPhysicalAddressFromCache(local);
String logical_name = org.jgroups.util.NameCache.get(local);
stubManager = new RouterStubManager(this, group, local, logical_name, physical_addr, getReconnectInterval()).useNio(this.use_nio);
for (InetSocketAddress gr : gossip_router_hosts) {
stubManager.createAndRegisterStub(new IpAddress(bind_addr, bind_port), new IpAddress(gr.getAddress(), gr.getPort())).receiver(this).set("tcp_nodelay", tcp_nodelay);
}
stubManager.connectStubs();
break;
case Event.DISCONNECT:
disconnectStub();
break;
}
return retEvent;
}
use of org.jgroups.stack.IpAddress in project wildfly by wildfly.
the class AddressableNodeMarshaller method writeTo.
@Override
public void writeTo(ProtoStreamWriter writer, AddressableNode member) throws IOException {
Address address = member.getAddress();
AddressMarshaller.INSTANCE.writeFields(writer, ADDRESS_INDEX, address);
writer.writeString(NAME_INDEX, member.getName());
if (!(address instanceof IpAddress)) {
writer.writeObject(SOCKET_ADDRESS_INDEX, new IpAddress(member.getSocketAddress()));
}
}
use of org.jgroups.stack.IpAddress in project wildfly by wildfly.
the class AddressableNodeMarshaller method readFrom.
@Override
public AddressableNode readFrom(ProtoStreamReader reader) throws IOException {
Address address = null;
String name = null;
InetSocketAddress socketAddress = null;
while (!reader.isAtEnd()) {
int tag = reader.readTag();
int index = WireType.getTagFieldNumber(tag);
if (index >= ADDRESS_INDEX && index < NAME_INDEX) {
address = AddressMarshaller.INSTANCE.readField(reader, index - ADDRESS_INDEX, address);
} else if (index == NAME_INDEX) {
name = reader.readString();
} else if (index == SOCKET_ADDRESS_INDEX) {
IpAddress ipAddress = reader.readObject(IpAddress.class);
socketAddress = new InetSocketAddress(ipAddress.getIpAddress(), ipAddress.getPort());
} else {
reader.skipField(tag);
}
}
return (address instanceof IpAddress) ? new AddressableNode((IpAddress) address, name) : new AddressableNode(address, name, socketAddress);
}
use of org.jgroups.stack.IpAddress in project wildfly by wildfly.
the class ChannelCommandDispatcherFactory method createNode.
@Override
public Node createNode(Address address) {
return this.members.computeIfAbsent(address, key -> {
IpAddress ipAddress = (IpAddress) this.dispatcher.getChannel().down(new Event(Event.GET_PHYSICAL_ADDRESS, address));
// Physical address might be null if node is no longer a member of the cluster
InetSocketAddress socketAddress = (ipAddress != null) ? new InetSocketAddress(ipAddress.getIpAddress(), ipAddress.getPort()) : new InetSocketAddress(0);
// If no logical name exists, create one using physical address
String name = Optional.ofNullable(NameCache.get(address)).orElseGet(() -> String.format("%s:%s", socketAddress.getHostString(), socketAddress.getPort()));
return new AddressableNode(address, name, socketAddress);
});
}
use of org.jgroups.stack.IpAddress in project JGroups by belaban.
the class DNS_PING method findMembers.
@Override
public void findMembers(List<Address> members, boolean initial_discovery, Responses responses) {
PingData data = null;
PhysicalAddress physical_addr = null;
Set<PhysicalAddress> cluster_members = new LinkedHashSet<>();
DNSResolver.DNSRecordType record_type = DNSResolver.DNSRecordType.valueOf(dns_record_type);
physical_addr = (PhysicalAddress) down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr));
// https://issues.jboss.org/browse/JGRP-1670
data = new PingData(local_addr, false, NameCache.get(local_addr), physical_addr);
if (members != null && members.size() <= max_members_in_discovery_request)
data.mbrs(members);
long start = System.currentTimeMillis();
List<Address> dns_discovery_members = getMembers(dns_query, record_type);
long time = System.currentTimeMillis() - start;
if (log.isDebugEnabled()) {
if (dns_discovery_members != null && !dns_discovery_members.isEmpty())
log.debug("%s: entries collected from DNS (in %d ms): %s", local_addr, time, dns_discovery_members);
else
log.debug("%s: no entries collected from DNS (in %d ms)", local_addr, time);
}
boolean ports_found = false;
if (dns_discovery_members != null) {
for (Address address : dns_discovery_members) {
if (// no need to send the request to myself
address.equals(physical_addr))
continue;
if (address instanceof IpAddress) {
IpAddress ip = ((IpAddress) address);
if (record_type == DNSResolver.DNSRecordType.SRV && ip.getPort() > 0) {
ports_found = true;
cluster_members.add(ip);
if (!probe_transport_ports)
continue;
}
for (int i = 0; i <= portRange; i++) cluster_members.add(new IpAddress(ip.getIpAddress(), transportPort + i));
}
}
}
if (dns_discovery_members != null && !dns_discovery_members.isEmpty() && log.isDebugEnabled()) {
if (ports_found)
log.debug("%s: sending discovery requests to %s", local_addr, cluster_members);
else
log.debug("%s: sending discovery requests to hosts %s on ports [%d .. %d]", local_addr, dns_discovery_members, transportPort, transportPort + portRange);
}
ByteArray data_buf = data != null ? marshal(data) : null;
PingHeader hdr = new PingHeader(PingHeader.GET_MBRS_REQ).clusterName(cluster_name).initialDiscovery(initial_discovery);
for (Address addr : cluster_members) {
// the message needs to be DONT_BUNDLE, see explanation above
final Message msg = new BytesMessage(addr).setFlag(DONT_BUNDLE, OOB).setFlag(DONT_LOOPBACK).putHeader(this.id, hdr);
if (data_buf != null)
msg.setArray(data_buf);
if (async_discovery_use_separate_thread_per_request)
timer.execute(() -> sendDiscoveryRequest(msg), sends_can_block);
else
sendDiscoveryRequest(msg);
}
}
Aggregations