List of usage examples for io.netty.util.concurrent Future isSuccess
boolean isSuccess();
From source file:org.opendaylight.controller.netconf.nettyutil.AbstractNetconfSessionNegotiator.java
License:Open Source License
@Override protected final void startNegotiation() { final Optional<SslHandler> sslHandler = getSslHandler(channel); if (sslHandler.isPresent()) { Future<Channel> future = sslHandler.get().handshakeFuture(); future.addListener(new GenericFutureListener<Future<? super Channel>>() { @Override/* www . j a v a 2 s .c o m*/ public void operationComplete(final Future<? super Channel> future) { Preconditions.checkState(future.isSuccess(), "Ssl handshake was not successful"); LOG.debug("Ssl handshake complete"); start(); } }); } else { start(); } }
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 ww w .j a va 2 s . c o 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.controller.sal.connect.netconf.listener.NetconfDeviceCommunicator.java
License:Open Source License
private ListenableFuture<RpcResult<NetconfMessage>> sendRequestWithLock(final NetconfMessage message, final QName rpc) { if (logger.isTraceEnabled()) { logger.trace("{}: Sending message {}", id, msgToS(message)); }/*from w ww . j av a 2 s .c o m*/ if (session == null) { logger.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 logger.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 { logger.trace("Finished sending request {}", req.request); } } }); return req.future; }
From source file:org.opendaylight.controller.sal.connect.netconf.NetconfDeviceListener.java
License:Open Source License
synchronized ListenableFuture<RpcResult<CompositeNode>> sendRequest(final NetconfMessage message) { if (session == null) { LOG.debug("Session to {} is disconnected, failing RPC request {}", device.getName(), message); return Futures.<RpcResult<CompositeNode>>immediateFuture(new RpcResult<CompositeNode>() { @Override/* ww w .j av a 2s. c om*/ public boolean isSuccessful() { return false; } @Override public CompositeNode getResult() { return null; } @Override public Collection<RpcError> getErrors() { // FIXME: indicate that the session is down return Collections.emptySet(); } }); } final Request req = new Request(new UncancellableFuture<RpcResult<CompositeNode>>(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 {}", req.request, future.cause()); req.future.setException(future.cause()); } else { LOG.trace("Finished sending request {}", req.request); } } }); return req.future; }
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 ww w . ja v a2 s . com 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.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 w ww . j av a2 s.c om 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 w w w . j av a 2 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)); }// w ww .jav a 2 s . c o 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());//from ww w. jav a2s. c o m } else { LOG.debug("operation complete"); operationSuccessful(); } }