List of usage examples for io.netty.util.concurrent Future isSuccess
boolean isSuccess();
From source file:org.opendaylight.ocpjava.protocol.impl.core.TcpHandler.java
License:Open Source License
/** * Shuts down {@link TcpHandler}}//from ww w . jav a2s .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.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());//from w ww. j a va 2s .c om } else { LOG.debug("operation complete"); operationSuccessful(); } }
From source file:org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.java
License:Open Source License
/** * Shuts down {@link TcpHandler}}/*w ww . ja v a 2s .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()/*from w w w. j a va2 s . c om*/ .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/*ww w. j a v a 2 s . c om*/ 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/*from ww w. j av a2 s . 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.protocol.framework.ServerTest.java
License:Open Source License
@Test public void testConnectionFailed() throws IOException, InterruptedException, ExecutionException, TimeoutException { final Promise<Boolean> p = new DefaultPromise<>(GlobalEventExecutor.INSTANCE); this.dispatcher = getServerDispatcher(p); this.server = this.dispatcher.createServer(this.serverAddress, new SessionListenerFactory<SimpleSessionListener>() { @Override/*from ww w .j av a 2s . com*/ public SimpleSessionListener getSessionListener() { return new SimpleSessionListener(); } }); this.server.get(); this.clientDispatcher = getClientDispatcher(); this.session = this.clientDispatcher .createClient(this.serverAddress, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000), new SessionListenerFactory<SimpleSessionListener>() { @Override public SimpleSessionListener getSessionListener() { return new SimpleSessionListener(); } }) .get(6, TimeUnit.SECONDS); final Future<?> session = this.clientDispatcher.createClient(this.serverAddress, new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000), new SessionListenerFactory<SimpleSessionListener>() { @Override public SimpleSessionListener getSessionListener() { return new SimpleSessionListener(); } }); assertFalse(session.isSuccess()); }
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/* w ww . ja v a 2s. 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()); } } }); }
From source file:org.ow2.petals.bc.gateway.commons.handlers.AuthenticatorSSLHandler.java
License:Open Source License
private void setUpSslHandlers(final ChannelHandlerContext ctx, final AbstractDomain domain, final @Nullable String certificate, final @Nullable String key, final @Nullable String passphrase, final @Nullable String remoteCertificate) throws SSLException { // TODO could we use certificate only for auth and not encryption? // TODO support openssl final SslHandler sslHandler; if (pdOrAuth.isB() && certificate != null && key != null) { // server side ssl, do not forget startTls so that our accept can be sent after the handler is added final ServiceUnitDataHandler handler = domain.getSUHandler(); final SslContextBuilder builder = SslContextBuilder .forServer(ServiceUnitUtil.getFile(handler.getInstallRoot(), certificate), ServiceUnitUtil.getFile(handler.getInstallRoot(), key), passphrase) .sslProvider(SslProvider.JDK).ciphers(null, IdentityCipherSuiteFilter.INSTANCE) .sessionCacheSize(0).sessionTimeout(0); if (remoteCertificate != null) { builder.trustManager(ServiceUnitUtil.getFile(handler.getInstallRoot(), remoteCertificate)) .clientAuth(ClientAuth.REQUIRE); }//from w ww . j a v a 2s. c o m // until https://github.com/netty/netty/issues/5170 is accepted // we need to create the handler by hand sslHandler = new SslHandler(builder.build().newEngine(ctx.alloc()), true); } else if (pdOrAuth.isA() && remoteCertificate != null) { // client side final String installRoot = domain.getSUHandler().getInstallRoot(); final SslContextBuilder builder = SslContextBuilder.forClient().sslProvider(SslProvider.JDK) .trustManager(ServiceUnitUtil.getFile(installRoot, remoteCertificate)) .ciphers(null, IdentityCipherSuiteFilter.INSTANCE).sessionCacheSize(0).sessionTimeout(0); if (certificate != null && key != null) { builder.keyManager(ServiceUnitUtil.getFile(installRoot, certificate), ServiceUnitUtil.getFile(installRoot, key), passphrase); } sslHandler = builder.build().newHandler(ctx.alloc()); } else { sslHandler = null; } // For a server, it contains the transporter name and the consumer domain name (it was updated in channelRead0) // For a client, it contains the provider domain name (it was set by the component) final String logName = logger.getName(); // let's replace the debug logger with something specific to this consumer ctx.pipeline().replace(HandlerConstants.LOG_DEBUG_HANDLER, HandlerConstants.LOG_DEBUG_HANDLER, new LoggingHandler(logName, LogLevel.TRACE)); ctx.pipeline().replace(HandlerConstants.LOG_ERRORS_HANDLER, HandlerConstants.LOG_ERRORS_HANDLER, new LastLoggingHandler(logName + ".errors")); if (sslHandler != null) { // if there is a sslHandler, then we can only add the domain handler after the handshake is finished // if not we risk sending things too early in it sslHandler.handshakeFuture().addListener(new FutureListener<Channel>() { @Override public void operationComplete(final @Nullable Future<Channel> future) throws Exception { assert future != null; if (!future.isSuccess()) { authenticationFuture.setFailure(future.cause()); } else { // I must keep the handler here until now in case there is an exception so that I can log it ctx.pipeline().replace(HandlerConstants.DOMAIN_HANDLER, HandlerConstants.DOMAIN_HANDLER, dhb.build(domain)); authenticationFuture.setSuccess(ctx.channel()); } } }); ctx.pipeline().addAfter(HandlerConstants.LOG_DEBUG_HANDLER, HandlerConstants.SSL_HANDLER, sslHandler); } if (pdOrAuth.isB()) { if (logger.isLoggable(Level.FINE)) { logger.fine("Sending an Accept (" + ctx.channel().remoteAddress() + ")"); } // this must be sent after the ssh handler is replaced (when using ssl) so that we are ready to receive ssl data right away // but this must be sent before the domain handler is replaced (when not using ssl), because it will send // data and it must arrive AFTER our Accept ctx.writeAndFlush(new AuthAccept()); } // else it is done in the FutureListener if (sslHandler == null) { ctx.pipeline().replace(HandlerConstants.DOMAIN_HANDLER, HandlerConstants.DOMAIN_HANDLER, dhb.build(domain)); authenticationFuture.setSuccess(ctx.channel()); } }
From source file:org.ow2.petals.bc.gateway.inbound.ConsumerDomain.java
License:Open Source License
private void scheduleNextPolling(final long currentDelay, final double accel, final long maxDelay) { final Runnable command = new Runnable() { @Override/* w w w .j a va 2 s. c o m*/ public void run() { final long nextDelay; if (accel > 1) { nextDelay = Math.min((long) (currentDelay * accel), maxDelay); } else { nextDelay = maxDelay; } try { if (logger.isLoggable(Level.FINE)) { logger.fine("Propagation refresh polling (next in " + nextDelay + "ms)"); } // TODO catch exceptions?! if (sendPropagations(false)) { logger.info("Changes in propagations detected: refreshed!"); } } finally { try { // in case it was interrupted during the propagation sending // this will also reset the interrupted flag pollingLock.lockInterruptibly(); try { // polling corresponds to the current task // if it's null, it was cancelled (thus the test for // isCancelled is not really needed but well...) if (polling != null && !polling.isCancelled()) { scheduleNextPolling(nextDelay, accel, maxDelay); } } finally { pollingLock.unlock(); } } catch (final InterruptedException e) { // we were interrupted, it's ok, we stop there } } } }; final long delay; if (accel > 1) { delay = Math.min(currentDelay, maxDelay); } else { delay = maxDelay; } polling = (ScheduledFuture<?>) GlobalEventExecutor.INSTANCE.schedule(command, delay, TimeUnit.MILLISECONDS) .addListener(new FutureListener<Object>() { @Override public void operationComplete(final @Nullable Future<Object> future) throws Exception { assert future != null; if (!future.isSuccess() && !future.isCancelled()) { logger.log(Level.WARNING, "Error during propagation refresh polling", future.cause()); } } }); }