本文整理汇总了Java中io.netty.channel.ChannelPipeline.addLast方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelPipeline.addLast方法的具体用法?Java ChannelPipeline.addLast怎么用?Java ChannelPipeline.addLast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.ChannelPipeline
的用法示例。
在下文中一共展示了ChannelPipeline.addLast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initChannel
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
/**
* Adds pipelines to channel.
*
* @param ch channel to be operated on
*/
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipe = ch.pipeline();
if (ssl) {
// HTTPs connection
SSLEngine sslEng = getSsl(null);
sslEng.setUseClientMode(true);
pipe.addLast("SSL", new SslHandler(sslEng, false));
}
pipe.addFirst("Timer", new ReadTimeoutHandler(30));
pipe.addLast("Codec", new HttpClientCodec());
pipe.addLast("Inflater", new HttpContentDecompressor());
pipe.addLast("Handler", new HTTPMessageHandler(builder));
}
示例2: initChannel
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// 根据服务端协议,选择解码器
Constants.ProtocolType type = transportConfig.getProvider().getProtocolType();
switch (type) {
case jsf:
pipeline.addLast(new JSFEncoder());
pipeline.addLast(new JSFDecoder(transportConfig.getPayload()));
break;
case dubbo:
pipeline.addLast(new DubboEncoder());
pipeline.addLast(new DubboDecoder(transportConfig.getPayload()));
break;
default:
throw new InitErrorException("Unsupported client protocol type : " + type.name());
}
pipeline.addLast(Constants.CLIENT_CHANNELHANDLE_NAME, clientChannelHandler);
}
示例3: initChannel
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new LoggingHandler());
// Add SSL handler first to encrypt and decrypt everything.
// In this example, we use a bogus certificate in the server side
// and accept any invalid certificates in the client side.
// You will need something more complicated to identify both
// and server in the real world.
if (sslCtx != null)
pipeline.addLast(sslCtx.newHandler(ch.alloc(), SecureChatClient.HOST, SecureChatClient.PORT));
// On top of the SSL handler, add the text line codec.
pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
pipeline.addLast(new StringDecoder());
pipeline.addLast(new StringEncoder());
// and then business logic.
pipeline.addLast(new SecureChatClientHandler());
}
示例4: initChannel
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("encoder", new MqttMessageEncoder());
pipeline.addLast("decoder", new MqttMessageDecoder());
pipeline.addLast("handler", new MqttMessageHandler());
}
示例5: initChannel
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if(sslCtx!=null)
{
p.addLast(new SslHandler(sslCtx.newEngine(ch.alloc())));
}
p.addLast(new HttpResponseDecoder());
//限制contentLength
p.addLast(new HttpObjectAggregator(65536));
p.addLast(new HttpRequestEncoder());
//大文件传输处理
// p.addLast(new ChunkedWriteHandler());
p.addLast(new DefaultListenerHandler<HttpResponse>(listener));
}
示例6: initChannel
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
final ChannelPipeline pipeline = socketChannel.pipeline();
NettyPipelineInit.serializePipeline(serializeProtocolEnum, pipeline);
pipeline.addLast("timeout", new IdleStateHandler(txConfig.getHeartTime(), txConfig.getHeartTime(), txConfig.getHeartTime(), TimeUnit.SECONDS));
pipeline.addLast(nettyClientMessageHandler);
}
示例7: initChannel
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
@Override
public void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline p = socketChannel.pipeline();
p.addLast(new SocksInitRequestDecoder());
p.addLast(socksMessageEncoder);
p.addLast(socksServerHandler);
p.addLast(trafficHandler);
}
示例8: initChannel
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// SSL的安全链接
if (ServerConfig.isSsl()) {
SSLContext sslcontext = SSLContext.getInstance("TLS");
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
KeyStore ks = KeyStore.getInstance("JKS");
String keyStorePath = ServerConfig.getKeyStorePath();
String keyStorePassword = ServerConfig.getKeyStorePassword();
ks.load(new FileInputStream(keyStorePath), keyStorePassword.toCharArray());
String keyPassword = ServerConfig.getKeyPassword();
kmf.init(ks, keyPassword.toCharArray());
sslcontext.init(kmf.getKeyManagers(), null, null);
SSLEngine sslEngine = sslcontext.createSSLEngine();
sslEngine.setUseClientMode(false);
sslEngine.setNeedClientAuth(false);
/**
* 务必放在第一位
*/
pipeline.addLast(new SslHandler(sslEngine));
logger.info("initChannel: addLast SslHandler");
/**
* Generates a temporary self-signed certificate for testing purposes.
*/
/*SelfSignedCertificate ssc = new SelfSignedCertificate();
SslContext sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
//SslContext sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
if (sslCtx != null) {
pipeline.addLast(sslCtx.newHandler(ch.alloc()));
}*/
}
// Register HTTP handler chain.
this.appendHttpPipeline(pipeline);
}
示例9: initChannel
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
@Override
protected void initChannel( SocketChannel _channel ) throws Exception {
logger.info( "Netty Server init channel: " + _channel.isActive() ) ;
ChannelPipeline pipeline = _channel.pipeline() ;
pipeline.addLast( ( AbsNettyDecoder ) CommonContextHolder.getBean( INettyHandler.NETTY_DECODER ) ) ;
pipeline.addLast( new IdleStateHandler( 100 , 0 , 0 , TimeUnit.SECONDS ) ) ;
pipeline.addLast( ( INettyHandler ) CommonContextHolder.getBean( INettyHandler.NETTY_HANDLER ) ) ;
}
示例10: initChannel
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
//pipeline.addLast("http-compressor", new HttpContentCompressor());
pipeline.addLast("http-codec", new HttpServerCodec());
pipeline.addLast("http-aggregator", new HttpObjectAggregator(65536));
pipeline.addLast("http-chunked", new ChunkedWriteHandler());
pipeline.addLast("http-handler", new HttpRedirectHandler());
}
示例11: initChannel
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception
{
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
pipeline.addLast(new MessageDecoder());
pipeline.addLast(new MessageEncoder());
pipeline.addLast(new ServerHandler());
}
示例12: channelCreated
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
public void channelCreated(Channel channel) throws Exception {
if (LOG.isInfoEnabled()) {
LOG.info("channel created : {}", channel.toString());
}
ChannelPipeline pipeline = channel.pipeline();
pipeline.addLast(new IdleStateHandler(readTimeout, 0, idleTimeout, TimeUnit.MILLISECONDS));
pipeline.addLast(new ChunkedWriteHandler()).addLast(new FastdfsHandler());
}
示例13: initChannel
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
@Override
public void initChannel(final SocketChannel ch) {
final ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new DelimiterBasedFrameDecoder(1048576 * 2, Delimiters.lineDelimiter()));
pipeline.addLast(new StringDecoder());
pipeline.addLast(new StringEncoder());
pipeline.addLast(new NettyClientHandler(this.consumer));
}
示例14: initChannel
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
ProtobufAdapter adapter = new ProtobufAdapter(config);
ChannelPipeline pipeline = socketChannel.pipeline();
pipeline.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
pipeline.addLast("decoder", adapter.getDecoder());
pipeline.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender());
pipeline.addLast("encoder", adapter.getEncoder());
pipeline.addLast("handler", new TcpServerHandler(config));
}
示例15: initChannel
import io.netty.channel.ChannelPipeline; //导入方法依赖的package包/类
@Override
protected void initChannel(Channel channel) throws Exception {
//IdleStateHandler检测心跳.
ChannelPipeline p = channel.pipeline();
p.addLast(new IdleStateHandler(20, 10, 0));
p.addLast(new ObjectEncoder());
p.addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)));
p.addLast(new NettyClientHandler());
}