@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."); }
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; } }
@Override public void write(Literal literal) throws IOException { if (channel.isConnected()) { InputStream in = literal.getInputStream(); if (in instanceof FileInputStream && channel.getFactory() instanceof NioServerSocketChannelFactory) { FileChannel fc = ((FileInputStream) in).getChannel(); // Zero-copy is only possible if no SSL/TLS and no COMPRESS is in place // // See JAMES-1305 and JAMES-1306 ChannelPipeline cp = channel.getPipeline(); if (zeroCopy && cp.get(SslHandler.class) == null && cp.get(ZlibEncoder.class) == null) { channel.write(new DefaultFileRegion(fc, fc.position(), literal.size())); } else { channel.write(new ChunkedNioFile(fc, 8192)); } } else { channel.write(new ChunkedStream(literal.getInputStream())); } } }
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); }
private NioChildDatagramChannel getChildChannel(Channel channel, SocketAddress remoteAddress) throws Exception { return childChannels.computeIfAbsent(remoteAddress, x -> { ChannelPipelineFactory childPipelineFactory = getPipelineFactory(); ChannelPipeline childPipeline; try { childPipeline = childPipelineFactory.getPipeline(); } catch (Exception e) { throw new RuntimeException(e); } ChannelFactory channelFactory = channel.getFactory(); NioChildDatagramChannel childChannel = ((NioServerDatagramChannelFactory)channelFactory).newChildChannel(channel, childPipeline); childChannel.setLocalAddress((InetSocketAddress) channel.getLocalAddress()); childChannel.setRemoteAddress((InetSocketAddress) remoteAddress); // fire child open on parent channel channel.getPipeline().sendUpstream(new DefaultChildChannelStateEvent(channel, childChannel)); AbstractNioWorker childWorker = childChannel.getWorker(); // Queue child channel connected event (as it needs to be run on child worker) ChannelStateEvent connected = new UpstreamChannelStateEvent(childChannel, ChannelState.CONNECTED, remoteAddress); childWorker.messageReceived(childChannel, connected); // Queue child channel open event (as it needs to be run on child worker) ChannelStateEvent open = new UpstreamChannelStateEvent(childChannel, ChannelState.OPEN, Boolean.TRUE); childWorker.messageReceived(childChannel, open); return childChannel; }); } }