List of usage examples for io.netty.util.concurrent GenericFutureListener GenericFutureListener
GenericFutureListener
From source file:org.opendaylight.controller.netconf.ssh.RemoteNetconfCommand.java
License:Open Source License
@Override public void destroy() { LOG.trace("Releasing internal connection to netconf server for client: {} on channel: {}", getClientAddress(), clientChannel); clientChannelFuture.cancel(true);/*from w ww . j av a2s. co m*/ if (clientChannel != null) { clientChannel.close().addListener(new GenericFutureListener<ChannelFuture>() { @Override public void operationComplete(final ChannelFuture future) throws Exception { if (future.isSuccess() == false) { LOG.warn("Unable to release internal connection to netconf server on channel: {}", clientChannel); } } }); } }
From source file:org.opendaylight.controller.netconf.util.AbstractNetconfSessionNegotiator.java
License:Open Source License
@Override protected void startNegotiation() throws Exception { final Optional<SslHandler> sslHandler = getSslHandler(channel); if (sslHandler.isPresent()) { Future<Channel> future = sslHandler.get().handshakeFuture(); future.addListener(new GenericFutureListener<Future<? super Channel>>() { @Override//from w w w . j a v a 2 s. co m public void operationComplete(Future<? super Channel> future) throws Exception { Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful"); logger.debug("Ssl handshake complete"); start(); } }); } else start(); }
From source file:org.opendaylight.controller.sal.connect.netconf.listener.NetconfDeviceCommunicator.java
License:Open Source License
public void initializeRemoteConnection(final NetconfClientDispatcher dispatcher, final NetconfClientConfiguration config) { // TODO 2313 extract listener from configuration if (config instanceof NetconfReconnectingClientConfiguration) { initFuture = dispatcher.createReconnectingClient((NetconfReconnectingClientConfiguration) config); } else {//from w w w. j a v a 2 s . c o m initFuture = dispatcher.createClient(config); } initFuture.addListener(new GenericFutureListener<Future<Object>>() { @Override public void operationComplete(Future<Object> future) throws Exception { if (!future.isSuccess() && !future.isCancelled()) { logger.debug("{}: Connection failed", id, future.cause()); NetconfDeviceCommunicator.this.remoteDevice.onRemoteSessionFailed(future.cause()); } } }); }
From source file:org.opendaylight.netconf.client.TcpClientChannelInitializer.java
License:Open Source License
@Override public void initialize(final Channel ch, final Promise<NetconfClientSession> promise) { final Future<NetconfClientSession> negotiationFuture = promise; //We have to add this channel outbound handler to channel pipeline, in order //to get notifications from netconf negotiatior. Set connection promise to //success only after successful negotiation. ch.pipeline().addFirst(new ChannelOutboundHandlerAdapter() { ChannelPromise connectPromise;//from w w w . j a v a 2 s .co m GenericFutureListener<Future<NetconfClientSession>> negotiationFutureListener; @Override public void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise channelPromise) throws Exception { connectPromise = channelPromise; ChannelPromise tcpConnectFuture = new DefaultChannelPromise(ch); negotiationFutureListener = new GenericFutureListener<Future<NetconfClientSession>>() { @Override public void operationComplete(final Future<NetconfClientSession> future) throws Exception { if (future.isSuccess()) { connectPromise.setSuccess(); } } }; tcpConnectFuture.addListener(new GenericFutureListener<Future<? super Void>>() { @Override public void operationComplete(final Future<? super Void> future) throws Exception { if (future.isSuccess()) { //complete connection promise with netconf negotiation future negotiationFuture.addListener(negotiationFutureListener); } else { connectPromise.setFailure(future.cause()); } } }); ctx.connect(remoteAddress, localAddress, tcpConnectFuture); } @Override public void disconnect(final ChannelHandlerContext ctx, final ChannelPromise promise) throws Exception { // If we have already succeeded and the session was dropped after, we need to fire inactive to notify reconnect logic if (connectPromise.isSuccess()) { ctx.fireChannelInactive(); } //If connection promise is not already set, it means negotiation failed //we must set connection promise to failure if (!connectPromise.isDone()) { connectPromise.setFailure(new IllegalStateException("Negotiation failed")); } //Remove listener from negotiation future, we don't want notifications //from negotiation anymore negotiationFuture.removeListener(negotiationFutureListener); super.disconnect(ctx, promise); promise.setSuccess(); } }); super.initialize(ch, promise); }
From source file:org.opendaylight.netconf.nettyutil.AbstractNetconfSessionNegotiator.java
License:Open Source License
private void start() { final NetconfHelloMessage helloMessage = this.sessionPreferences.getHelloMessage(); LOG.debug("Session negotiation started with hello message {} on channel {}", helloMessage, channel); channel.pipeline().addLast(NAME_OF_EXCEPTION_HANDLER, new ExceptionHandlingInboundChannelHandler()); sendMessage(helloMessage);/*w ww . j a v a2 s . c om*/ replaceHelloMessageOutboundHandler(); changeState(State.OPEN_WAIT); timeout = this.timer.newTimeout(new TimerTask() { @Override public void run(final Timeout timeout) { synchronized (this) { if (state != State.ESTABLISHED) { LOG.debug("Connection timeout after {}, session is in state {}", timeout, state); // Do not fail negotiation if promise is done or canceled // It would result in setting result of the promise second time and that throws exception if (isPromiseFinished() == false) { LOG.warn("Netconf session was not established after {}", connectionTimeoutMillis); changeState(State.FAILED); channel.close().addListener(new GenericFutureListener<ChannelFuture>() { @Override public void operationComplete(final ChannelFuture future) throws Exception { if (future.isSuccess()) { LOG.debug("Channel {} closed: success", future.channel()); } else { LOG.warn("Channel {} closed: fail", future.channel()); } } }); } } else if (channel.isOpen()) { channel.pipeline().remove(NAME_OF_EXCEPTION_HANDLER); } } } private boolean isPromiseFinished() { return promise.isDone() || promise.isCancelled(); } }, connectionTimeoutMillis, TimeUnit.MILLISECONDS); }
From source file:org.opendaylight.netconf.nettyutil.handler.ssh.client.AsyncSshHandler.java
License:Open Source License
@Override public synchronized void connect(final ChannelHandlerContext ctx, final SocketAddress remoteAddress, final SocketAddress localAddress, final ChannelPromise promise) throws Exception { LOG.debug("SSH session connecting on channel {}. promise: {} ", ctx.channel(), connectPromise); this.connectPromise = promise; if (negotiationFuture != null) { negotiationFutureListener = new GenericFutureListener<Future<?>>() { @Override/*from ww w .j a v a 2 s . c o m*/ public void operationComplete(final Future<?> future) { if (future.isSuccess()) { connectPromise.setSuccess(); } } }; //complete connection promise with netconf negotiation future negotiationFuture.addListener(negotiationFutureListener); } startSsh(ctx, remoteAddress); }
From source file:org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator.java
License:Open Source License
/** * * @param dispatcher//from ww w . j a va 2s. co m * @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.ocpjava.protocol.impl.core.connection.ConnectionAdapterImpl.java
License:Open Source License
/** * @param resultFuture/*from w w w. ja v a 2 s . c o m*/ * @param failureInfo * @param errorSeverity * @param message * @return */ private static SettableFuture<Boolean> handleTransportChannelFuture(final ChannelFuture resultFuture) { final SettableFuture<Boolean> transportResult = SettableFuture.create(); resultFuture.addListener(new GenericFutureListener<io.netty.util.concurrent.Future<? super Void>>() { @Override public void operationComplete(final io.netty.util.concurrent.Future<? super Void> future) throws Exception { transportResult.set(future.isSuccess()); if (!future.isSuccess()) { transportResult.setException(future.cause()); } } }); return transportResult; }
From source file:org.opendaylight.ocpjava.protocol.impl.core.TcpHandler.java
License:Open Source License
/** * Shuts down {@link TcpHandler}}/* w w w. ja v a 2s . c o 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(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.ConnectionAdapterImpl.java
License:Open Source License
/** * @param resultFuture//from w w w . j a v a 2s .c o m * @param failureInfo * @return */ private SettableFuture<RpcResult<Void>> handleRpcChannelFuture(ChannelFuture resultFuture, final String failureInfo, final ErrorSeverity errorSeverity, final String errorMessage) { final SettableFuture<RpcResult<Void>> rpcResult = SettableFuture.create(); LOG.debug("handlerpcchannelfuture"); resultFuture.addListener(new GenericFutureListener<io.netty.util.concurrent.Future<? super Void>>() { @Override public void operationComplete(io.netty.util.concurrent.Future<? super Void> future) throws Exception { LOG.debug("operation complete"); Collection<RpcError> errors = Collections.emptyList(); if (future.cause() != null) { LOG.debug("future.cause != null"); RpcError rpcError = buildRpcError(failureInfo, errorSeverity, errorMessage, future.cause()); errors = Lists.newArrayList(rpcError); } rpcResult.set(Rpcs.getRpcResult(future.isSuccess(), (Void) null, errors)); } }); return rpcResult; }