Example usage for io.netty.util.concurrent Future cause

List of usage examples for io.netty.util.concurrent Future cause

Introduction

In this page you can find the example usage for io.netty.util.concurrent Future cause.

Prototype

Throwable cause();

Source Link

Document

Returns the cause of the failed I/O operation if the I/O operation has failed.

Usage

From source file:org.waarp.ftp.core.data.handler.ftps.FtpsTemporaryFirstHandler.java

License:Open Source License

@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
    // Get the SslHandler in the current pipeline.
    Channel channel = ctx.channel();

    if (session == null) {
        setSession(channel);//w  w w  . j  a  v a 2s. co m
    }
    if (session == null) {
        logger.error("Cannot find session for SSL");
        return;
    }
    // Server: no renegotiation still, but possible clientAuthent
    // Mode is always as SSL Server mode.
    SslHandler sslHandler = FtpsInitializer.waarpSslContextFactory.initInitializer(true,
            FtpsInitializer.waarpSslContextFactory.needClientAuthentication(),
            FtpChannelUtils.getRemoteInetSocketAddress(session.getControlChannel()).getAddress()
                    .getHostAddress(),
            FtpChannelUtils.getRemoteInetSocketAddress(session.getControlChannel()).getPort());
    WaarpSslUtility.addSslOpenedChannel(channel);
    // Get the SslHandler and begin handshake ASAP.
    logger.debug("SSL found but need handshake: " + ctx.channel().toString());
    final FtpsTemporaryFirstHandler myself = this;
    WaarpSslUtility.addSslHandler(null, ctx.pipeline(), sslHandler,
            new GenericFutureListener<Future<? super Channel>>() {
                public void operationComplete(Future<? super Channel> future) throws Exception {
                    logger.debug("Handshake: " + future.isSuccess() + ":" + ((Channel) future.get()).toString(),
                            future.cause());
                    if (future.isSuccess()) {
                        logger.debug("End of initialization of SSL and data channel");
                        myself.superChannelActive(ctx);
                        ctx.pipeline().remove(myself);
                    } else {
                        ctx.close();
                    }
                }
            });
}

From source file:pers.zlf.sslocal.handler.shadowsocks.ShadowsocksServerConnectHandler.java

License:Apache License

@Override
public void channelRead0(final ChannelHandlerContext ctx, final SocksCmdRequest request) throws Exception {
    final Option option = ShadowsocksClient.getShadowsocksOption(ctx.channel());
    Promise<Channel> promise = ctx.executor().newPromise();
    promise.addListener(new GenericFutureListener<Future<Channel>>() {
        @Override/*from   w  w  w.j  a va2  s.com*/
        public void operationComplete(final Future<Channel> future) throws Exception {
            final Channel outboundChannel = future.getNow();
            if (future.isSuccess()) {
                ctx.channel().writeAndFlush(new SocksCmdResponse(SocksCmdStatus.SUCCESS, request.addressType()))
                        .addListener(new ChannelFutureListener() {
                            @Override
                            public void operationComplete(ChannelFuture channelFuture) {
                                ctx.pipeline().remove(ShadowsocksServerConnectHandler.this);
                                outboundChannel.pipeline().addLast(
                                        new ShadowsocksMessageCodec(CryptoFactory
                                                .createCrypto(option.getMethod(), option.getPassword())),
                                        new RelayHandler(ctx.channel()));
                                ctx.pipeline().addLast(new RelayHandler(outboundChannel));

                                outboundChannel.writeAndFlush(request);
                            }
                        });
            } else {
                ctx.channel()
                        .writeAndFlush(new SocksCmdResponse(SocksCmdStatus.FAILURE, request.addressType()));
                ChannelUtils.closeOnFlush(ctx.channel());
            }
        }
    });

    final Channel inboundChannel = ctx.channel();
    b.group(inboundChannel.eventLoop()).channel(NioSocketChannel.class)
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000).option(ChannelOption.SO_KEEPALIVE, true)
            .handler(new DirectClientHandler(promise));

    b.connect(option.getRemoteHost(), option.getRemotePort()).addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (future.isSuccess()) {
                // Connection established use handler provided results
            } else {
                // Close the connection if the connection attempt has failed.
                if (logger.isErrorEnabled()) {
                    logger.error("Failed to connect shadowsocks server", future.cause());
                }

                ctx.channel()
                        .writeAndFlush(new SocksCmdResponse(SocksCmdStatus.FAILURE, request.addressType()));
                ChannelUtils.closeOnFlush(ctx.channel());
            }
        }
    });
}

From source file:reactor.io.net.impl.netty.tcp.NettyTcpClient.java

License:Apache License

@Override
protected Promise<Void> doShutdown() {

    if (nettyOptions != null && nettyOptions.eventLoopGroup() != null) {
        return Promises.success();
    }//from w w  w.  jav a  2s.c o m

    final Promise<Void> promise = Promises.prepare();

    ioGroup.shutdownGracefully().addListener(new FutureListener<Object>() {
        @Override
        public void operationComplete(Future<Object> future) throws Exception {
            if (future.isDone() && future.isSuccess()) {
                promise.onComplete();
            } else {
                promise.onError(future.cause());
            }
        }
    });
    return promise;
}

From source file:reactor.io.net.netty.udp.NettyDatagramServer.java

License:Apache License

@Override
public Promise<Boolean> shutdown() {
    final Promise<Boolean> d = Promises.ready(getEnvironment(), getReactor().getDispatcher());

    getReactor().schedule(new Consumer<Void>() {
        @SuppressWarnings("unchecked")
        @Override/*from w w w.j av a 2 s .  c o m*/
        public void accept(Void v) {
            GenericFutureListener listener = new GenericFutureListener() {
                @Override
                public void operationComplete(Future future) throws Exception {
                    if (future.isSuccess()) {
                        d.onNext(true);
                    } else {
                        d.onError(future.cause());
                    }
                }
            };
            if (null == nettyOptions || null == nettyOptions.eventLoopGroup()) {
                ioGroup.shutdownGracefully().addListener(listener);
            }
        }
    }, null);
    notifyShutdown();

    return d;
}

From source file:reactor.ipc.netty.channel.PooledClientContextHandler.java

License:Open Source License

@Override
public void operationComplete(Future<CHANNEL> future) throws Exception {
    sink.setCancellation(this);
    if (future.isCancelled() || cancelled) {
        if (log.isDebugEnabled()) {
            log.debug("Cancelled {}", future.toString());
        }//from   w  w w  .j  a  va  2  s. c  o m
        return;
    }
    if (!future.isSuccess()) {
        if (future.cause() != null) {
            sink.error(future.cause());
        } else {
            sink.error(new IOException("error while connecting to " + future.toString()));
        }
        return;
    }
    CHANNEL c = future.get();

    if (c.eventLoop().inEventLoop()) {
        connectOrAcquire(c);
    } else {
        c.eventLoop().execute(() -> connectOrAcquire(c));
    }
}