use of org.jgroups.PhysicalAddress in project JGroups by belaban.
the class RegexMembership method authenticate.
public boolean authenticate(AuthToken token, Message msg) {
Address sender = msg.getSrc();
if (match_ip_address) {
PhysicalAddress src = sender != null ? (PhysicalAddress) auth.down(new Event(Event.GET_PHYSICAL_ADDRESS, sender)) : null;
String ip_addr = src != null ? src.toString() : null;
if (ip_addr != null) {
Matcher matcher = pattern.matcher(ip_addr);
boolean result = matcher.matches();
if (log.isTraceEnabled())
log.trace("matching ip_address: pattern= " + pattern + ", input= " + ip_addr + ", result= " + result);
if (result)
return true;
}
}
if (match_logical_name) {
String logical_name = sender != null ? NameCache.get(sender) : null;
if (logical_name != null) {
Matcher matcher = pattern.matcher(logical_name);
boolean result = matcher.matches();
if (log.isTraceEnabled())
log.trace("matching logical_name: pattern= " + pattern + ", input= " + logical_name + ", result= " + result);
if (result)
return true;
}
}
return false;
}
use of org.jgroups.PhysicalAddress in project JGroups by belaban.
the class BasicTCP method handleDownEvent.
protected Object handleDownEvent(Event evt) {
Object ret = super.handleDownEvent(evt);
if (evt.getType() == Event.VIEW_CHANGE) {
Set<Address> physical_mbrs = new HashSet<>();
for (Address addr : members) {
PhysicalAddress physical_addr = getPhysicalAddressFromCache(addr);
if (physical_addr != null)
physical_mbrs.add(physical_addr);
}
// remove all connections which are not members
retainAll(physical_mbrs);
}
return ret;
}
use of org.jgroups.PhysicalAddress in project JGroups by belaban.
the class TCPGOSSIP method members.
@Override
public void members(List<PingData> mbrs) {
PhysicalAddress own_physical_addr = (PhysicalAddress) down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr));
PingData data = new PingData(local_addr, false, org.jgroups.util.NameCache.get(local_addr), own_physical_addr);
PingHeader hdr = new PingHeader(PingHeader.GET_MBRS_REQ).clusterName(cluster_name);
Set<PhysicalAddress> physical_addrs = mbrs.stream().filter(ping_data -> ping_data != null && ping_data.getPhysicalAddr() != null).map(PingData::getPhysicalAddr).collect(Collectors.toSet());
for (PhysicalAddress physical_addr : physical_addrs) {
if (// no need to send the request to myself
physical_addr != null && own_physical_addr.equals(physical_addr))
continue;
// the message needs to be DONT_BUNDLE, see explanation above
final Message msg = new Message(physical_addr).setFlag(Message.Flag.INTERNAL, Message.Flag.DONT_BUNDLE, Message.Flag.OOB).putHeader(this.id, hdr).setBuffer(marshal(data));
log.trace("%s: sending discovery request to %s", local_addr, msg.getDest());
down_prot.down(msg);
}
}
use of org.jgroups.PhysicalAddress in project JGroups by belaban.
the class DNS_PING method down.
@Override
public Object down(Event evt) {
Object retval = super.down(evt);
switch(evt.getType()) {
case Event.VIEW_CHANGE:
for (Address logical_addr : view.getMembersRaw()) {
PhysicalAddress physical_addr = (PhysicalAddress) down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESS, logical_addr));
if (physical_addr != null) {
discovered_hosts.addIfAbsent(physical_addr);
}
}
break;
case Event.SUSPECT:
Collection<Address> addresses = evt.getArg() instanceof Address ? Collections.singletonList(evt.arg()) : evt.arg();
discovered_hosts.removeAll(addresses);
break;
case Event.ADD_PHYSICAL_ADDRESS:
Tuple<Address, PhysicalAddress> tuple = evt.getArg();
PhysicalAddress physical_addr = tuple.getVal2();
if (physical_addr != null)
discovered_hosts.addIfAbsent(physical_addr);
break;
}
return retval;
}
use of org.jgroups.PhysicalAddress in project JGroups by belaban.
the class FILE_PING method writeAll.
protected void writeAll(Address[] excluded_mbrs) {
Map<Address, PhysicalAddress> cache_contents = (Map<Address, PhysicalAddress>) down_prot.down(new Event(Event.GET_LOGICAL_PHYSICAL_MAPPINGS, false));
if (excluded_mbrs != null)
for (Address excluded_mbr : excluded_mbrs) cache_contents.remove(excluded_mbr);
List<PingData> list = new ArrayList<>(cache_contents.size());
for (Map.Entry<Address, PhysicalAddress> entry : cache_contents.entrySet()) {
Address addr = entry.getKey();
if (update_store_on_view_change && (view != null && !view.containsMember(addr)))
continue;
PhysicalAddress phys_addr = entry.getValue();
PingData data = new PingData(addr, true, NameCache.get(addr), phys_addr).coord(addr.equals(local_addr));
list.add(data);
}
write(list, cluster_name);
if (log.isTraceEnabled())
log.trace("wrote to backend store: %s", list.stream().map(PingData::getAddress).collect(Collectors.toList()));
}
Aggregations