bootstrap.setOption("child.bufferFactory", new HeapChannelBufferFactory(ByteOrder.LITTLE_ENDIAN));
public TcpClient(final ChannelGroup channelGroup, final Executor executor) { this.channelGroup = channelGroup; channelFactory = new NioClientSocketChannelFactory(executor, executor); channelBufferFactory = new HeapChannelBufferFactory(ByteOrder.LITTLE_ENDIAN); bootstrap = new ClientBootstrap(channelFactory); bootstrap.setOption("bufferFactory", channelBufferFactory); setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT_DURATION, DEFAULT_CONNECTION_TIMEOUT_UNIT); setKeepAlive(DEFAULT_KEEP_ALIVE); namedChannelHandlers = Lists.newArrayList(); }
public void start() { Preconditions.checkState(outgoingChannel == null); channelFactory = new NioServerSocketChannelFactory(executorService, executorService); bootstrap = new ServerBootstrap(channelFactory); bootstrap.setOption("child.bufferFactory", new HeapChannelBufferFactory(ByteOrder.LITTLE_ENDIAN)); bootstrap.setOption("child.keepAlive", true); incomingChannelGroup = new DefaultChannelGroup(); bootstrap.setPipelineFactory(new TcpServerPipelineFactory(incomingChannelGroup, topicParticipantManager, serviceManager)); outgoingChannel = bootstrap.bind(bindAddress.toInetSocketAddress()); advertiseAddress.setPortCallable(new Callable<Integer>() { @Override public Integer call() throws Exception { return ((InetSocketAddress) outgoingChannel.getLocalAddress()).getPort(); } }); if (DEBUG) { log.info("Bound to: " + bindAddress); log.info("Advertising: " + advertiseAddress); } }
private Channel buildServerChannel() { TopicParticipantManager topicParticipantManager = new TopicParticipantManager(); ServiceManager serviceManager = new ServiceManager(); NioServerSocketChannelFactory channelFactory = new NioServerSocketChannelFactory(executorService, executorService); ServerBootstrap bootstrap = new ServerBootstrap(channelFactory); bootstrap.setOption("child.bufferFactory", new HeapChannelBufferFactory(ByteOrder.LITTLE_ENDIAN)); bootstrap.setOption("child.keepAlive", true); ChannelGroup serverChannelGroup = new DefaultChannelGroup(); TcpServerPipelineFactory serverPipelineFactory = new TcpServerPipelineFactory(serverChannelGroup, topicParticipantManager, serviceManager) { @Override public ChannelPipeline getPipeline() { ChannelPipeline pipeline = super.getPipeline(); // We're not interested firstIncomingMessageQueue testing the // handshake here. Removing it means connections are established // immediately. pipeline.remove(TcpServerPipelineFactory.HANDSHAKE_HANDLER); pipeline.addLast("ServerHandler", new ServerHandler()); return pipeline; } }; bootstrap.setPipelineFactory(serverPipelineFactory); Channel serverChannel = bootstrap.bind(new InetSocketAddress(0)); return serverChannel; }