@SuppressWarnings({"UnnecessaryBoxing"}) public Client(final NettyTransportProvider provider, final SocketAddress address, final UUID id) { this.provider = provider; factory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool(MyThreadFactory.instance), Executors.newCachedThreadPool(MyThreadFactory.instance)); final ClientBootstrap bootstrap = new ClientBootstrap(factory); final NettyHandler handler = new ClientHandler(this.provider, id); bootstrap.getPipeline().addLast("handler", handler); bootstrap.setOption("tcpNoDelay", Boolean.valueOf(true)); bootstrap.setOption("keepAlive", Boolean.valueOf(true)); channelFuture = bootstrap.connect(address); }
@Override public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { // Suspend incoming traffic until connected to the remote host. final Channel inboundChannel = e.getChannel(); inboundChannel.setReadable(false); // Start the connection attempt. ClientBootstrap cb = new ClientBootstrap(cf); cb.getPipeline().addLast("handler", new OutboundHandler(e.getChannel())); ChannelFuture f = cb.connect(new InetSocketAddress(remoteHost, remotePort)); outboundChannel = f.getChannel(); f.addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { // Connection attempt succeeded: // Begin to accept incoming traffic. inboundChannel.setReadable(true); } else { // Close the connection if the connection attempt has failed. inboundChannel.close(); } } }); }
fsm.setInitState(new DisconnectedState(fsm)); ChannelPipeline pipeline = bootstrap.getPipeline(); pipeline.addLast("lengthbaseddecoder", new LengthFieldBasedFrameDecoder(8 * 1024, 0, 4, 0, 4));
@Override public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) { final Channel inboundChannel = e.getChannel(); RtmpProxy.ALL_CHANNELS.add(inboundChannel); inboundChannel.setReadable(false); ClientBootstrap cb = new ClientBootstrap(cf); cb.getPipeline().addLast("handshaker", new ProxyHandshakeHandler()); cb.getPipeline().addLast("handler", new OutboundHandler(e.getChannel())); ChannelFuture f = cb.connect(new InetSocketAddress(remoteHost, remotePort)); outboundChannel = f.getChannel(); f.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { logger.info("connected to remote host: {}, port: {}", remoteHost, remotePort); inboundChannel.setReadable(true); } else { inboundChannel.close(); } } }); }
@Override public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) { final Channel inboundChannel = e.getChannel(); RtmpProxy.ALL_CHANNELS.add(inboundChannel); inboundChannel.setReadable(false); ClientBootstrap cb = new ClientBootstrap(cf); cb.getPipeline().addLast("handshaker", new ProxyHandshakeHandler()); cb.getPipeline().addLast("handler", new OutboundHandler(e.getChannel())); ChannelFuture f = cb.connect(new InetSocketAddress(remoteHost, remotePort)); outboundChannel = f.getChannel(); f.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { logger.info("connected to remote host: {}, port: {}", remoteHost, remotePort); inboundChannel.setReadable(true); } else { inboundChannel.close(); } } }); }
cb.getPipeline().addFirst("ssl", new SslHandler(eg)); cb.getPipeline().addLast("decoder", new ObjectDecoder(commons.getInt("maxFramgeLength_",NettyChannelPipelineFactory.maxFramgeLength_))); cb.getPipeline().addLast("encoder", new ObjectEncoder(commons.getInt("estimatedLength_",NettyChannelPipelineFactory.estimatedLength_))); cb.getPipeline().addLast("handler", corr);
/** * Creates a new default SmppClient. * @param executor The executor that IO workers will be executed with. An * Executors.newCachedDaemonThreadPool() is recommended. The max threads * will never grow more than expectedSessions if NIO sockets are used. * @param expectedSessions The max number of concurrent sessions expected * to be active at any time. This number controls the max number of worker * threads that the underlying Netty library will use. If processing * occurs in a sessionHandler (a blocking op), be <b>VERY</b> careful * setting this to the correct number of concurrent sessions you expect. * @param monitorExecutor The scheduled executor that all sessions will share * to monitor themselves and expire requests. If null monitoring will * be disabled. */ public DefaultSmppClient(ExecutorService executors, int expectedSessions, ScheduledExecutorService monitorExecutor) { this.channels = new DefaultChannelGroup(); this.executors = executors; this.channelFactory = new NioClientSocketChannelFactory(this.executors, this.executors, expectedSessions); this.clientBootstrap = new ClientBootstrap(channelFactory); // we use the same default pipeline for all new channels - no need for a factory this.clientConnector = new SmppClientConnector(this.channels); this.clientBootstrap.getPipeline().addLast(SmppChannelConstants.PIPELINE_CLIENT_CONNECTOR_NAME, this.clientConnector); this.monitorExecutor = monitorExecutor; // a shared instance of a timer for session writeTimeout timing this.writeTimeoutTimer = new org.jboss.netty.util.HashedWheelTimer(); }
/** * Creates a new default SmppClient. * @param executor The executor that IO workers will be executed with. An * Executors.newCachedDaemonThreadPool() is recommended. The max threads * will never grow more than expectedSessions if NIO sockets are used. * @param expectedSessions The max number of concurrent sessions expected * to be active at any time. This number controls the max number of worker * threads that the underlying Netty library will use. If processing * occurs in a sessionHandler (a blocking op), be <b>VERY</b> careful * setting this to the correct number of concurrent sessions you expect. * @param monitorExecutor The scheduled executor that all sessions will share * to monitor themselves and expire requests. If null monitoring will * be disabled. */ public DefaultSmppClient(ExecutorService executors, int expectedSessions, ScheduledExecutorService monitorExecutor) { this.channels = new DefaultChannelGroup(); this.executors = executors; this.channelFactory = new NioClientSocketChannelFactory(this.executors, this.executors, expectedSessions); this.clientBootstrap = new ClientBootstrap(channelFactory); // we use the same default pipeline for all new channels - no need for a factory this.clientConnector = new SmppClientConnector(this.channels); this.clientBootstrap.getPipeline().addLast(SmppChannelConstants.PIPELINE_CLIENT_CONNECTOR_NAME, this.clientConnector); this.monitorExecutor = monitorExecutor; // a shared instance of a timer for session writeTimeout timing this.writeTimeoutTimer = new org.jboss.netty.util.HashedWheelTimer(); }
/** * Creates a new default SmppClient. * @param executor The executor that IO workers will be executed with. An * Executors.newCachedDaemonThreadPool() is recommended. The max threads * will never grow more than expectedSessions if NIO sockets are used. * @param expectedSessions The max number of concurrent sessions expected * to be active at any time. This number controls the max number of worker * threads that the underlying Netty library will use. If processing * occurs in a sessionHandler (a blocking op), be <b>VERY</b> careful * setting this to the correct number of concurrent sessions you expect. * @param monitorExecutor The scheduled executor that all sessions will share * to monitor themselves and expire requests. If null monitoring will * be disabled. */ public DefaultSmppClient(ExecutorService executors, int expectedSessions, ScheduledExecutorService monitorExecutor) { this.channels = new DefaultChannelGroup(); this.executors = executors; this.channelFactory = new NioClientSocketChannelFactory(this.executors, this.executors, expectedSessions); this.clientBootstrap = new ClientBootstrap(channelFactory); // we use the same default pipeline for all new channels - no need for a factory this.clientConnector = new SmppClientConnector(this.channels); this.clientBootstrap.getPipeline().addLast(SmppChannelConstants.PIPELINE_CLIENT_CONNECTOR_NAME, this.clientConnector); this.monitorExecutor = monitorExecutor; // a shared instance of a timer for session writeTimeout timing this.writeTimeoutTimer = new org.jboss.netty.util.HashedWheelTimer(); }
/** * Creates a new default SmppClient. * @param executor The executor that IO workers will be executed with. An * Executors.newCachedDaemonThreadPool() is recommended. The max threads * will never grow more than expectedSessions if NIO sockets are used. * @param expectedSessions The max number of concurrent sessions expected * to be active at any time. This number controls the max number of worker * threads that the underlying Netty library will use. If processing * occurs in a sessionHandler (a blocking op), be <b>VERY</b> careful * setting this to the correct number of concurrent sessions you expect. * @param monitorExecutor The scheduled executor that all sessions will share * to monitor themselves and expire requests. If null monitoring will * be disabled. */ public DefaultSmppClient(ExecutorService executors, int expectedSessions, ScheduledExecutorService monitorExecutor) { this.channels = new DefaultChannelGroup(); this.executors = executors; this.channelFactory = new NioClientSocketChannelFactory(this.executors, this.executors, expectedSessions); this.clientBootstrap = new ClientBootstrap(channelFactory); // we use the same default pipeline for all new channels - no need for a factory this.clientConnector = new SmppClientConnector(this.channels); this.clientBootstrap.getPipeline().addLast(SmppChannelConstants.PIPELINE_CLIENT_CONNECTOR_NAME, this.clientConnector); this.monitorExecutor = monitorExecutor; // a shared instance of a timer for session writeTimeout timing this.writeTimeoutTimer = new org.jboss.netty.util.HashedWheelTimer(); }
fsm.setInitState(new DisconnectedState(fsm)); ChannelPipeline pipeline = bootstrap.getPipeline(); pipeline.addLast("lengthbaseddecoder", new LengthFieldBasedFrameDecoder(8 * 1024, 0, 4, 0, 4)); pipeline.addLast("lengthprepender", new LengthFieldPrepender(4));
fsm.setInitState(new DisconnectedState(fsm)); ChannelPipeline pipeline = bootstrap.getPipeline(); pipeline.addLast("lengthbaseddecoder", new LengthFieldBasedFrameDecoder(8 * 1024, 0, 4, 0, 4)); pipeline.addLast("lengthprepender", new LengthFieldPrepender(4));