Search in sources :

Example 1 with PhysicalAddress

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);
    }
}
Also used : PingData(org.jgroups.protocols.PingData) InetAddress(java.net.InetAddress) PhysicalAddress(org.jgroups.PhysicalAddress) Address(org.jgroups.Address) PhysicalAddress(org.jgroups.PhysicalAddress) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 2 with PhysicalAddress

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);
}
Also used : Property(org.jgroups.annotations.Property) Protocol(org.jgroups.stack.Protocol) Event(org.jgroups.Event) UUID(org.jgroups.util.UUID) java.util(java.util) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) PhysicalAddress(org.jgroups.PhysicalAddress) org.jgroups.util(org.jgroups.util) java.io(java.io) ManagedOperation(org.jgroups.annotations.ManagedOperation) MBean(org.jgroups.annotations.MBean) Address(org.jgroups.Address) FileChannel(java.nio.channels.FileChannel) View(org.jgroups.View) PhysicalAddress(org.jgroups.PhysicalAddress) Address(org.jgroups.Address) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PhysicalAddress(org.jgroups.PhysicalAddress) View(org.jgroups.View) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 3 with PhysicalAddress

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();
    }
}
Also used : RouterStub(org.jgroups.stack.RouterStub) RouterStubManager(org.jgroups.stack.RouterStubManager) InetSocketAddress(java.net.InetSocketAddress) Event(org.jgroups.Event) PhysicalAddress(org.jgroups.PhysicalAddress) IpAddress(org.jgroups.stack.IpAddress) InetAddress(java.net.InetAddress)

Example 4 with PhysicalAddress

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

Example 5 with PhysicalAddress

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

Aggregations

PhysicalAddress (org.jgroups.PhysicalAddress)16 Event (org.jgroups.Event)11 Address (org.jgroups.Address)10 IpAddress (org.jgroups.stack.IpAddress)6 InetAddress (java.net.InetAddress)4 Message (org.jgroups.Message)4 PingData (org.jgroups.protocols.PingData)3 InetSocketAddress (java.net.InetSocketAddress)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 PingHeader (org.jgroups.protocols.PingHeader)2 RouterStubManager (org.jgroups.stack.RouterStubManager)2 Container (io.fabric8.kubernetes.api.model.Container)1 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 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