Search in sources :

Example 1 with JdkSocketChannel

use of org.webpieces.nio.api.jdk.JdkSocketChannel in project webpieces by deanhiller.

the class BasTCPServerChannel method accept.

/* (non-Javadoc)
	 * @see api.biz.xsoftware.nio.TCPServerChannel#accept()
	 */
public boolean accept(int newSocketNum) throws IOException {
    XFuture<Void> future;
    try {
        // special code...see information in close() method
        if (isClosed())
            return false;
        JdkSocketChannel newChan = channel.accept();
        if (newChan == null)
            return false;
        newChan.configureBlocking(false);
        SocketAddress remoteAddress = newChan.getRemoteAddress();
        String serverSocketId = id + "." + newSocketNum;
        BasTCPChannel tcpChan = new BasTCPChannel(serverSocketId, newChan, remoteAddress, selMgr, router, pool, config);
        if (log.isTraceEnabled())
            log.trace(tcpChan + "Accepted new incoming connection");
        XFuture<DataListener> connectFuture = connectionListener.connected(tcpChan, true);
        future = connectFuture.thenCompose(l -> tcpChan.registerForReads(l)).thenApply(c -> null);
    } catch (Throwable e) {
        future = new XFuture<Void>();
        future.completeExceptionally(e);
    }
    future.exceptionally(t -> {
        log.error(this + "Failed to connect", t);
        connectionListener.failed(this, t);
        return null;
    });
    return true;
}
Also used : DataListener(org.webpieces.nio.api.handlers.DataListener) BufferPool(org.webpieces.data.api.BufferPool) Logger(org.slf4j.Logger) SocketAddress(java.net.SocketAddress) ClosedChannelException(java.nio.channels.ClosedChannelException) SelectionKey(java.nio.channels.SelectionKey) NioException(org.webpieces.util.exceptions.NioException) SneakyThrow(org.webpieces.util.exceptions.SneakyThrow) LoggerFactory(org.slf4j.LoggerFactory) TCPServerChannel(org.webpieces.nio.api.channels.TCPServerChannel) IOException(java.io.IOException) BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) BindException(java.net.BindException) ConnectionListener(org.webpieces.nio.api.handlers.ConnectionListener) ConsumerFunc(org.webpieces.nio.api.handlers.ConsumerFunc) InetSocketAddress(java.net.InetSocketAddress) ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketException(java.net.SocketException) JdkSelect(org.webpieces.nio.api.jdk.JdkSelect) XFuture(org.webpieces.util.futures.XFuture) NioClosedChannelException(org.webpieces.util.exceptions.NioClosedChannelException) JdkSocketChannel(org.webpieces.nio.api.jdk.JdkSocketChannel) XFuture(org.webpieces.util.futures.XFuture) DataListener(org.webpieces.nio.api.handlers.DataListener) JdkSocketChannel(org.webpieces.nio.api.jdk.JdkSocketChannel) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Aggregations

IOException (java.io.IOException)1 BindException (java.net.BindException)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 SocketException (java.net.SocketException)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 SelectionKey (java.nio.channels.SelectionKey)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 BufferPool (org.webpieces.data.api.BufferPool)1 BackpressureConfig (org.webpieces.nio.api.BackpressureConfig)1 TCPServerChannel (org.webpieces.nio.api.channels.TCPServerChannel)1 ConnectionListener (org.webpieces.nio.api.handlers.ConnectionListener)1 ConsumerFunc (org.webpieces.nio.api.handlers.ConsumerFunc)1 DataListener (org.webpieces.nio.api.handlers.DataListener)1 JdkSelect (org.webpieces.nio.api.jdk.JdkSelect)1 JdkSocketChannel (org.webpieces.nio.api.jdk.JdkSocketChannel)1 NioClosedChannelException (org.webpieces.util.exceptions.NioClosedChannelException)1 NioException (org.webpieces.util.exceptions.NioException)1