use of org.jgroups.PhysicalAddress in project JGroups by belaban.
the class GossipRouter method handleGetMembersRequest.
protected void handleGetMembersRequest(Address sender, DataInput in) {
GossipData req = readRequest(in, GossipType.GET_MBRS);
if (req == null)
return;
GossipData rsp = new GossipData(GossipType.GET_MBRS_RSP, req.getGroup(), null);
Map<Address, Entry> members = address_mappings.get(req.getGroup());
if (members != null) {
for (Map.Entry<Address, Entry> entry : members.entrySet()) {
Address logical_addr = entry.getKey();
PhysicalAddress phys_addr = entry.getValue().phys_addr;
String logical_name = entry.getValue().logical_name;
PingData data = new PingData(logical_addr, true, logical_name, phys_addr);
rsp.addPingData(data);
}
}
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream(rsp.serializedSize());
try {
rsp.writeTo(out);
server.send(sender, out.buffer(), 0, out.position());
} catch (Exception ex) {
log.error("failed sending %d to %s: %s", GossipType.GET_MBRS_RSP, sender, ex);
}
}
use of org.jgroups.PhysicalAddress in project JGroups by belaban.
the class PDC method down.
public Object down(Event evt) {
switch(evt.getType()) {
case Event.GET_PHYSICAL_ADDRESS:
Object addr = down_prot.down(evt);
Address arg = evt.getArg();
return addr != null ? addr : cache.get(arg);
case Event.GET_PHYSICAL_ADDRESSES:
Collection<PhysicalAddress> addrs = (Collection<PhysicalAddress>) down_prot.down(evt);
Collection<PhysicalAddress> tmp = new HashSet<>(addrs);
tmp.addAll(cache.values());
return tmp;
case Event.GET_LOGICAL_PHYSICAL_MAPPINGS:
Map<Address, PhysicalAddress> map = (Map<Address, PhysicalAddress>) down_prot.down(evt);
Map<Address, PhysicalAddress> new_map = new HashMap<>(map);
new_map.putAll(cache);
return new_map;
case Event.ADD_PHYSICAL_ADDRESS:
Tuple<Address, PhysicalAddress> new_val = evt.getArg();
if (new_val != null) {
cache.put(new_val.getVal1(), new_val.getVal2());
writeNodeToDisk(new_val.getVal1(), new_val.getVal2());
}
break;
case Event.REMOVE_ADDRESS:
Address tmp_addr = evt.getArg();
if (cache.remove(tmp_addr) != null)
removeNodeFromDisk(tmp_addr);
break;
case Event.SET_LOCAL_ADDRESS:
local_addr = evt.getArg();
break;
case Event.VIEW_CHANGE:
List<Address> members = ((View) evt.getArg()).getMembers();
cache.keySet().stream().filter(mbr -> !members.contains(mbr)).forEach(mbr -> {
cache.remove(mbr);
removeNodeFromDisk(mbr);
});
break;
}
return down_prot.down(evt);
}
use of org.jgroups.PhysicalAddress in project JGroups by belaban.
the class TCPGOSSIP method handleConnect.
public void handleConnect() {
if (cluster_name == null || local_addr == null)
log.error(Util.getMessage("GroupaddrOrLocaladdrIsNullCannotRegisterWithGossipRouterS"));
else {
InetAddress bind_addr = getTransport().getBindAddress();
log.trace("registering " + local_addr + " under " + cluster_name + " with GossipRouter");
stubManager.destroyStubs();
PhysicalAddress physical_addr = (PhysicalAddress) down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr));
stubManager = new RouterStubManager(this, cluster_name, local_addr, NameCache.get(local_addr), physical_addr, reconnect_interval).useNio(this.use_nio);
for (InetSocketAddress host : initial_hosts) {
RouterStub stub = stubManager.createAndRegisterStub(new IpAddress(bind_addr, 0), new IpAddress(host.getAddress(), host.getPort()));
stub.socketConnectionTimeout(sock_conn_timeout);
}
stubManager.connectStubs();
}
}
use of org.jgroups.PhysicalAddress 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.PhysicalAddress 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;
if (!use_ip_addrs || !initial_discovery) {
log.debug("Performing initial discovery");
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);
}
List<Address> dns_discovery_members = dns_resolver.resolveIps(dns_query, DNSResolver.DNSRecordType.valueOf(dns_record_type));
log.debug("Entries collected from DNS: %s", dns_discovery_members);
if (dns_discovery_members != null) {
for (Address address : dns_discovery_members) {
if (physical_addr != null && address.equals(physical_addr)) {
// no need to send the request to myself
continue;
}
Address addressToBeAdded = address;
if (address instanceof IpAddress) {
IpAddress ip = ((IpAddress) address);
if (ip.getPort() == 0) {
log.debug("Discovered IP Address with port 0 (%s). Replacing with default Transport port: %d", ip.printIpAddress(), transportPort);
addressToBeAdded = new IpAddress(ip.getIpAddress(), transportPort);
}
}
discovered_hosts.addIfAbsent(addressToBeAdded);
}
}
log.debug("Performing discovery of the following hosts %s", discovered_hosts.toString());
PingHeader hdr = new PingHeader(PingHeader.GET_MBRS_REQ).clusterName(cluster_name).initialDiscovery(initial_discovery);
for (final Address addr : discovered_hosts) {
// the message needs to be DONT_BUNDLE, see explanation above
final Message msg = new Message(addr).setFlag(Message.Flag.INTERNAL, Message.Flag.DONT_BUNDLE, Message.Flag.OOB).putHeader(this.id, hdr);
if (data != null)
msg.setBuffer(marshal(data));
if (async_discovery_use_separate_thread_per_request)
timer.execute(() -> sendDiscoveryRequest(msg), sends_can_block);
else
sendDiscoveryRequest(msg);
}
}
Aggregations