Search in sources :

Example 21 with UnresolvedAddressException

use of java.nio.channels.UnresolvedAddressException in project SilverKing by Morgan-Stanley.

the class AsyncBase method newOutgoingConnection.

// //////////////////////////////////////////////////////////////////////////////////
public T newOutgoingConnection(InetSocketAddress dest, ConnectionListener listener) throws IOException {
    SocketChannel channel;
    channel = SocketChannel.open();
    if (dest.isUnresolved()) {
        Log.warning("Unresolved InetSocketAddress: " + dest);
        throw new ConnectException("Unresolved InetSocketAddress" + dest.toString());
    }
    LWTThreadUtil.setBlocked();
    try {
        channel.socket().connect(dest, defSocketConnectTimeout);
    // channel.connect(dest);
    } catch (UnresolvedAddressException uae) {
        Log.logErrorWarning(uae);
        Log.warning(dest);
        throw new ConnectException(dest.toString());
    } finally {
        LWTThreadUtil.setNonBlocked();
    }
    return addConnection(channel, listener);
}
Also used : ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketChannel(java.nio.channels.SocketChannel) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) ConnectException(java.net.ConnectException)

Example 22 with UnresolvedAddressException

use of java.nio.channels.UnresolvedAddressException in project zookeeper by apache.

the class ClientCnxnSocketNIO method connect.

@Override
void connect(InetSocketAddress addr) throws IOException {
    SocketChannel sock = createSock();
    try {
        registerAndConnect(sock, addr);
    } catch (UnresolvedAddressException | UnsupportedAddressTypeException | SecurityException | IOException e) {
        LOG.error("Unable to open socket to {}", addr);
        sock.close();
        throw e;
    }
    initialized = false;
    /*
         * Reset incomingBuffer
         */
    lenBuffer.clear();
    incomingBuffer = lenBuffer;
}
Also used : SocketChannel(java.nio.channels.SocketChannel) UnsupportedAddressTypeException(java.nio.channels.UnsupportedAddressTypeException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) IOException(java.io.IOException)

Example 23 with UnresolvedAddressException

use of java.nio.channels.UnresolvedAddressException in project zookeeper by apache.

the class QuorumCnxManager method initiateConnection.

/**
 * First we create the socket, perform SSL handshake and authentication if needed.
 * Then we perform the initiation protocol.
 * If this server has initiated the connection, then it gives up on the
 * connection if it loses challenge. Otherwise, it keeps the connection.
 */
public void initiateConnection(final MultipleAddresses electionAddr, final Long sid) {
    Socket sock = null;
    try {
        LOG.debug("Opening channel to server {}", sid);
        if (self.isSslQuorum()) {
            sock = self.getX509Util().createSSLSocket();
        } else {
            sock = SOCKET_FACTORY.get();
        }
        setSockOpts(sock);
        sock.connect(electionAddr.getReachableOrOne(), cnxTO);
        if (sock instanceof SSLSocket) {
            SSLSocket sslSock = (SSLSocket) sock;
            sslSock.startHandshake();
            LOG.info("SSL handshake complete with {} - {} - {}", sslSock.getRemoteSocketAddress(), sslSock.getSession().getProtocol(), sslSock.getSession().getCipherSuite());
        }
        LOG.debug("Connected to server {} using election address: {}:{}", sid, sock.getInetAddress(), sock.getPort());
    } catch (X509Exception e) {
        LOG.warn("Cannot open secure channel to {} at election address {}", sid, electionAddr, e);
        closeSocket(sock);
        return;
    } catch (UnresolvedAddressException | IOException e) {
        LOG.warn("Cannot open channel to {} at election address {}", sid, electionAddr, e);
        closeSocket(sock);
        return;
    }
    try {
        startConnection(sock, sid);
    } catch (IOException e) {
        LOG.error("Exception while connecting, id: {}, addr: {}, closing learner connection", sid, sock.getRemoteSocketAddress(), e);
        closeSocket(sock);
    }
}
Also used : X509Exception(org.apache.zookeeper.common.X509Exception) SSLSocket(javax.net.ssl.SSLSocket) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) IOException(java.io.IOException) SSLSocket(javax.net.ssl.SSLSocket) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket)

Example 24 with UnresolvedAddressException

use of java.nio.channels.UnresolvedAddressException in project j2objc by google.

the class AsynchronousSocketChannelTest method test_bind_unresolvedAddress.

public void test_bind_unresolvedAddress() throws Exception {
    AsynchronousSocketChannel asc = AsynchronousSocketChannel.open();
    try {
        asc.bind(new InetSocketAddress("unresolvedname", 31415));
        fail();
    } catch (UnresolvedAddressException expected) {
    }
    assertNull(asc.getLocalAddress());
    assertNull(asc.getRemoteAddress());
    assertTrue(asc.isOpen());
    asc.close();
}
Also used : AsynchronousSocketChannel(java.nio.channels.AsynchronousSocketChannel) InetSocketAddress(java.net.InetSocketAddress) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException)

Example 25 with UnresolvedAddressException

use of java.nio.channels.UnresolvedAddressException in project j2objc by google.

the class DatagramChannelTest method testConnect_Unresolved.

/**
 * Test method for 'DatagramChannelImpl.connect(SocketAddress)'
 */
public void testConnect_Unresolved() throws IOException {
    assertFalse(this.channel1.isConnected());
    InetSocketAddress unresolved = new InetSocketAddress("unresolved address", 1080);
    try {
        this.channel1.connect(unresolved);
        // $NON-NLS-1$
        fail("Should throw an UnresolvedAddressException here.");
    } catch (UnresolvedAddressException e) {
    // OK.
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException)

Aggregations

UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)30 IOException (java.io.IOException)15 InetSocketAddress (java.net.InetSocketAddress)15 SocketChannel (java.nio.channels.SocketChannel)8 ConnectException (java.net.ConnectException)5 SocketAddress (java.net.SocketAddress)4 UnsupportedAddressTypeException (java.nio.channels.UnsupportedAddressTypeException)4 Socket (java.net.Socket)3 SocketTimeoutException (java.net.SocketTimeoutException)3 ClosedChannelException (java.nio.channels.ClosedChannelException)3 SelectionKey (java.nio.channels.SelectionKey)3 ServerSocketChannel (java.nio.channels.ServerSocketChannel)3 FetchRequest (kafka.api.FetchRequest)3 FetchRequestBuilder (kafka.api.FetchRequestBuilder)3 FetchResponse (kafka.javaapi.FetchResponse)3 ByteBufferMessageSet (kafka.javaapi.message.ByteBufferMessageSet)3 Status (io.grpc.Status)2 Http2Exception (io.netty.handler.codec.http2.Http2Exception)2 ServerSocket (java.net.ServerSocket)2 AsynchronousSocketChannel (java.nio.channels.AsynchronousSocketChannel)2