use of io.netty.channel.ChannelPipeline in project tutorials-java by Artister.
the class ServerChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline pipeline = socketChannel.pipeline();
// 字符串解码 和 编码
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());
// 字符长度
pipeline.addLast(new LineBasedFrameDecoder(2048));
// 自己的逻辑Handler
pipeline.addLast("handler", new HelloWordServerHandler());
}
use of io.netty.channel.ChannelPipeline in project cosmic by MissionCriticalCloud.
the class NfsSecondaryStorageResource method startPostUploadServer.
private void startPostUploadServer() {
final int PORT = 8210;
final int NO_OF_WORKERS = 15;
final EventLoopGroup bossGroup = new NioEventLoopGroup(1);
final EventLoopGroup workerGroup = new NioEventLoopGroup(NO_OF_WORKERS);
final ServerBootstrap b = new ServerBootstrap();
final NfsSecondaryStorageResource storageResource = this;
b.group(bossGroup, workerGroup);
b.channel(NioServerSocketChannel.class);
b.handler(new LoggingHandler(LogLevel.INFO));
b.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(final SocketChannel ch) throws Exception {
final ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new HttpRequestDecoder());
pipeline.addLast(new HttpResponseEncoder());
pipeline.addLast(new HttpContentCompressor());
pipeline.addLast(new HttpUploadServerHandler(storageResource));
}
});
new Thread() {
@Override
public void run() {
try {
final Channel ch = b.bind(PORT).sync().channel();
s_logger.info(String.format("Started post upload server on port %d with %d workers", PORT, NO_OF_WORKERS));
ch.closeFuture().sync();
} catch (final InterruptedException e) {
s_logger.info("Failed to start post upload server");
s_logger.debug("Exception while starting post upload server", e);
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
s_logger.info("shutting down post upload server");
}
}
}.start();
s_logger.info("created a thread to start post upload server");
}
use of io.netty.channel.ChannelPipeline in project autobahn-java by crossbario.
the class NettyWebSocket method connect.
@Override
public void connect(ITransportHandler transportHandler, TransportOptions options) throws Exception {
if (options == null) {
if (mOptions == null) {
options = new TransportOptions();
} else {
options = new TransportOptions();
options.setAutoPingInterval(mOptions.getAutoPingInterval());
options.setAutoPingTimeout(mOptions.getAutoPingTimeout());
options.setMaxFramePayloadSize(mOptions.getMaxFramePayloadSize());
}
}
URI uri;
uri = new URI(mUri);
int port = validateURIAndGetPort(uri);
String scheme = uri.getScheme();
String host = uri.getHost();
final SslContext sslContext = getSSLContext(scheme);
WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, mSerializers, true, new DefaultHttpHeaders(), options.getMaxFramePayloadSize());
mHandler = new NettyWebSocketClientHandler(handshaker, this, transportHandler);
EventLoopGroup group = new NioEventLoopGroup();
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group);
bootstrap.channel(NioSocketChannel.class);
TransportOptions opt = options;
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline channelPipeline = ch.pipeline();
if (sslContext != null) {
channelPipeline.addLast(sslContext.newHandler(ch.alloc(), host, port));
}
channelPipeline.addLast(new HttpClientCodec(), new HttpObjectAggregator(8192), WebSocketClientCompressionHandler.INSTANCE, new IdleStateHandler(opt.getAutoPingInterval() + opt.getAutoPingTimeout(), opt.getAutoPingInterval(), 0, TimeUnit.SECONDS), mHandler);
}
});
mChannel = bootstrap.connect(uri.getHost(), port).sync().channel();
mHandler.getHandshakeFuture().sync();
}
use of io.netty.channel.ChannelPipeline in project jim-framework by jiangmin168168.
the class RpcServerInitializer method initChannel.
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
// logger.info("RpcServerInitializer.initChannel");
ChannelPipeline pipeline = socketChannel.pipeline();
;
Executor executor = this.rpcThreadPoolFactory.getThreadPool(ConstantConfig.DEFAULT_THREAD_POOL_NAME).getExecutor(1, 1);
pipeline.addLast(new RpcEncoder(RpcResponse.class)).addLast(new RpcDecoder(RpcRequest.class)).addLast(new IdleStateHandler(Constants.READER_TIME_SECONDS, 0, 0)).addLast(new ServerHeartbeatHandler()).addLast(new RpcServerInvoker(this.handlerMap, this.filterMap, executor));
}
use of io.netty.channel.ChannelPipeline in project runelite by runelite.
the class CacheClient method connect.
public void connect() {
Bootstrap b = new Bootstrap();
b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
// p.addFirst(new HttpProxyHandler(new InetSocketAddress("runelite.net", 3128)));
p.addLast("decoder", new HandshakeResponseDecoder());
p.addLast(new CacheClientHandler(), new HandshakeResponseHandler(CacheClient.this), new ArchiveResponseHandler(CacheClient.this));
p.addLast(new UpdateHandshakeEncoder(), new EncryptionEncoder(), new ArchiveRequestEncoder());
}
});
// Start the client.
ChannelFuture f = b.connect(host, PORT).syncUninterruptibly();
channel = f.channel();
}
Aggregations