Search in sources :

Example 6 with PhysicalAddress

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;
}
Also used : PhysicalAddress(org.jgroups.PhysicalAddress) Address(org.jgroups.Address) Matcher(java.util.regex.Matcher) Event(org.jgroups.Event) PhysicalAddress(org.jgroups.PhysicalAddress)

Example 7 with PhysicalAddress

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;
}
Also used : LocalAddress(org.jgroups.annotations.LocalAddress) InetAddress(java.net.InetAddress) PhysicalAddress(org.jgroups.PhysicalAddress) Address(org.jgroups.Address) PhysicalAddress(org.jgroups.PhysicalAddress) HashSet(java.util.HashSet)

Example 8 with PhysicalAddress

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);
    }
}
Also used : Message(org.jgroups.Message) Event(org.jgroups.Event) PhysicalAddress(org.jgroups.PhysicalAddress)

Example 9 with PhysicalAddress

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;
}
Also used : IpAddress(org.jgroups.stack.IpAddress) PhysicalAddress(org.jgroups.PhysicalAddress) Address(org.jgroups.Address) Event(org.jgroups.Event) PhysicalAddress(org.jgroups.PhysicalAddress)

Example 10 with PhysicalAddress

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()));
}
Also used : PhysicalAddress(org.jgroups.PhysicalAddress) Address(org.jgroups.Address) ArrayList(java.util.ArrayList) Event(org.jgroups.Event) PhysicalAddress(org.jgroups.PhysicalAddress) Map(java.util.Map)

Aggregations

PhysicalAddress (org.jgroups.PhysicalAddress)13 Address (org.jgroups.Address)9 Event (org.jgroups.Event)9 InetAddress (java.net.InetAddress)4 IpAddress (org.jgroups.stack.IpAddress)4 Message (org.jgroups.Message)3 InetSocketAddress (java.net.InetSocketAddress)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 PingData (org.jgroups.protocols.PingData)2 RouterStubManager (org.jgroups.stack.RouterStubManager)2 java.io (java.io)1 FileChannel (java.nio.channels.FileChannel)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 View (org.jgroups.View)1 LocalAddress (org.jgroups.annotations.LocalAddress)1