use of org.jboss.netty.channel.ChannelPipeline in project camel by apache.
the class DefaultServerPipelineFactory method getPipeline.
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline channelPipeline = Channels.pipeline();
SslHandler sslHandler = configureServerSSLOnDemand();
if (sslHandler != null) {
// must close on SSL exception
sslHandler.setCloseOnSSLException(true);
LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
addToPipeline("ssl", channelPipeline, sslHandler);
}
List<ChannelHandler> encoders = consumer.getConfiguration().getEncoders();
for (int x = 0; x < encoders.size(); x++) {
ChannelHandler encoder = encoders.get(x);
if (encoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
}
addToPipeline("encoder-" + x, channelPipeline, encoder);
}
List<ChannelHandler> decoders = consumer.getConfiguration().getDecoders();
for (int x = 0; x < decoders.size(); x++) {
ChannelHandler decoder = decoders.get(x);
if (decoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
}
addToPipeline("decoder-" + x, channelPipeline, decoder);
}
if (consumer.getConfiguration().isOrderedThreadPoolExecutor()) {
// this must be added just before the ServerChannelHandler
// use ordered thread pool, to ensure we process the events in order, and can send back
// replies in the expected order. eg this is required by TCP.
// and use a Camel thread factory so we have consistent thread namings
ExecutionHandler executionHandler = new ExecutionHandler(consumer.getEndpoint().getComponent().getExecutorService());
addToPipeline("executionHandler", channelPipeline, executionHandler);
LOG.debug("Using OrderedMemoryAwareThreadPoolExecutor with core pool size: {}", consumer.getConfiguration().getMaximumPoolSize());
}
// our handler must be added last
addToPipeline("handler", channelPipeline, new ServerChannelHandler(consumer));
LOG.trace("Created ChannelPipeline: {}", channelPipeline);
return channelPipeline;
}
use of org.jboss.netty.channel.ChannelPipeline in project camel by apache.
the class NettyUdpConnectionlessSendTest 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;
}
});
}
use of org.jboss.netty.channel.ChannelPipeline in project camel by apache.
the class HttpClientPipelineFactory method getPipeline.
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
SslHandler sslHandler = configureClientSSLOnDemand();
if (sslHandler != null) {
// must close on SSL exception
sslHandler.setCloseOnSSLException(true);
LOG.debug("Client SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
pipeline.addLast("ssl", sslHandler);
}
pipeline.addLast("http", new HttpClientCodec());
List<ChannelHandler> decoders = producer.getConfiguration().getDecoders();
for (int x = 0; x < decoders.size(); x++) {
ChannelHandler decoder = decoders.get(x);
if (decoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
}
pipeline.addLast("decoder-" + x, decoder);
}
List<ChannelHandler> encoders = producer.getConfiguration().getEncoders();
for (int x = 0; x < encoders.size(); x++) {
ChannelHandler encoder = encoders.get(x);
if (encoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
}
pipeline.addLast("encoder-" + x, encoder);
}
if (producer.getConfiguration().getRequestTimeout() > 0) {
if (LOG.isTraceEnabled()) {
LOG.trace("Using request timeout {} millis", producer.getConfiguration().getRequestTimeout());
}
ChannelHandler timeout = new ReadTimeoutHandler(producer.getEndpoint().getTimer(), producer.getConfiguration().getRequestTimeout(), TimeUnit.MILLISECONDS);
pipeline.addLast("timeout", timeout);
}
// handler to route Camel messages
pipeline.addLast("handler", new HttpClientChannelHandler(producer));
return pipeline;
}
use of org.jboss.netty.channel.ChannelPipeline in project camel by apache.
the class HttpServerPipelineFactory method getPipeline.
@Override
public ChannelPipeline getPipeline() throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = Channels.pipeline();
SslHandler sslHandler = configureServerSSLOnDemand();
if (sslHandler != null) {
// must close on SSL exception
sslHandler.setCloseOnSSLException(true);
LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
pipeline.addLast("ssl", sslHandler);
}
pipeline.addLast("decoder", new HttpRequestDecoder(4096, configuration.getMaxHeaderSize(), 8192));
List<ChannelHandler> decoders = consumer.getConfiguration().getDecoders();
for (int x = 0; x < decoders.size(); x++) {
ChannelHandler decoder = decoders.get(x);
if (decoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
}
pipeline.addLast("decoder-" + x, decoder);
}
pipeline.addLast("aggregator", new HttpChunkAggregator(configuration.getChunkedMaxContentLength()));
pipeline.addLast("encoder", new HttpResponseEncoder());
List<ChannelHandler> encoders = consumer.getConfiguration().getEncoders();
for (int x = 0; x < encoders.size(); x++) {
ChannelHandler encoder = encoders.get(x);
if (encoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
}
pipeline.addLast("encoder-" + x, encoder);
}
if (supportCompressed()) {
pipeline.addLast("deflater", new HttpContentCompressor());
}
if (consumer.getConfiguration().isOrderedThreadPoolExecutor()) {
// this must be added just before the HttpServerMultiplexChannelHandler
// use ordered thread pool, to ensure we process the events in order, and can send back
// replies in the expected order. eg this is required by TCP.
// and use a Camel thread factory so we have consistent thread namings
ExecutionHandler executionHandler = new ExecutionHandler(consumer.getEndpoint().getComponent().getExecutorService());
pipeline.addLast("executionHandler", executionHandler);
LOG.debug("Using OrderedMemoryAwareThreadPoolExecutor with core pool size: {}", consumer.getConfiguration().getMaximumPoolSize());
}
int port = consumer.getConfiguration().getPort();
ChannelHandler handler = consumer.getEndpoint().getComponent().getMultiplexChannelHandler(port).getChannelHandler();
pipeline.addLast("handler", handler);
return pipeline;
}
use of org.jboss.netty.channel.ChannelPipeline in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850Config method serverBootstrap.
/**
* Returns a ServerBootstrap setting up a server pipeline listening for
* incoming IEC61850 register device requests.
*
* @return an IEC61850 server bootstrap.
*/
@Bean(destroyMethod = "releaseExternalResources")
public ServerBootstrap serverBootstrap() {
final ChannelFactory factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
final ServerBootstrap bootstrap = new ServerBootstrap(factory);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws ProtocolAdapterException {
final ChannelPipeline pipeline = Iec61850Config.this.createChannelPipeline(Iec61850Config.this.iec61850ChannelHandlerServer());
LOGGER.info("Created new IEC61850 handler pipeline for server");
return pipeline;
}
});
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", false);
bootstrap.bind(new InetSocketAddress(this.iec61850PortListener()));
return bootstrap;
}
Aggregations