Search in sources :

Example 1 with ConnectedStreamChannel

use of org.xnio.channels.ConnectedStreamChannel in project undertow by undertow-io.

the class UndertowXnioSsl method connectSsl.

@SuppressWarnings("deprecation")
public IoFuture<ConnectedSslStreamChannel> connectSsl(final XnioWorker worker, final InetSocketAddress bindAddress, final InetSocketAddress destination, final ChannelListener<? super ConnectedSslStreamChannel> openListener, final ChannelListener<? super BoundChannel> bindListener, final OptionMap optionMap) {
    final FutureResult<ConnectedSslStreamChannel> futureResult = new FutureResult<>(IoUtils.directExecutor());
    final IoFuture<SslConnection> futureSslConnection = openSslConnection(worker, bindAddress, destination, new ChannelListener<SslConnection>() {

        public void handleEvent(final SslConnection sslConnection) {
            final ConnectedSslStreamChannel assembledChannel = new AssembledConnectedSslStreamChannel(sslConnection, sslConnection.getSourceChannel(), sslConnection.getSinkChannel());
            if (!futureResult.setResult(assembledChannel)) {
                safeClose(assembledChannel);
            } else {
                ChannelListeners.invokeChannelListener(assembledChannel, openListener);
            }
        }
    }, bindListener, optionMap).addNotifier(new IoFuture.HandlingNotifier<SslConnection, FutureResult<ConnectedSslStreamChannel>>() {

        public void handleCancelled(final FutureResult<ConnectedSslStreamChannel> result) {
            result.setCancelled();
        }

        public void handleFailed(final IOException exception, final FutureResult<ConnectedSslStreamChannel> result) {
            result.setException(exception);
        }
    }, futureResult);
    futureResult.getIoFuture().addNotifier(new IoFuture.HandlingNotifier<ConnectedStreamChannel, IoFuture<SslConnection>>() {

        public void handleCancelled(final IoFuture<SslConnection> result) {
            result.cancel();
        }
    }, futureSslConnection);
    futureResult.addCancelHandler(futureSslConnection);
    return futureResult.getIoFuture();
}
Also used : SslConnection(org.xnio.ssl.SslConnection) ConnectedStreamChannel(org.xnio.channels.ConnectedStreamChannel) ChannelListener(org.xnio.ChannelListener) FutureResult(org.xnio.FutureResult) IoFuture(org.xnio.IoFuture) AssembledConnectedSslStreamChannel(org.xnio.channels.AssembledConnectedSslStreamChannel) IOException(java.io.IOException) ConnectedSslStreamChannel(org.xnio.channels.ConnectedSslStreamChannel) AssembledConnectedSslStreamChannel(org.xnio.channels.AssembledConnectedSslStreamChannel)

Aggregations

IOException (java.io.IOException)1 ChannelListener (org.xnio.ChannelListener)1 FutureResult (org.xnio.FutureResult)1 IoFuture (org.xnio.IoFuture)1 AssembledConnectedSslStreamChannel (org.xnio.channels.AssembledConnectedSslStreamChannel)1 ConnectedSslStreamChannel (org.xnio.channels.ConnectedSslStreamChannel)1 ConnectedStreamChannel (org.xnio.channels.ConnectedStreamChannel)1 SslConnection (org.xnio.ssl.SslConnection)1