Refine search
/** * This method simply delegates the call to * {@link ChannelFactory#releaseExternalResources()}. */ public void releaseExternalResources() { ChannelFactory factory = this.factory; if (factory != null) { factory.releaseExternalResources(); } }
pipeline.addLast("handler", handler); Channel channel = channelFactory.newChannel(pipeline); int tries = 0; ChannelFuture future = null; future = channel.connect(remoteAddress).awaitUninterruptibly(); if (!future.isSuccess()) { tries++; while (channel.isConnected()) { ChannelBuffer buffer; try { break; lastWriteFuture = channel.write(buffer);
/** * This method simply delegates the call to * {@link ChannelFactory#shutdown()}. */ public void shutdown() { ChannelFactory factory = this.factory; if (factory != null) { factory.shutdown(); } } /**
Channel ch = getFactory().newChannel(pipeline); boolean success = false; try { ch.getConfig().setOptions(getOptions()); success = true; } finally { if (!success) { ch.close(); ch.bind(localAddress);
/** * Stops the client. This must be called in all cases even if start failed. */ public void stop() { if (masterRunning) { channel.close().awaitUninterruptibly(); factory.releaseExternalResources(); masterRunning = false; } } }
public void close() throws Throwable { connected.set(false); // if (null != timer) { // timer.stop(); // timer = null; // } if (null != channel) { channel.close().awaitUninterruptibly(); channel.getFactory().releaseExternalResources(); synchronized (channel) { channel.notifyAll(); } channel = null; } }
} catch (InterruptedException e) { connectCheck.cancel(); connectCheck.getChannel().getCloseFuture().awaitUninterruptibly(); factory.releaseExternalResources(); throw e; connectCheck.getChannel().getCloseFuture().awaitUninterruptibly(); factory.releaseExternalResources(); return new JoinStatusImpl("Failed to connect to server - " + connectCheck.getCause().getMessage()); } else { allChannels.add(connectCheck.getChannel()); ClientConnectionHandler connectionHandler = connectCheck.getChannel().getPipeline().get(ClientConnectionHandler.class); if (connectionHandler == null) { JoinStatusImpl status = new JoinStatusImpl();
if (channel.isBound()) NettyAcceptor.log.warn(channel + " is still connected to " + channel.getRemoteAddress()); channelFactory.releaseExternalResources(); channelFactory = null;
/** * Reconnect to the remote address that the closed channel was connected to. * This creates a new {@link ChannelPipeline} with the same handler instances * contained in the old channel's pipeline. * * @param timeout Timer task handle. * * @throws Exception when reconnection fails. */ @Override public void run(Timeout timeout) throws Exception { ChannelPipeline old = channel.getPipeline(); CommandHandler<?, ?> handler = old.get(CommandHandler.class); RedisAsyncConnection<?, ?> connection = old.get(RedisAsyncConnection.class); ChannelPipeline pipeline = Channels.pipeline(this, handler, connection); Channel c = bootstrap.getFactory().newChannel(pipeline); c.getConfig().setOptions(bootstrap.getOptions()); c.connect((SocketAddress) bootstrap.getOption("remoteAddress")); } }
public static void connect(final ClientOptions options) { final ClientBootstrap bootstrap = getBootstrap(Executors.newCachedThreadPool(), options); final ChannelFuture future = bootstrap.connect(new InetSocketAddress(options.getHost(), options.getPort())); future.awaitUninterruptibly(); if(!future.isSuccess()) { // future.getCause().printStackTrace(); logger.error("error creating client connection: {}", future.getCause().getMessage()); } future.getChannel().getCloseFuture().awaitUninterruptibly(); bootstrap.getFactory().releaseExternalResources(); }
public synchronized void stop(boolean emergencyCloseDown) { LOGGER.info("[{}] Stopping Odette FTP service...", this); if (timer != null) { } if (channel != null) { // stop accepting incoming connections channel.unbind(); if (emergencyCloseDown) { ChannelGroupFuture closeActiveChannels = activeChildChannels.close(); // TODO send Emergency Close Down End Session to all channels open // TODO maybe safe to include a timeout argument here closeActiveChannels.awaitUninterruptibly(); } else { ChannelGroupFuture activeChannelsCloseFuture = getChannelGroupCloseFuture(activeChildChannels); // TODO maybe safe to include a timeout argument here activeChannelsCloseFuture.awaitUninterruptibly(); } timer.stop(); channel.getFactory().releaseExternalResources(); channel = null; timer = null; } LOGGER.info("[{}] Odette FTP is stopped.", this); }
public static void shutdownChannelFactory(ChannelFactory channelFactory, ExecutorService bossExecutor, ExecutorService workerExecutor, ChannelGroup allChannels) { // Close all channels if (allChannels != null) { closeChannels(allChannels); } // Shutdown the channel factory if (channelFactory != null) { channelFactory.shutdown(); } // Stop boss threads if (bossExecutor != null) { shutdownExecutor(bossExecutor, "bossExecutor"); } // Finally stop I/O workers if (workerExecutor != null) { shutdownExecutor(workerExecutor, "workerExecutor"); } // Release any other resources netty might be holding onto via this channelFactory if (channelFactory != null) { channelFactory.releaseExternalResources(); } }
@Override public Channel newChannel(ChannelPipeline pipeline) { Channel newChannel = channelFactory.newChannel(pipeline); ChannelConfig newChannelConfig = newChannel.getConfig(); newChannelConfig.setConnectTimeoutMillis((int) getConnectTimeoutMillis()); return newChannel; }
private <K, V, T extends RedisAsyncConnection<K, V>> T connect(CommandHandler<K, V> handler, T connection) { try { ConnectionWatchdog watchdog = new ConnectionWatchdog(bootstrap, channels, timer); ChannelPipeline pipeline = Channels.pipeline(watchdog, handler, connection); Channel channel = bootstrap.getFactory().newChannel(pipeline); ChannelFuture future = channel.connect((SocketAddress) bootstrap.getOption("remoteAddress")); future.await(); if (!future.isSuccess()) { throw future.getCause(); } watchdog.setReconnect(true); return connection; } catch (Throwable e) { throw new RedisException("Unable to connect", e); } }
Channel channel = getFactory().newChannel(bossPipeline); final ChannelFuture bfuture = new DefaultChannelFuture(channel, false); binder.bindFuture.addListener(new ChannelFutureListener() {
Channel ch = getFactory().newChannel(pipeline); boolean success = false; try { ch.getConfig().setOptions(getOptions()); success = true; } finally { if (!success) { ch.close(); ch.bind(localAddress);
public void close() { // Close the connection. channel.close().awaitUninterruptibly(); // Shut down all thread pools to exit. channelFactory.releaseExternalResources(); }
@Override public void stopServer() { log.info("Stopping Netty engine (" + getClass().getName() + ") on port " + getEngineConfiguration().getPort()); if (serverChannel != null) { serverChannel.close(); serverChannel.getFactory().releaseExternalResources(); } log.info("Netty engine (" + getClass().getName() + ") on port " + getEngineConfiguration().getPort() + " has stopped."); }
/** * Reconnect to the remote address that the closed channel was connected to. * This creates a new {@link ChannelPipeline} with the same handler instances * contained in the old channel's pipeline. * * @param timeout Timer task handle. * * @throws Exception when reconnection fails. */ @Override public void run(Timeout timeout) throws Exception { ChannelPipeline old = channel.getPipeline(); CommandHandler<?, ?> handler = old.get(CommandHandler.class); RedisAsyncConnection<?, ?> connection = old.get(RedisAsyncConnection.class); ChannelPipeline pipeline = Channels.pipeline(this, handler, connection); Channel c = bootstrap.getFactory().newChannel(pipeline); c.getConfig().setOptions(bootstrap.getOptions()); c.connect((SocketAddress) bootstrap.getOption("remoteAddress")); } }
public static void connect(final ClientOptions options) { final ClientBootstrap bootstrap = getBootstrap(Executors.newCachedThreadPool(), options); final ChannelFuture future = bootstrap.connect(new InetSocketAddress(options.getHost(), options.getPort())); future.awaitUninterruptibly(); if(!future.isSuccess()) { // future.getCause().printStackTrace(); logger.error("error creating client connection: {}", future.getCause().getMessage()); } future.getChannel().getCloseFuture().awaitUninterruptibly(); bootstrap.getFactory().releaseExternalResources(); }