Search in sources :

Example 21 with IpAddress

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

the class IpAddressTest method testStreamableAdditionalData.

public void testStreamableAdditionalData() throws Exception {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream oos = new DataOutputStream(bos);
    byte[] buf = null;
    ByteArrayInputStream bis = null;
    DataInputStream ois;
    IpAddress a2, b2, c2, d2, e2, f2, g2, h2;
    a.writeTo(oos);
    b.writeTo(oos);
    c.writeTo(oos);
    d.writeTo(oos);
    e.writeTo(oos);
    f.writeTo(oos);
    g.writeTo(oos);
    h.writeTo(oos);
    buf = bos.toByteArray();
    bis = new ByteArrayInputStream(buf);
    ois = new DataInputStream(bis);
    a2 = new IpAddress();
    a2.readFrom(ois);
    b2 = new IpAddress();
    b2.readFrom(ois);
    c2 = new IpAddress();
    c2.readFrom(ois);
    d2 = new IpAddress();
    d2.readFrom(ois);
    e2 = new IpAddress();
    e2.readFrom(ois);
    f2 = new IpAddress();
    f2.readFrom(ois);
    g2 = new IpAddress();
    g2.readFrom(ois);
    h2 = new IpAddress();
    h2.readFrom(ois);
    Assert.assertEquals(b2, c2);
    Assert.assertEquals(a, a2);
    Assert.assertEquals(b, b2);
    Assert.assertEquals(c, c2);
    Assert.assertEquals(d, d2);
    Assert.assertEquals(e, e2);
    Assert.assertEquals(f, f2);
    Assert.assertEquals(g, g2);
    Assert.assertEquals(h, h2);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) IpAddress(org.jgroups.stack.IpAddress) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream)

Example 22 with IpAddress

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

the class IpAddressTest method testIPv6WithStreamable.

public static void testIPv6WithStreamable() throws Exception {
    IpAddress ip = new IpAddress("fe80:0:0:0:21b:21ff:fe07:a3b0", 5555);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    byte[] buf = null;
    ByteArrayInputStream bis = null;
    DataInputStream dis;
    System.out.println("-- address is " + ip);
    ip.writeTo(dos);
    buf = bos.toByteArray();
    bis = new ByteArrayInputStream(buf);
    dis = new DataInputStream(bis);
    IpAddress ip2 = new IpAddress();
    ip2.readFrom(dis);
    Assert.assertEquals(ip, ip2);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) IpAddress(org.jgroups.stack.IpAddress) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream)

Example 23 with IpAddress

use of org.jgroups.stack.IpAddress 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) IpAddress(org.jgroups.stack.IpAddress) InetAddress(java.net.InetAddress)

Example 24 with IpAddress

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

the class Util method parseCommaDelimitedHosts.

/**
 * Input is "daddy[8880],sindhu[8880],camille[5555]. Returns a list of IpAddresses
 */
public static List<PhysicalAddress> parseCommaDelimitedHosts(String hosts, int port_range) throws UnknownHostException {
    StringTokenizer tok = hosts != null ? new StringTokenizer(hosts, ",") : null;
    String t;
    IpAddress addr;
    Set<PhysicalAddress> retval = new HashSet<>();
    while (tok != null && tok.hasMoreTokens()) {
        t = tok.nextToken().trim();
        String host = t.substring(0, t.indexOf('['));
        host = host.trim();
        int port = Integer.parseInt(t.substring(t.indexOf('[') + 1, t.indexOf(']')));
        InetAddress[] resolvedAddresses = InetAddress.getAllByName(host);
        for (int i = 0; i < resolvedAddresses.length; i++) {
            for (int p = port; p <= port + port_range; p++) {
                addr = new IpAddress(resolvedAddresses[i], p);
                retval.add(addr);
            }
        }
    }
    return new LinkedList<>(retval);
}
Also used : IpAddress(org.jgroups.stack.IpAddress)

Example 25 with IpAddress

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

the class Util method parseCommaDelimitedHostsInto.

/**
 * Parses a string into a list of IpAddresses
 * @param list The list to which to add parsed elements
 * @param hosts The string with host:port pairs
 * @param unresolved_hosts A list of unresolved hosts
 * @param port_range The port range to consider
 * @return True if all hostnames resolved fine, false otherwise
 */
public static boolean parseCommaDelimitedHostsInto(final Collection<PhysicalAddress> list, final Collection<String> unresolved_hosts, String hosts, int port_range, StackType stack_type) {
    StringTokenizer tok = hosts != null ? new StringTokenizer(hosts, ",") : null;
    boolean all_resolved = true;
    while (tok != null && tok.hasMoreTokens()) {
        String t = tok.nextToken().trim();
        String host = t.substring(0, t.indexOf('['));
        host = host.trim();
        int port = Integer.parseInt(t.substring(t.indexOf('[') + 1, t.indexOf(']')));
        try {
            InetAddress[] resolvedAddresses = InetAddress.getAllByName(host);
            for (int i = 0; i < resolvedAddresses.length; i++) {
                for (int p = port; p <= port + port_range; p++) {
                    InetAddress inet = resolvedAddresses[i];
                    boolean add = (inet == null && stack_type == StackType.Dual) || (inet instanceof Inet6Address && stack_type == StackType.IPv6) || (inet instanceof Inet4Address && stack_type == StackType.IPv4);
                    if (add) {
                        IpAddress addr = new IpAddress(inet, p);
                        list.add(addr);
                    }
                }
            }
        } catch (UnknownHostException ex) {
            all_resolved = false;
            unresolved_hosts.add(host);
        }
    }
    return all_resolved;
}
Also used : 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