Search in sources :

Example 56 with IpAddress

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

the class IpAddressTest method testConstructor.

public void testConstructor() throws Exception {
    IpAddress tmp = new IpAddress("192.168.1.5:7800");
    assert tmp.getPort() == 7800;
    assert tmp.getIpAddress().equals(InetAddress.getByName("192.168.1.5"));
    tmp = new IpAddress("10.1.2.3");
    assert tmp.getPort() == 0;
    assert tmp.getIpAddress().equals(InetAddress.getByName("10.1.2.3"));
    tmp = new IpAddress("fe80::21b:21ff:fe07:a3b0:6000");
    assert tmp.getPort() == 6000;
    assert tmp.getIpAddress().equals(InetAddress.getByName("fe80::21b:21ff:fe07:a3b0"));
    tmp = new IpAddressUUID(7500);
    assert tmp.getPort() == 7500;
}
Also used : IpAddress(org.jgroups.stack.IpAddress) IpAddressUUID(org.jgroups.stack.IpAddressUUID)

Example 57 with IpAddress

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

the class IpAddressTest method testCopy.

public void testCopy() {
    IpAddress tmp = a.copy();
    assert tmp.equals(a);
    tmp = j.copy();
    assert tmp.equals(j);
}
Also used : IpAddress(org.jgroups.stack.IpAddress)

Example 58 with IpAddress

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

the class STATE_SOCK method createStreamToProvider.

protected Tuple<InputStream, Object> createStreamToProvider(Address provider, StateHeader hdr) throws Exception {
    IpAddress address = hdr.bind_addr;
    Socket socket = null;
    try {
        socket = getSocketFactory().createSocket("jgroups.state_sock.sock");
        socket.bind(new InetSocketAddress(bind_addr, 0));
        socket.setReceiveBufferSize(buffer_size);
        Util.connect(socket, new InetSocketAddress(address.getIpAddress(), address.getPort()), 0);
        log.debug("%s: connected to state provider %s:%d", local_addr, address.getIpAddress(), address.getPort());
        DataOutputStream out = new DataOutputStream(socket.getOutputStream());
        Util.writeAddress(local_addr, out);
        return new Tuple<>(new BufferedInputStream(socket.getInputStream(), buffer_size), socket);
    } catch (Throwable t) {
        Util.close(socket);
        if (t instanceof Exception)
            throw (Exception) t;
        throw new Exception("failed creating socket", t);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) IpAddress(org.jgroups.stack.IpAddress) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Tuple(org.jgroups.util.Tuple) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 59 with IpAddress

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

the class Util method readAddress.

public static Address readAddress(DataInput in) throws Exception {
    byte flags = in.readByte();
    if (Util.isFlagSet(flags, Address.NULL))
        return null;
    Address addr;
    if (Util.isFlagSet(flags, Address.UUID_ADDR)) {
        addr = new UUID();
        addr.readFrom(in);
    } else if (Util.isFlagSet(flags, Address.SITE_UUID)) {
        addr = new SiteUUID();
        addr.readFrom(in);
    } else if (Util.isFlagSet(flags, Address.SITE_MASTER)) {
        addr = new SiteMaster();
        addr.readFrom(in);
    } else if (Util.isFlagSet(flags, Address.IP_ADDR)) {
        addr = new IpAddress();
        addr.readFrom(in);
    } else if (Util.isFlagSet(flags, Address.IP_ADDR_UUID)) {
        addr = new IpAddressUUID();
        addr.readFrom(in);
    } else {
        addr = readOtherAddress(in);
    }
    return addr;
}
Also used : IpAddress(org.jgroups.stack.IpAddress) SiteMaster(org.jgroups.protocols.relay.SiteMaster) IpAddress(org.jgroups.stack.IpAddress) SiteUUID(org.jgroups.protocols.relay.SiteUUID) SiteUUID(org.jgroups.protocols.relay.SiteUUID) IpAddressUUID(org.jgroups.stack.IpAddressUUID) IpAddressUUID(org.jgroups.stack.IpAddressUUID)

Example 60 with IpAddress

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

the class SizeTest method testIpAddress2.

public static void testIpAddress2() throws Exception {
    IpAddress addr = new IpAddress(3456);
    _testSize(addr);
}
Also used : IpAddress(org.jgroups.stack.IpAddress)

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