Search in sources :

Example 66 with IpAddress

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

the class BuffersTest method testRead3.

public void testRead3() throws Exception {
    byte[] cookie = { 'b', 'e', 'l', 'a' };
    IpAddress addr = new IpAddress(7500);
    ByteArrayDataOutputStream out = new ByteArrayDataOutputStream();
    addr.writeTo(out);
    MockSocketChannel ch = new MockSocketChannel().bytesToRead((ByteBuffer) ByteBuffer.allocate(cookie.length + Global.SHORT_SIZE + out.position()).put(cookie).putShort(Version.version).put(out.buffer(), 0, out.position()).flip());
    int remaining = ch.bytesToRead().remaining();
    ch.bytesToRead().limit(remaining - 10);
    Buffers bufs = new Buffers(ByteBuffer.allocate(cookie.length), ByteBuffer.allocate(Global.SHORT_SIZE), ByteBuffer.allocate(out.position()));
    boolean rc = bufs.read(ch);
    assert !rc;
    ch.bytesToRead().limit(remaining - 2);
    rc = bufs.read(ch);
    assert !rc;
    ch.bytesToRead().limit(remaining);
    rc = bufs.read(ch);
    assert rc;
    readCookieVersionAndAddress(bufs, cookie, addr);
}
Also used : MockSocketChannel(org.jgroups.nio.MockSocketChannel) IpAddress(org.jgroups.stack.IpAddress) Buffers(org.jgroups.nio.Buffers) ByteArrayDataOutputStream(org.jgroups.util.ByteArrayDataOutputStream)

Example 67 with IpAddress

use of org.jgroups.stack.IpAddress in project fabric8 by fabric8io.

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 68 with IpAddress

use of org.jgroups.stack.IpAddress in project wildfly by wildfly.

the class AddressSerializerTestCase method test.

private static void test(Tester<Address> tester) throws IOException {
    UUID uuid = UUID.randomUUID();
    InetSocketAddress address = new InetSocketAddress(InetAddress.getLoopbackAddress(), Short.MAX_VALUE);
    IpAddress ipAddress = new IpAddress(address);
    IpAddressUUID ipAddressUUID = new IpAddressUUID(address);
    tester.test(uuid);
    tester.test(ipAddress);
    tester.test(ipAddressUUID);
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IpAddress(org.jgroups.stack.IpAddress) UUID(org.jgroups.util.UUID) IpAddressUUID(org.jgroups.stack.IpAddressUUID) IpAddressUUID(org.jgroups.stack.IpAddressUUID)

Aggregations

IpAddress (org.jgroups.stack.IpAddress)68 InetSocketAddress (java.net.InetSocketAddress)12 Address (org.jgroups.Address)9 IpAddressUUID (org.jgroups.stack.IpAddressUUID)8 Event (org.jgroups.Event)6 ByteArrayDataOutputStream (org.jgroups.util.ByteArrayDataOutputStream)6 ByteArrayDataInputStream (org.jgroups.util.ByteArrayDataInputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 DataInputStream (java.io.DataInputStream)4 DataOutputStream (java.io.DataOutputStream)4 InetAddress (java.net.InetAddress)4 PhysicalAddress (org.jgroups.PhysicalAddress)4 Test (org.testng.annotations.Test)4 UUID (org.jgroups.util.UUID)3 ServerSocket (java.net.ServerSocket)2 Socket (java.net.Socket)2 ByteBuffer (java.nio.ByteBuffer)2 ManagedOperation (org.jgroups.annotations.ManagedOperation)2 FixedMembershipToken (org.jgroups.auth.FixedMembershipToken)2