@Override public void stop() { bootstrap.releaseExternalResources(); } }
@Override public void stop() { if (serverBootstrap != null) serverBootstrap.shutdown(); }
public void run() { udpBootstrap.releaseExternalResources(); } });
public void start() { bootstrap = new ClientBootstrap(clientChannelFactory); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("reuseAddress", true); bootstrap.setOption("sendBufferSize", bufferSize); bootstrap.setOption("keepAlive", true); // Set up the pipeline factory. bootstrap.setPipelineFactory(new StormClientPipelineFactory(this, stormConf)); reconnect(); }
NettyServerCnxnFactory() { bootstrap = new ServerBootstrap( new NioServerSocketChannelFactory( Executors.newCachedThreadPool(), Executors.newCachedThreadPool())); // parent channel bootstrap.setOption("reuseAddress", true); // child channels bootstrap.setOption("child.tcpNoDelay", true); /* set socket linger to off, so that socket close does not block */ bootstrap.setOption("child.soLinger", -1); bootstrap.getPipeline().addLast("servercnxnfactory", channelHandler); }
public Bootstrap createServerBootstrap() { // TODO The thread pools should be injected from spring. serverBootstrap = new ServerBootstrap( new NioServerSocketChannelFactory(Executors .newFixedThreadPool(1,new NamedThreadFactory( "Flash-Server-Boss")), Executors .newFixedThreadPool(1,new NamedThreadFactory( "Flash-Server-Worker")))); return serverBootstrap; }
@Override public void start() { LOG.info("binding to port " + localAddress); parentChannel = bootstrap.bind(localAddress); }
/** * Attempts a new connection with the specified {@code remoteAddress} and * the current {@code "localAddress"} option. If the {@code "localAddress"} * option is not set, the local address of a new channel is determined * automatically. This method is identical with the following code: * * <pre> * {@link ClientBootstrap} b = ...; * b.connect(remoteAddress, b.getOption("localAddress")); * </pre> * * @return a future object which notifies when this connection attempt * succeeds or fails * * @throws ClassCastException * if {@code "localAddress"} option's value is * neither a {@link SocketAddress} nor {@code null} * @throws ChannelPipelineException * if this bootstrap's {@link #setPipelineFactory(ChannelPipelineFactory) pipelineFactory} * failed to create a new {@link ChannelPipeline} */ public ChannelFuture connect(SocketAddress remoteAddress) { if (remoteAddress == null) { throw new NullPointerException("remoteAddress"); } SocketAddress localAddress = (SocketAddress) getOption("localAddress"); return connect(remoteAddress, localAddress); }
/** * Closes the Netty Channel and releases all resources */ @Override protected void stopInner() { /* * TODO REST-Server Need to handle inflight operations. What happens to * the existing async operations when a channel.close() is issued in * Netty? */ if(this.nettyServerChannel != null) { this.nettyServerChannel.close(); } if(allChannels != null) { allChannels.close().awaitUninterruptibly(); } this.bootstrap.releaseExternalResources(); }
@Override public void startServer(InetSocketAddress socketAddress) { this.socketAddress = socketAddress; //TODO these should be set from spring serverBootstrap.setOption("broadcast", "false"); serverBootstrap.setOption("receiveBufferSizePredictorFactory", bufferSizePredictor); serverBootstrap.setOption("sendBufferSize", 65536); serverBootstrap.setOption("receiveBufferSize", 65536); configureServerBootStrap(args); try { channel = ((ConnectionlessBootstrap) serverBootstrap) .bind(socketAddress); } catch (ChannelException e) { LOG.error("Unable to start UDP server due to error {}",e); throw e; } }
/** * Creates a new channel which is bound to the local address which was * specified in the current {@code "localAddress"} option. This method is * similar to the following code: * * <pre> * {@link ConnectionlessBootstrap} b = ...; * b.bind(b.getOption("localAddress")); * </pre> * * @return a new bound channel which accepts incoming connections * * @throws IllegalStateException * if {@code "localAddress"} option was not set * @throws ClassCastException * if {@code "localAddress"} option's value is * neither a {@link SocketAddress} nor {@code null} * @throws ChannelException * if failed to create a new channel and * bind it to the local address */ public Channel bind() { SocketAddress localAddress = (SocketAddress) getOption("localAddress"); if (localAddress == null) { throw new IllegalStateException("localAddress option is not set."); } return bind(localAddress); }
/** * Creates a new datagram channel instance using the {@link #udpBootstrap} * by binding to local host. * * @param localhostName * The host machine (for e.g. 'localhost') to which it needs to * bind to. This is <b>Not</b> the remote jet-server hostname. * @return The newly created instance of the datagram channel. * @throws UnknownHostException */ public DatagramChannel createDatagramChannel(String localhostName) throws UnknownHostException { DatagramChannel datagramChannel = (DatagramChannel) udpBootstrap .bind(new InetSocketAddress(localhostName, 0)); return datagramChannel; }
@Override public Bootstrap createServerBootstrap() { serverBootstrap = new ConnectionlessBootstrap( new NioDatagramChannelFactory(Executors .newCachedThreadPool(new NamedThreadFactory( "UDP-Server-Worker")))); return serverBootstrap; }
@Override public void configureServerBootStrap(String[] optionsList) { // For clients who do not use spring. if(null == serverBootstrap){ createServerBootstrap(); } serverBootstrap.setPipelineFactory(pipelineFactory); if (null != optionsList && optionsList.length > 0) { for (String option : optionsList) { serverBootstrap.setOption(option, true); } } }
/** * Creates a new instance with the specified initial {@link ChannelFactory}. */ protected Bootstrap(ChannelFactory channelFactory) { setFactory(channelFactory); }
@Override protected void doOpen() throws Throwable { NettyHelper.setNettyLoggerFactory(); bootstrap = new ClientBootstrap(channelFactory); // config // @see org.jboss.netty.channel.socket.SocketChannelConfig bootstrap.setOption("keepAlive", true); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("connectTimeoutMillis", getConnectTimeout()); final NettyHandler nettyHandler = new NettyHandler(getUrl(), this); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() { NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this); ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("decoder", adapter.getDecoder()); pipeline.addLast("encoder", adapter.getEncoder()); pipeline.addLast("handler", nettyHandler); return pipeline; } }); }
public Bootstrap createServerBootstrap() { // TODO The thread pools should be injected from spring. serverBootstrap = new ServerBootstrap( new NioServerSocketChannelFactory(Executors .newCachedThreadPool(new NamedThreadFactory( "TCP-Server-Boss")), Executors .newCachedThreadPool(new NamedThreadFactory( "TCP-Server-Worker")))); return serverBootstrap; }
public void run() { ChannelGroupFuture future = ALL_CHANNELS.close(); try { future.await(NettyTCPClient.this.maxShutdownWaitTime); } catch (InterruptedException e) { e.printStackTrace(); } bootstrap.releaseExternalResources(); } });
@Override protected void doOpen() throws Throwable { NettyHelper.setNettyLoggerFactory(); bootstrap = new ClientBootstrap(channelFactory); // config // @see org.jboss.netty.channel.socket.SocketChannelConfig bootstrap.setOption("keepAlive", true); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("connectTimeoutMillis", getConnectTimeout()); final NettyHandler nettyHandler = new NettyHandler(getUrl(), this); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() { NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this); ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("decoder", adapter.getDecoder()); pipeline.addLast("encoder", adapter.getEncoder()); pipeline.addLast("handler", nettyHandler); return pipeline; } }); }
public ServerInfoService() { pool = Executors.newCachedThreadPool(); factory = new NioClientSocketChannelFactory(pool, pool, 1, 1); bootstrap = new ClientBootstrap(factory); bootstrap.setPipelineFactory(new InfoRequestPipelineFactory()); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); }