List of usage examples for io.netty.util.concurrent Future await
Future<V> await() throws InterruptedException;
From source file:io.grpc.netty.NettyServer.java
License:Apache License
@Override public void start(ServerListener serverListener) throws IOException { listener = checkNotNull(serverListener, "serverListener"); ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup);/* w w w . ja va 2 s . com*/ b.channelFactory(channelFactory); // For non-socket based channel, the option will be ignored. b.option(SO_BACKLOG, 128); b.childOption(SO_KEEPALIVE, true); if (channelOptions != null) { for (Map.Entry<ChannelOption<?>, ?> entry : channelOptions.entrySet()) { @SuppressWarnings("unchecked") ChannelOption<Object> key = (ChannelOption<Object>) entry.getKey(); b.childOption(key, entry.getValue()); } } b.childHandler(new ChannelInitializer<Channel>() { @Override public void initChannel(Channel ch) { ChannelPromise channelDone = ch.newPromise(); long maxConnectionAgeInNanos = NettyServer.this.maxConnectionAgeInNanos; if (maxConnectionAgeInNanos != MAX_CONNECTION_AGE_NANOS_DISABLED) { // apply a random jitter of +/-10% to max connection age maxConnectionAgeInNanos = (long) ((.9D + Math.random() * .2D) * maxConnectionAgeInNanos); } NettyServerTransport transport = new NettyServerTransport(ch, channelDone, protocolNegotiator, streamTracerFactories, transportTracerFactory.create(), maxStreamsPerConnection, flowControlWindow, maxMessageSize, maxHeaderListSize, keepAliveTimeInNanos, keepAliveTimeoutInNanos, maxConnectionIdleInNanos, maxConnectionAgeInNanos, maxConnectionAgeGraceInNanos, permitKeepAliveWithoutCalls, permitKeepAliveTimeInNanos); ServerTransportListener transportListener; // This is to order callbacks on the listener, not to guard access to channel. synchronized (NettyServer.this) { if (channel != null && !channel.isOpen()) { // Server already shutdown. ch.close(); return; } // `channel` shutdown can race with `ch` initialization, so this is only safe to increment // inside the lock. eventLoopReferenceCounter.retain(); transportListener = listener.transportCreated(transport); } /** * Releases the event loop if the channel is "done", possibly due to the channel closing. */ final class LoopReleaser implements ChannelFutureListener { private boolean done; @Override public void operationComplete(ChannelFuture future) throws Exception { if (!done) { done = true; eventLoopReferenceCounter.release(); } } } transport.start(transportListener); ChannelFutureListener loopReleaser = new LoopReleaser(); channelDone.addListener(loopReleaser); ch.closeFuture().addListener(loopReleaser); } }); // Bind and start to accept incoming connections. ChannelFuture future = b.bind(address); try { future.await(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); throw new RuntimeException("Interrupted waiting for bind"); } if (!future.isSuccess()) { throw new IOException("Failed to bind", future.cause()); } channel = future.channel(); Future<?> channelzFuture = channel.eventLoop().submit(new Runnable() { @Override public void run() { InternalInstrumented<SocketStats> listenSocket = new ListenSocket(channel); listenSocketStats.set(listenSocket); channelz.addListenSocket(listenSocket); } }); try { channelzFuture.await(); } catch (InterruptedException ex) { throw new RuntimeException("Interrupted while registering listen socket to channelz", ex); } }
From source file:mmo.server.Server.java
License:Open Source License
public void shutdown() throws InterruptedException { timer.stop();/* w w w .j a v a 2s . c o m*/ Future<?> parentShutdown = parentGroup.shutdownGracefully(); Future<?> childShutdown = childGroup.shutdownGracefully(); Future<?> gameLoopShutdown = gameLoop.shutdownGracefully(); parentShutdown.await(); childShutdown.await(); gameLoopShutdown.await(); }
From source file:net.wessendorf.microprofile.service.PushSender.java
License:Apache License
private synchronized void connectToDestinations(final ApnsClient apnsClient) { logger.debug("connecting to APNs"); final Future<Void> connectFuture = apnsClient.connect(ApnsClient.DEVELOPMENT_APNS_HOST); try {// w ww .j a v a2s . c o m connectFuture.await(); } catch (InterruptedException e) { logger.error("Error connecting to APNs", e); } }
From source file:org.asynchttpclient.reactivestreams.HttpStaticFileServer.java
License:Apache License
public static void shutdown() { Future<?> bossFuture = bossGroup.shutdownGracefully(); Future<?> workerFuture = workerGroup.shutdownGracefully(); try {/*from www . ja va 2s.com*/ bossFuture.await(); workerFuture.await(); } catch (InterruptedException e) { e.printStackTrace(); } }
From source file:org.jboss.aerogear.unifiedpush.message.sender.apns.PushyApnsSender.java
License:Apache License
private synchronized void connectToDestinations(final iOSVariant iOSVariant, final ApnsClient apnsClient) { String apnsHost;/*from ww w .jav a 2 s .co m*/ int apnsPort = ApnsClient.DEFAULT_APNS_PORT; // are we production or development ? if (iOSVariant.isProduction()) { apnsHost = ApnsClient.PRODUCTION_APNS_HOST; } else { apnsHost = ApnsClient.DEVELOPMENT_APNS_HOST; } //Or is there even a custom ost&port provided by a system property, for tests ? if (customAerogearApnsPushHost != null) { apnsHost = customAerogearApnsPushHost; if (customAerogearApnsPushPort != null) { apnsPort = customAerogearApnsPushPort; } } // Once we've created a client, we can connect it to the APNs gateway. // Note that this process is asynchronous; we'll get a Future right // away, but we'll need to wait for it to complete before we can send // any notifications. Note that this is a Netty Future, which is an // extension of the Java Future interface that allows callers to add // listeners and adds methods for checking the status of the Future. logger.debug("connecting to APNs"); final Future<Void> connectFuture = apnsClient.connect(apnsHost, apnsPort); try { connectFuture.await(); } catch (InterruptedException e) { logger.error("Error connecting to APNs", e); } }
From source file:org.kaaproject.kaa.server.common.server.AbstractNettyServer.java
License:Apache License
/** * Netty HTTP server shutdown./*from ww w. ja v a 2 s . co m*/ */ public void shutdown() { LOG.info("NettyHttpServer stopping..."); if (bossGroup != null) { try { Future<? extends Object> future = bossGroup.shutdownGracefully(250, 1000, TimeUnit.MILLISECONDS); future.await(); } catch (InterruptedException exception) { LOG.trace("NettyHttpServer stopping: bossGroup error", exception); } finally { bossGroup = null; LOG.trace("NettyHttpServer stopping: bossGroup stoped"); } } if (workerGroup != null) { try { Future<? extends Object> future = workerGroup.shutdownGracefully(250, 1000, TimeUnit.MILLISECONDS); future.await(); } catch (InterruptedException exception) { LOG.trace("NettyHttpServer stopping: workerGroup error", exception); } finally { workerGroup = null; LOG.trace("NettyHttpServer stopping: workerGroup stopped"); } } }
From source file:org.redisson.RedissonBlockingDeque.java
License:Apache License
@Override public V takeFirst() throws InterruptedException { Future<V> res = takeFirstAsync(); return res.await().getNow(); }
From source file:org.redisson.RedissonBlockingDeque.java
License:Apache License
@Override public V takeLast() throws InterruptedException { Future<V> res = takeLastAsync(); return res.await().getNow(); }
From source file:org.redisson.RedissonBlockingDeque.java
License:Apache License
@Override public V pollFirstFromAny(long timeout, TimeUnit unit, String... queueNames) throws InterruptedException { Future<V> res = pollFirstFromAnyAsync(timeout, unit, queueNames); return res.await().getNow(); }
From source file:org.redisson.RedissonBlockingDeque.java
License:Apache License
@Override public V pollLastFromAny(long timeout, TimeUnit unit, String... queueNames) throws InterruptedException { Future<V> res = pollLastFromAnyAsync(timeout, unit, queueNames); return res.await().getNow(); }