use of io.netty.channel.ChannelPipeline in project cdap by caskdata.
the class NettyRouter method createServerBootstrap.
private ServerBootstrap createServerBootstrap(final ChannelGroup channelGroup) throws ServiceBindException {
EventLoopGroup bossGroup = createEventLoopGroup(serverBossThreadPoolSize, "router-server-boss-thread-%d");
EventLoopGroup workerGroup = createEventLoopGroup(serverWorkerThreadPoolSize, "router-server-worker-thread-%d");
return new ServerBootstrap().group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, serverConnectionBacklog).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
channelGroup.add(ch);
ChannelPipeline pipeline = ch.pipeline();
if (isSSLEnabled()) {
pipeline.addLast("ssl", sslHandlerFactory.create(ch.alloc()));
}
pipeline.addLast("http-codec", new HttpServerCodec());
pipeline.addLast("http-status-request-handler", new HttpStatusRequestHandler());
if (securityEnabled) {
pipeline.addLast("access-token-authenticator", new AuthenticationHandler(cConf, tokenValidator, discoveryServiceClient, accessTokenTransformer));
}
if (cConf.getBoolean(Constants.Router.ROUTER_AUDIT_LOG_ENABLED)) {
pipeline.addLast("audit-log", new AuditLogHandler());
}
// Always let the client to continue sending the request body after the authentication passed
pipeline.addLast("expect-continue", new HttpServerExpectContinueHandler());
// for now there's only one hardcoded rule, but if there will be more, we may want it generic and configurable
pipeline.addLast("http-request-handler", new HttpRequestRouter(cConf, serviceLookup));
}
});
}
use of io.netty.channel.ChannelPipeline in project xian by happyyangyuan.
the class RpcNettyClientInitializer method initChannel.
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
if (sslCtx != null) {
pipeline.addLast(sslCtx.newHandler(ch.alloc(), HOST, PORT));
}
pipeline.addLast(new DelimiterBasedFrameDecoder(Integer.MAX_VALUE, new ByteBuf[] { Unpooled.wrappedBuffer(Constant.RPC_DELIMITER.getBytes()) }));
pipeline.addLast(DECODER);
pipeline.addLast(ENCODER);
// and then unit logic.
pipeline.addLast(new RpcClientHandler(nodeId));
pipeline.addLast(new RpcClientDecoder());
pipeline.addLast(new StreamRpcClientHandler());
pipeline.addLast(new RpcClientUnitHandler());
}
use of io.netty.channel.ChannelPipeline in project xian by happyyangyuan.
the class DefaultInitializer method initChannel.
@Override
public void initChannel(SocketChannel ch) throws Exception {
final ChannelPipeline p = ch.pipeline();
initOutboundHandlers(p);
initInboundHandlers(p);
initIdleStateHandlers(p);
}
use of io.netty.channel.ChannelPipeline in project bgpcep by opendaylight.
the class PeerTest method mockSession.
private void mockSession() {
final EventLoop eventLoop = mock(EventLoop.class);
final Channel channel = mock(Channel.class);
final ChannelPipeline pipeline = mock(ChannelPipeline.class);
doReturn(null).when(eventLoop).schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
doReturn(eventLoop).when(channel).eventLoop();
doReturn(Boolean.TRUE).when(channel).isWritable();
doReturn(null).when(channel).close();
doReturn(pipeline).when(channel).pipeline();
doCallRealMethod().when(channel).toString();
doReturn(pipeline).when(pipeline).addLast(any(ChannelHandler.class));
doReturn(new DefaultChannelPromise(channel)).when(channel).writeAndFlush(any(Notification.class));
doReturn(new InetSocketAddress("localhost", 12345)).when(channel).remoteAddress();
doReturn(new InetSocketAddress("localhost", 12345)).when(channel).localAddress();
final List<BgpParameters> params = Lists.newArrayList(new BgpParametersBuilder().setOptionalCapabilities(Lists.newArrayList(new OptionalCapabilitiesBuilder().setCParameters(new CParametersBuilder().addAugmentation(CParameters1.class, new CParameters1Builder().setMultiprotocolCapability(new MultiprotocolCapabilityBuilder().setAfi(Ipv4AddressFamily.class).setSafi(UnicastSubsequentAddressFamily.class).build()).build()).build()).build())).build());
final Open openObj = new OpenBuilder().setBgpIdentifier(new Ipv4Address("1.1.1.1")).setHoldTimer(50).setMyAsNumber(72).setBgpParameters(params).build();
this.session = new BGPSessionImpl(this.classic, channel, openObj, 30, null);
this.session.setChannelExtMsgCoder(openObj);
}
use of io.netty.channel.ChannelPipeline in project tutorials-java by Artister.
the class ClientChannelInitializer method initChannel.
protected void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline pipeline = socketChannel.pipeline();
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("encoder", new StringEncoder());
// 客户端的handler
// 先调用handler在ChannnelActive方法中调用fireChannelActive会激活handler1
pipeline.addLast("handler", new HwClientHandler());
pipeline.addLast("handler1", new BaseClientHandler());
}
Aggregations