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.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator.java

License:Open Source License

/**
 *
 * @param dispatcher/*from  w  ww.jav a2  s. c  om*/
 * @param config
 * @return future that returns succes on first succesfull connection and failure when the underlying
 * reconnecting strategy runs out of reconnection attempts
 */
public ListenableFuture<NetconfDeviceCapabilities> initializeRemoteConnection(
        final NetconfClientDispatcher dispatcher, final NetconfClientConfiguration config) {
    if (config instanceof NetconfReconnectingClientConfiguration) {
        initFuture = dispatcher.createReconnectingClient((NetconfReconnectingClientConfiguration) config);
    } else {
        initFuture = dispatcher.createClient(config);
    }

    initFuture.addListener(new GenericFutureListener<Future<Object>>() {

        @Override
        public void operationComplete(Future<Object> future) throws Exception {
            if (!future.isSuccess() && !future.isCancelled()) {
                LOG.debug("{}: Connection failed", id, future.cause());
                NetconfDeviceCommunicator.this.remoteDevice.onRemoteSessionFailed(future.cause());
                if (firstConnectionFuture.isDone()) {
                    firstConnectionFuture.setException(future.cause());
                }
            }
        }
    });
    return firstConnectionFuture;
}

From source file:org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator.java

License:Open Source License

private ListenableFuture<RpcResult<NetconfMessage>> sendRequestWithLock(final NetconfMessage message,
        final QName rpc) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("{}: Sending message {}", id, msgToS(message));
    }/*from  w  ww  .ja  v a 2  s  . co m*/

    if (session == null) {
        LOG.warn("{}: Session is disconnected, failing RPC request {}", id, message);
        return Futures.immediateFuture(createSessionDownRpcResult());
    }

    final Request req = new Request(new UncancellableFuture<RpcResult<NetconfMessage>>(true), message);
    requests.add(req);

    session.sendMessage(req.request).addListener(new FutureListener<Void>() {
        @Override
        public void operationComplete(final Future<Void> future) throws Exception {
            if (!future.isSuccess()) {
                // We expect that a session down will occur at this point
                LOG.debug("{}: Failed to send request {}", id, XmlUtil.toString(req.request.getDocument()),
                        future.cause());

                if (future.cause() != null) {
                    req.future.set(createErrorRpcResult(RpcError.ErrorType.TRANSPORT,
                            future.cause().getLocalizedMessage()));
                } else {
                    req.future.set(createSessionDownRpcResult()); // assume session is down
                }
                req.future.setException(future.cause());
            } else {
                LOG.trace("Finished sending request {}", req.request);
            }
        }
    });

    return req.future;
}

From source file:org.opendaylight.ocpjava.protocol.impl.core.connection.AbstractRpcListener.java

License:Open Source License

@Override
public final void operationComplete(final Future<Void> future) {
    if (!future.isSuccess()) {
        LOG.debug("operation failed");
        failedRpc(future.cause());
    } else {/*from www  .j  a v a  2 s. c  om*/
        LOG.debug("operation complete");
        operationSuccessful();
    }
}

From source file:org.opendaylight.ocpjava.protocol.impl.core.TcpHandler.java

License:Open Source License

/**
 * Shuts down {@link TcpHandler}}/*from   w ww.  j ava2  s  .  c om*/
 */
@Override
public ListenableFuture<Boolean> shutdown() {
    final SettableFuture<Boolean> result = SettableFuture.create();
    workerGroup.shutdownGracefully();
    // boss will shutdown as soon, as worker is down
    bossGroup.shutdownGracefully()
            .addListener(new GenericFutureListener<io.netty.util.concurrent.Future<Object>>() {

                @Override
                public void operationComplete(final io.netty.util.concurrent.Future<Object> downResult)
                        throws Exception {
                    result.set(downResult.isSuccess());
                    if (downResult.cause() != null) {
                        result.setException(downResult.cause());
                    }
                }

            });
    return result;
}

From source file:org.opendaylight.openflowjava.protocol.impl.connection.AbstractRpcListener.java

License:Open Source License

@Override
public final void operationComplete(final Future<? super Void> future) {
    if (!future.isSuccess()) {
        LOG.debug("operation failed");
        failedRpc(future.cause());
    } else {//from  ww w .ja v  a  2  s  . c o m
        LOG.debug("operation complete");
        operationSuccessful();
    }
}

From source file:org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.java

License:Open Source License

/**
 * Shuts down {@link TcpHandler}}/*from   w w w . j a  va2  s  .co m*/
 */
@Override
public ListenableFuture<Boolean> shutdown() {
    final SettableFuture<Boolean> result = SettableFuture.create();
    workerGroup.shutdownGracefully();
    // boss will shutdown as soon, as worker is down
    bossGroup.shutdownGracefully()
            .addListener(new GenericFutureListener<io.netty.util.concurrent.Future<Object>>() {

                @Override
                public void operationComplete(io.netty.util.concurrent.Future<Object> downResult)
                        throws Exception {
                    result.set(downResult.isSuccess());
                    if (downResult.cause() != null) {
                        result.setException(downResult.cause());
                    }
                }

            });
    return result;
}

From source file:org.opendaylight.openflowjava.protocol.impl.core.UdpHandler.java

License:Open Source License

@Override
public ListenableFuture<Boolean> shutdown() {
    final SettableFuture<Boolean> result = SettableFuture.create();
    group.shutdownGracefully()// w  w w  .  ja  v a  2s.c  o  m
            .addListener(new GenericFutureListener<io.netty.util.concurrent.Future<Object>>() {

                @Override
                public void operationComplete(final io.netty.util.concurrent.Future<Object> downResult)
                        throws Exception {
                    result.set(downResult.isSuccess());
                    if (downResult.cause() != null) {
                        result.setException(downResult.cause());
                    }
                }

            });
    return result;
}

From source file:org.opendaylight.protocol.bgp.rib.impl.protocol.BGPReconnectPromise.java

License:Open Source License

public synchronized void connect() {
    // Set up a client with pre-configured bootstrap, but add a closed channel handler into the pipeline to support reconnect attempts
    this.pending = connectSessionPromise(this.address, this.retryTimer, this.bootstrap,
            new ChannelPipelineInitializer<S>() {
                @Override//from w w w  .j  a  v a  2  s  .c  o m
                public void initializeChannel(final SocketChannel channel, final Promise<S> promise) {
                    BGPReconnectPromise.this.initializer.initializeChannel(channel, promise);
                    // add closed channel handler
                    // This handler has to be added as last channel handler and the channel inactive event has to be caught by it
                    // Handlers in front of it can react to channelInactive event, but have to forward the event or the reconnect will not work
                    // This handler is last so all handlers in front of it can handle channel inactive (to e.g. resource cleanup) before a new connection is started
                    channel.pipeline().addLast(new ClosedChannelHandler(BGPReconnectPromise.this));
                }
            });

    this.pending.addListener(new GenericFutureListener<Future<Object>>() {
        @Override
        public void operationComplete(final Future<Object> future) throws Exception {
            if (!future.isSuccess()) {
                BGPReconnectPromise.this.setFailure(future.cause());
            }
        }
    });
}

From source file:org.opendaylight.protocol.framework.ReconnectPromise.java

License:Open Source License

synchronized void connect() {
    final ReconnectStrategy cs = this.strategyFactory.createReconnectStrategy();

    // Set up a client with pre-configured bootstrap, but add a closed channel handler into the pipeline to support reconnect attempts
    pending = this.dispatcher.createClient(this.address, cs, b,
            new AbstractDispatcher.PipelineInitializer<S>() {
                @Override/*w ww  . java2s.c o m*/
                public void initializeChannel(final SocketChannel channel, final Promise<S> promise) {
                    initializer.initializeChannel(channel, promise);
                    // add closed channel handler
                    // This handler has to be added as last channel handler and the channel inactive event has to be caught by it
                    // Handlers in front of it can react to channelInactive event, but have to forward the event or the reconnect will not work
                    // This handler is last so all handlers in front of it can handle channel inactive (to e.g. resource cleanup) before a new connection is started
                    channel.pipeline().addLast(new ClosedChannelHandler(ReconnectPromise.this));
                }
            });

    pending.addListener(new GenericFutureListener<Future<Object>>() {
        @Override
        public void operationComplete(Future<Object> future) throws Exception {
            if (!future.isSuccess()) {
                ReconnectPromise.this.setFailure(future.cause());
            }
        }
    });
}

From source file:org.opendaylight.usc.client.netconf.ReconnectPromise.java

License:Open Source License

synchronized void connect() {
    final ReconnectStrategy cs = this.strategyFactory.createReconnectStrategy();

    // Set up a client with pre-configured bootstrap, but add a closed channel handler into the pipeline to
    // support reconnect attempts
    pending = dispatcher.createClient(this.address, cs, b, new PipelineInitializer<NetconfClientSession>() {
        @Override//from  w w  w  . ja  v a2s . c  o  m
        public void initializeChannel(final Channel channel, final Promise<NetconfClientSession> promise) {
            initializer.initializeChannel(channel, promise);
            // add closed channel handler
            // This handler has to be added as last channel handler and the channel inactive event has
            // to be caught by it
            // Handlers in front of it can react to channelInactive event, but have to forward the event
            // or the reconnect will not work
            // This handler is last so all handlers in front of it can handle channel inactive (to e.g.
            // resource cleanup) before a new connection is started
            channel.pipeline().addLast(new ClosedChannelHandler(ReconnectPromise.this));
        }
    });

    pending.addListener(new GenericFutureListener<Future<Object>>() {
        @Override
        public void operationComplete(Future<Object> future) throws Exception {
            if (!future.isSuccess()) {
                ReconnectPromise.this.setFailure(future.cause());
            }
        }
    });
}