use of org.jboss.netty.channel.ChannelPipelineFactory in project dubbo by alibaba.
the class NettyClient method doOpen.
@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", getTimeout());
final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
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;
}
});
}
use of org.jboss.netty.channel.ChannelPipelineFactory in project dubbo by alibaba.
the class NettyServer method doOpen.
@Override
protected void doOpen() throws Throwable {
NettyHelper.setNettyLoggerFactory();
ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerBoss", true));
ExecutorService worker = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerWorker", true));
ChannelFactory channelFactory = new NioServerSocketChannelFactory(boss, worker, getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS));
bootstrap = new ServerBootstrap(channelFactory);
final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
channels = nettyHandler.getChannels();
// https://issues.jboss.org/browse/NETTY-365
// https://issues.jboss.org/browse/NETTY-379
// final Timer timer = new HashedWheelTimer(new NamedThreadFactory("NettyIdleTimer", true));
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() {
NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyServer.this);
ChannelPipeline pipeline = Channels.pipeline();
/*int idleTimeout = getIdleTimeout();
if (idleTimeout > 10000) {
pipeline.addLast("timer", new IdleStateHandler(timer, idleTimeout / 1000, 0, 0));
}*/
pipeline.addLast("decoder", adapter.getDecoder());
pipeline.addLast("encoder", adapter.getEncoder());
pipeline.addLast("handler", nettyHandler);
return pipeline;
}
});
// bind
channel = bootstrap.bind(getBindAddress());
}
use of org.jboss.netty.channel.ChannelPipelineFactory in project databus by linkedin.
the class DummyHttpRequestHandler method setupClient.
private void setupClient() {
_clientBootstrap = new ClientBootstrap(new DefaultLocalClientChannelFactory());
_clientBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline clientPipeline = pipeline();
clientPipeline.addLast("client logger 1", new LoggingHandler("client logger 1", InternalLogLevel.DEBUG, true));
clientPipeline.addLast("codec", new HttpClientCodec());
clientPipeline.addLast("aggregator", new FooterAwareHttpChunkAggregator(1000000));
_responseHandler = new SimpleHttpResponseHandler();
clientPipeline.addLast("handler", _responseHandler);
clientPipeline.addLast("client logger 5", new LoggingHandler("client logger 5", InternalLogLevel.DEBUG, true));
return clientPipeline;
}
});
}
use of org.jboss.netty.channel.ChannelPipelineFactory in project camel by apache.
the class DefaultNettySharedHttpServer method doStart.
protected void doStart() throws Exception {
ObjectHelper.notNull(configuration, "setNettyServerBootstrapConfiguration() must be called with a NettyServerBootstrapConfiguration instance", this);
// port must be set
if (configuration.getPort() <= 0) {
throw new IllegalArgumentException("Port must be configured on NettySharedHttpServerBootstrapConfiguration " + configuration);
}
// hostname must be set
if (ObjectHelper.isEmpty(configuration.getHost())) {
throw new IllegalArgumentException("Host must be configured on NettySharedHttpServerBootstrapConfiguration " + configuration);
}
LOG.debug("NettySharedHttpServer using configuration: {}", configuration);
// force using tcp as the underlying transport
configuration.setProtocol("tcp");
channelFactory = new HttpServerMultiplexChannelHandler();
channelFactory.init(configuration.getPort());
ChannelPipelineFactory pipelineFactory = new HttpServerSharedPipelineFactory(configuration, channelFactory, classResolver);
// thread factory and pattern
String port = Matcher.quoteReplacement("" + configuration.getPort());
String pattern = threadPattern;
pattern = pattern.replaceFirst("#port#", port);
ThreadFactory tf = new CamelThreadFactory(pattern, "NettySharedHttpServer", true);
// create bootstrap factory and disable compatible check as its shared among the consumers
bootstrapFactory = new HttpServerBootstrapFactory(channelFactory, false);
bootstrapFactory.init(tf, configuration, pipelineFactory);
ServiceHelper.startServices(channelFactory);
if (startServer) {
LOG.info("Starting NettySharedHttpServer on {}:{}", configuration.getHost(), configuration.getPort());
ServiceHelper.startServices(bootstrapFactory);
}
}
use of org.jboss.netty.channel.ChannelPipelineFactory in project camel by apache.
the class NettyUdpConnectedSendTest method createNettyUdpReceiver.
public void createNettyUdpReceiver() {
bootstrap = new ConnectionlessBootstrap(new NioDatagramChannelFactory());
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline channelPipeline = Channels.pipeline();
channelPipeline.addLast("StringDecoder", new StringDecoder(CharsetUtil.UTF_8));
channelPipeline.addLast("ContentHandler", new ContentHandler());
return channelPipeline;
}
});
}
Aggregations