Search in sources :

Example 1 with PingHeader

use of org.jgroups.protocols.PingHeader in project JGroups by belaban.

the class MessageTest method addHeaders.

protected static void addHeaders(Message msg) {
    TpHeader tp_hdr = new TpHeader("DemoChannel2");
    msg.putHeader(UDP_ID, tp_hdr);
    PingHeader ping_hdr = new PingHeader(PingHeader.GET_MBRS_REQ).clusterName("demo-cluster");
    msg.putHeader(PING_ID, ping_hdr);
    NakAckHeader2 nak_hdr = NakAckHeader2.createXmitRequestHeader(Util.createRandomAddress("S"));
    msg.putHeader(NAKACK_ID, nak_hdr);
}
Also used : NakAckHeader2(org.jgroups.protocols.pbcast.NakAckHeader2) PingHeader(org.jgroups.protocols.PingHeader) TpHeader(org.jgroups.protocols.TpHeader)

Example 2 with PingHeader

use of org.jgroups.protocols.PingHeader 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)

Example 3 with PingHeader

use of org.jgroups.protocols.PingHeader in project fabric8 by fabric8io.

the class KubernetesDiscovery method findMembers.

@Override
public void findMembers(List<Address> members, boolean initial_discovery, Responses responses) {
    kubernetesHosts = findKubernetesHosts();
    PhysicalAddress physical_addr = (PhysicalAddress) down(new Event(Event.GET_PHYSICAL_ADDRESS, local_addr));
    // https://issues.jboss.org/browse/JGRP-1670
    PingData data = new PingData(local_addr, false, org.jgroups.util.UUID.get(local_addr), physical_addr);
    PingHeader hdr = new PingHeader(PingHeader.GET_MBRS_REQ).clusterName(cluster_name);
    Set<PhysicalAddress> cluster_members = new HashSet<>(kubernetesHosts);
    cluster_members.addAll(dynamic_hosts);
    if (use_disk_cache) {
        // this only makes sense if we have PDC below us
        Collection<PhysicalAddress> list = (Collection<PhysicalAddress>) down_prot.down(new Event(Event.GET_PHYSICAL_ADDRESSES));
        if (list != null)
            for (PhysicalAddress phys_addr : list) if (!cluster_members.contains(phys_addr))
                cluster_members.add(phys_addr);
    }
    for (final PhysicalAddress addr : cluster_members) {
        if (// no need to send the request to myself
        physical_addr != null && addr.equals(physical_addr))
            continue;
        // 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).setBuffer(marshal(data));
        log.trace("%s: sending discovery request to %s", local_addr, msg.getDest());
        down_prot.down(new Event(Event.MSG, msg));
    }
}
Also used : PingData(org.jgroups.protocols.PingData) Message(org.jgroups.Message) Event(org.jgroups.Event) PhysicalAddress(org.jgroups.PhysicalAddress) PingHeader(org.jgroups.protocols.PingHeader)

Example 4 with PingHeader

use of org.jgroups.protocols.PingHeader in project JGroups by belaban.

the class StreamableTest method testHeaders.

public static void testHeaders() throws Exception {
    Address dest = UUID.randomUUID();
    Address src = UUID.randomUUID();
    Message msg = new Message(dest, "Hello world".getBytes()).src(src);
    PingHeader hdr = new PingHeader(PingHeader.GET_MBRS_REQ);
    msg.putHeader(PING_ID, hdr);
    TpHeader udp_hdr = new TpHeader("bla");
    msg.putHeader(UDP_ID, udp_hdr);
    stream(msg);
}
Also used : PingHeader(org.jgroups.protocols.PingHeader) TpHeader(org.jgroups.protocols.TpHeader)

Aggregations

PingHeader (org.jgroups.protocols.PingHeader)4 Event (org.jgroups.Event)2 Message (org.jgroups.Message)2 PhysicalAddress (org.jgroups.PhysicalAddress)2 PingData (org.jgroups.protocols.PingData)2 TpHeader (org.jgroups.protocols.TpHeader)2 Address (org.jgroups.Address)1 NakAckHeader2 (org.jgroups.protocols.pbcast.NakAckHeader2)1 IpAddress (org.jgroups.stack.IpAddress)1