Search in sources :

Example 46 with IpAddress

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

the class VERIFY_SUSPECT method verifySuspectWithICMP.

void verifySuspectWithICMP(Address suspected_mbr) {
    InetAddress host = suspected_mbr instanceof IpAddress ? ((IpAddress) suspected_mbr).getIpAddress() : null;
    if (host == null)
        throw new IllegalArgumentException("suspected_mbr is not of type IpAddress - FD_ICMP only works with these");
    try {
        if (log.isTraceEnabled())
            log.trace("pinging host " + suspected_mbr + " using interface " + intf);
        long start = System.currentTimeMillis(), stop;
        boolean rc = host.isReachable(intf, 0, (int) timeout);
        stop = System.currentTimeMillis();
        if (// success
        rc)
            log.trace("successfully received response from " + host + " (after " + (stop - start) + "ms)");
        else {
            // failure
            log.debug("failed pinging " + suspected_mbr + " after " + (stop - start) + "ms; passing up SUSPECT event");
            removeSuspect(suspected_mbr);
            up_prot.up(new Event(Event.SUSPECT, Collections.singletonList(suspected_mbr)));
        }
    } catch (Exception ex) {
        log.error(Util.getMessage("FailedPinging"), suspected_mbr, ex);
    }
}
Also used : IpAddress(org.jgroups.stack.IpAddress) InetAddress(java.net.InetAddress)

Example 47 with IpAddress

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

the class Discovery method read.

/* -------------------------- Private methods ---------------------------- */
protected List<PingData> read(InputStream in) {
    List<PingData> retval = null;
    try {
        while (true) {
            try {
                String name_str = Util.readToken(in);
                String uuid_str = Util.readToken(in);
                String addr_str = Util.readToken(in);
                String coord_str = Util.readToken(in);
                if (name_str == null || uuid_str == null || addr_str == null || coord_str == null)
                    break;
                UUID uuid = null;
                try {
                    long tmp = Long.valueOf(uuid_str);
                    uuid = new UUID(0, tmp);
                } catch (Throwable t) {
                    uuid = UUID.fromString(uuid_str);
                }
                PhysicalAddress phys_addr = new IpAddress(addr_str);
                boolean is_coordinator = coord_str.trim().equals("T") || coord_str.trim().equals("t");
                if (retval == null)
                    retval = new ArrayList<>();
                retval.add(new PingData(uuid, true, name_str, phys_addr).coord(is_coordinator));
            } catch (Throwable t) {
                log.error(Util.getMessage("FailedReadingLineOfInputStream"), t);
            }
        }
        return retval;
    } finally {
        Util.close(in);
    }
}
Also used : IpAddress(org.jgroups.stack.IpAddress) UUID(org.jgroups.util.UUID)

Example 48 with IpAddress

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

the class FD_SOCK method startServerSocket.

protected void startServerSocket() throws Exception {
    srv_sock = Util.createServerSocket(getSocketFactory(), "jgroups.fd_sock.srv_sock", bind_addr, start_port, // grab a random unused port above 10000
    start_port + port_range);
    srv_sock_addr = new IpAddress(external_addr != null ? external_addr : bind_addr, external_port > 0 ? external_port : srv_sock.getLocalPort());
    if (local_addr != null)
        cache.add(local_addr, srv_sock_addr);
    if (srv_sock_handler != null)
        // won't start if already running
        srv_sock_handler.start();
}
Also used : IpAddress(org.jgroups.stack.IpAddress)

Example 49 with IpAddress

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

the class UnicastTestTcp method init.

public void init(String local_addr, String remote_addr, int local_port, int remote_port) throws Exception {
    local = new InetSocketAddress(local_addr, local_port);
    remote = new InetSocketAddress(remote_addr, remote_port);
    destination = new IpAddress(remote.getAddress(), remote.getPort());
    srv_sock = Util.createServerSocket(new DefaultSocketFactory(), "server", local.getAddress(), local.getPort());
    System.out.println("Listening on " + srv_sock.getLocalSocketAddress());
    acceptor = new Acceptor();
    acceptor.start();
    sock = new Socket();
    // sock.bind(local);
    sock.setSendBufferSize(SOCK_SEND_BUF_SIZE);
    sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE);
    try {
        sock.connect(remote);
        output = new DataOutputStream(new BufferedOutputStream(sock.getOutputStream()));
        System.out.println("Connected to " + sock.getRemoteSocketAddress());
    } catch (Throwable t) {
        System.out.println("Failed connecting to " + remote + ": will only act as server");
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DefaultSocketFactory(org.jgroups.util.DefaultSocketFactory) IpAddress(org.jgroups.stack.IpAddress) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket)

Example 50 with IpAddress

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

the class ProtocolConfigurationTest method testAssignmentInetAddresses.

/*
	 * Checks InetAddress and IpAddress processing 
	 */
public void testAssignmentInetAddresses() throws Exception {
    // create the layer described by INETADDRESSES
    protocol = Configurator.createProtocol(addressProps, stack);
    // get the value which should have been assigned a default
    InetAddress a = ((INETADDRESSES) protocol).getInetAddressField();
    System.out.println("value of inetAddressField = " + a);
    // get the value which should not have been assigned a default
    InetAddress b = ((INETADDRESSES) protocol).getInetAddressMethod();
    System.out.println("value of inetAddressMethod = " + b);
    // get the value which should have been assigned a default
    List<IpAddress> c = ((INETADDRESSES) protocol).getIpAddressListField();
    System.out.println("value of ipAddressListField = " + c);
    // get the value which should not have been assigned a default
    List<IpAddress> d = ((INETADDRESSES) protocol).getIpAddressListMethod();
    System.out.println("value of ipAddressListMethod = " + d);
}
Also used : IpAddress(org.jgroups.stack.IpAddress) InetAddress(java.net.InetAddress)

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