Refine search
public void stop() { channelGroup.close().awaitUninterruptibly(); }
/** * Shuts down this channel pool and releases all retained resources. * * @return a {@code Future} that will be completed when all resources held by this pool have been released */ public Future<Void> close() { return this.allChannels.close().addListener(new GenericFutureListener<Future<Void>>() { @Override public void operationComplete(final Future<Void> future) throws Exception { ApnsChannelPool.this.isClosed = true; if (ApnsChannelPool.this.channelFactory instanceof Closeable) { ((Closeable) ApnsChannelPool.this.channelFactory).close(); } for (final Promise<Channel> acquisitionPromise : ApnsChannelPool.this.pendingAcquisitionPromises) { acquisitionPromise.tryFailure(POOL_CLOSED_EXCEPTION); } } }); } }
@Override public <T> void broadcastSync(T message, MediaType mediaType, Predicate<WebSocketSession> filter) { WebSocketFrame frame = webSocketMessageEncoder.encodeMessage(message, mediaType); try { webSocketSessionRepository.getChannelGroup().writeAndFlush(frame, ch -> { Attribute<NettyRxWebSocketSession> attr = ch.attr(NettyRxWebSocketSession.WEB_SOCKET_SESSION_KEY); NettyRxWebSocketSession s = attr.get(); return s != null && s.isOpen() && filter.test(s); }).sync(); } catch (InterruptedException e) { throw new WebSocketSessionException("Broadcast Interrupted"); } }
private void actualClose(final ContextInternal closeContext, final Handler<AsyncResult<Void>> done) { if (id != null) { vertx.sharedHttpServers().remove(id); } ContextInternal currCon = vertx.getContext(); for (ConnectionBase conn : connectionMap.values()) { conn.close(); } // Sanity check if (vertx.getContext() != currCon) { throw new IllegalStateException("Context was changed"); } if (metrics != null) { metrics.close(); } ChannelGroupFuture fut = serverChannelGroup.close(); fut.addListener(cgf -> executeCloseDone(closeContext, done, fut.cause())); }
@Override public synchronized void pause() { if (paused) { return; } if (channelClazz == null) { return; } // We *pause* the acceptor so no new connections are made if (serverChannelGroup != null) { ChannelGroupFuture future = serverChannelGroup.close().awaitUninterruptibly(); if (!future.isSuccess()) { ActiveMQServerLogger.LOGGER.nettyChannelGroupBindError(); for (Channel channel : future.group()) { if (channel.isActive()) { ActiveMQServerLogger.LOGGER.nettyChannelStillBound(channel, channel.remoteAddress()); } } } } paused = true; }
protected void stopServerBootstrap() { // close all channels LOG.info("ConnectionlessBootstrap disconnecting from {}:{}", configuration.getHost(), configuration.getPort()); LOG.trace("Closing {} channels", allChannels.size()); allChannels.close().awaitUninterruptibly(); // and then shutdown the thread pools if (workerGroup != null) { workerGroup.shutdownGracefully(); workerGroup = null; } }
bootstrap = createBootstrap(channelGroup); Channel serverChannel = bootstrap.bind(bindAddress).sync().channel(); channelGroup.add(serverChannel); } catch (Throwable t) { channelGroup.close().awaitUninterruptibly(); try { if (bootstrap != null) {
private void close0() throws InterruptedException { LOGGER.log(Level.INFO, "Close this pool."); ChannelGroup channelGroup = new DefaultChannelGroup( GlobalEventExecutor.INSTANCE); Channel ch = idleChannels.poll(); while (ch != null) { try { channelGroup.add(ch); idleChannels.remove(ch); } catch (VirtualMachineError e) { throw e; } catch (Throwable t) { // NOOP, swallow this exception LOGGER.log(Level.WARNING, "Swallow this exception:" + t.getMessage()); } ch = idleChannels.poll(); } channelGroup.close().sync(); }
private void closeAllChannels(boolean graceful) { ChannelGroupFuture future = allChannels.close(); // if this is a graceful shutdown, log any channel closing failures. if this isn't a // graceful shutdown, ignore them. if (graceful) { try { future.await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } if (!future.isSuccess()) { for (ChannelFuture cf : future) { if (!cf.isSuccess()) { logger.info("Unable to close channel: " + cf.channel(), cf.cause()); } } } } } }
/** * Stop the Server */ public void stop() { if (started.getAndSet(false)) { runtime.destroy(); final ChannelGroupFuture future = ALL_CHANNELS.close(); future.awaitUninterruptibly(); ALL_CHANNELS.clear(); } }
/** * Stop proxy server * */ public void stop() { ChannelGroupFuture future = _allChannels.close().awaitUninterruptibly(); if (!future.isSuccess()) { final Iterator<ChannelFuture> iter = future.iterator(); while (iter.hasNext()) { final ChannelFuture cf = iter.next(); if (!cf.isSuccess()) { LOG.warn(String.format("Failed to close channel %s because %s", cf.channel(), cf.cause())); } } } _acceptorGroup.shutdownGracefully(); _upstreamWorkerGroup.shutdownGracefully(); _downstreamWorkerGroup.shutdownGracefully(); }
private void finishShutdown() { callbackStopRequest.run(); // Timeout any waiters which haven't received a Channel yet cancelWaiters(); // Close all active and idle Channels final TimeoutRunnable afterClose = new TimeoutRunnable( _scheduler, deadline - System.currentTimeMillis(), TimeUnit.MILLISECONDS, () -> { callbackShutdown.run(); LOG.info("Shutdown complete"); callback.onSuccess(None.none()); }, "Timed out waiting for channels to close, continuing shutdown"); _allChannels.close().addListener((ChannelGroupFutureListener) channelGroupFuture -> { if (!channelGroupFuture.isSuccess()) { LOG.warn("Failed to close some connections, ignoring"); } afterClose.run(); }); }
public void close() { System.out.println("Closing all sockets..."); DefaultChannelGroup allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); userSession.forEach((userKey, session) -> { allChannels.addAll(session.appChannels); allChannels.addAll(session.hardwareChannels); }); allChannels.close().awaitUninterruptibly(); }
@Override public <T> Flowable<T> broadcast(T message, MediaType mediaType, Predicate<WebSocketSession> filter) { return Flowable.create(emitter -> { try { WebSocketFrame frame = webSocketMessageEncoder.encodeMessage(message, mediaType); webSocketSessionRepository.getChannelGroup().writeAndFlush(frame, ch -> { Attribute<NettyRxWebSocketSession> attr = ch.attr(NettyRxWebSocketSession.WEB_SOCKET_SESSION_KEY); NettyRxWebSocketSession s = attr.get(); return s != null && s.isOpen() && filter.test(s); }).addListener(future -> { if (future.isSuccess()) { emitter.onNext(message); emitter.onComplete(); } else { Throwable cause = future.cause(); emitter.onError(new WebSocketSessionException("Broadcast Failure: " + cause.getMessage(), cause)); } }); } catch (Throwable e) { emitter.onError(new WebSocketSessionException("Broadcast Failure: " + e.getMessage(), e)); } }, BackpressureStrategy.BUFFER); } }
public static CompletableFuture<Void> completable(ChannelGroupFuture future) { CompletableFuture<Void> cf = new CompletableFuture<>(); future.addListener( (ChannelGroupFutureListener) future1 -> { if (future1.isSuccess()) { cf.complete(null); } else { cf.completeExceptionally(future1.cause()); } }); return cf; } }
ChannelGroupFuture channelsFuture = channels.newCloseFuture(); channelsFuture.addListener(new FutureListener<Void>() { @Override public void operationComplete(Future<Void> future) throws Exception {
private void closeClients(Promise<Void> clientsFuture) { log.info("Active Clients: {}",clientChannelGroup.size()); clientChannelGroup.closeIddleChannels(); clientChannelGroup.newCloseFuture().addListener(f->clientsFuture.setSuccess(null)); }