Search in sources :

Example 41 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class UtilTest method testWriteAddress.

public void testWriteAddress() throws Exception {
    Address a1 = Util.createRandomAddress();
    Address a2 = Util.createRandomAddress();
    Address a4 = Util.createRandomAddress();
    Address a5 = new IpAddress("127.0.0.1", 5555);
    ByteArrayOutputStream outstream = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(outstream);
    Util.writeAddress(a1, dos);
    Util.writeAddress(a2, dos);
    Util.writeAddress(a4, dos);
    Util.writeAddress(a5, dos);
    dos.close();
    byte[] buf = outstream.toByteArray();
    ByteArrayInputStream instream = new ByteArrayInputStream(buf);
    DataInputStream dis = new DataInputStream(instream);
    Assert.assertEquals(a1, Util.readAddress(dis));
    Assert.assertEquals(a2, Util.readAddress(dis));
    Assert.assertEquals(a4, Util.readAddress(dis));
    Address tmp = Util.readAddress(dis);
    assert a5.equals(tmp);
}
Also used : IpAddress(org.jgroups.stack.IpAddress) IpAddress(org.jgroups.stack.IpAddress)

Example 42 with IpAddress

use of org.jgroups.stack.IpAddress in project fabric8 by jboss-fuse.

the class KubernetesDiscovery method findKubernetesHosts.

public List<PhysicalAddress> findKubernetesHosts() {
    List<PhysicalAddress> addresses = new ArrayList<>();
    Map<String, String> labels = Collections.singletonMap(Constants.JGROUPS_CLUSTER_NAME, cluster_name);
    for (Pod pod : client.pods().withLabels(labels).list().getItems()) {
        List<Container> containers = KubernetesHelper.getContainers(pod);
        for (Container container : containers) {
            for (ContainerPort port : container.getPorts()) {
                if (Constants.JGROUPS_TCP_PORT.equals(port.getName())) {
                    try {
                        String ip = pod.getStatus().getPodIP();
                        if (ip != null) {
                            addresses.add(new IpAddress(ip, port.getContainerPort()));
                        }
                    } catch (Exception ex) {
                        LOGGER.warn("Failed to create Address {}.", pod.getStatus().getPodIP());
                    }
                }
            }
        }
    }
    return addresses;
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) ContainerPort(io.fabric8.kubernetes.api.model.ContainerPort) PhysicalAddress(org.jgroups.PhysicalAddress) IpAddress(org.jgroups.stack.IpAddress)

Example 43 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class SizeTest method testFdHeaders.

public void testFdHeaders() throws Exception {
    IpAddress a1 = new IpAddress("127.0.0.1", 5555);
    IpAddress a2 = new IpAddress("127.0.0.1", 6666);
    FD_SOCK.FdHeader sockhdr = new FD_SOCK.FdHeader(FD_SOCK.FdHeader.GET_CACHE);
    _testSize(sockhdr);
    sockhdr = new FD_SOCK.FdHeader(FD_SOCK.FdHeader.SUSPECT, new IpAddress("127.0.0.1", 5555));
    _testSize(sockhdr);
    Set<Address> tmp = Set.of(a1, a2);
    sockhdr = new FD_SOCK.FdHeader(FD_SOCK.FdHeader.SUSPECT);
    _testSize(sockhdr);
    sockhdr.mbrs(tmp);
    _testSize(sockhdr);
    FD_SOCK2.FdHeader hdr = new FD_SOCK2.FdHeader(FD_SOCK2.FdHeader.SUSPECT);
    _testSize(hdr);
    hdr.mbrs(tmp);
    _testSize(hdr);
    hdr = new FD_SOCK2.FdHeader(FD_SOCK2.FdHeader.CONNECT_RSP);
    hdr.serverAddress(a1);
    _testSize(hdr);
    hdr.cluster("demo");
    _testSize(hdr);
}
Also used : IpAddress(org.jgroups.stack.IpAddress) IpAddress(org.jgroups.stack.IpAddress)

Example 44 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class SizeTest method testIpAddressWithHighPort.

public static void testIpAddressWithHighPort() throws Exception {
    IpAddress addr = new IpAddress("127.0.0.1", 65535);
    _testSize(addr);
}
Also used : IpAddress(org.jgroups.stack.IpAddress)

Example 45 with IpAddress

use of org.jgroups.stack.IpAddress in project JGroups by belaban.

the class SizeTest method testPingData.

public static void testPingData() throws Exception {
    PingData data;
    final Address a = Util.createRandomAddress("A");
    final PhysicalAddress physical_addr = new IpAddress("127.0.0.1", 7500);
    data = new PingData(null, false);
    _testSize(data);
    data = new PingData(a, true);
    _testSize(data);
    data = new PingData(a, true, "A", physical_addr).coord(true);
    _testSize(data);
    data = new PingData(a, true, "A", physical_addr).coord(true).mbrs(Arrays.asList(Util.createRandomAddress("A"), Util.createRandomAddress("B")));
    _testSize(data);
}
Also used : IpAddress(org.jgroups.stack.IpAddress) IpAddress(org.jgroups.stack.IpAddress)

Aggregations

IpAddress (org.jgroups.stack.IpAddress)87 InetSocketAddress (java.net.InetSocketAddress)15 Address (org.jgroups.Address)13 InetAddress (java.net.InetAddress)7 Test (org.testng.annotations.Test)7 Event (org.jgroups.Event)6 PhysicalAddress (org.jgroups.PhysicalAddress)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4 IOException (java.io.IOException)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 JChannel (org.jgroups.JChannel)3 ManagedOperation (org.jgroups.annotations.ManagedOperation)3 DefaultSocketFactory (org.jgroups.util.DefaultSocketFactory)3 Container (io.fabric8.kubernetes.api.model.Container)2 ContainerPort (io.fabric8.kubernetes.api.model.ContainerPort)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 ServerSocket (java.net.ServerSocket)2