本文整理汇总了Java中io.netty.channel.Channel.pipeline方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.pipeline方法的具体用法?Java Channel.pipeline怎么用?Java Channel.pipeline使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.Channel
的用法示例。
在下文中一共展示了Channel.pipeline方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initChannel
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
protected void initChannel(Channel ch) throws Exception {
RPCChannelHandler channelHandler =
new RPCChannelHandler(syncManager, rpcService);
IdleStateHandler idleHandler =
new IdleStateHandler(5, 10, 0);
ReadTimeoutHandler readTimeoutHandler =
new ReadTimeoutHandler(30);
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("idle", idleHandler);
pipeline.addLast("timeout", readTimeoutHandler);
pipeline.addLast("handshaketimeout",
new HandshakeTimeoutHandler(channelHandler, timer, 10));
pipeline.addLast("syncMessageDecoder",
new SyncMessageDecoder(maxFrameSize));
pipeline.addLast("syncMessageEncoder",
new SyncMessageEncoder());
pipeline.addLast("handler", channelHandler);
}
示例2: initChannel
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
protected void initChannel(Channel channel) throws Exception {
ChannelPipeline pipeline = channel.pipeline();
BoundNode node = channel.parent().attr(HANDLER).get();
node.clientChannelGroup.add(channel);
MDC.put("node", node.getId().toString());
try {
logger.debug("Got new connection {}", channel);
pipeline
.addLast("decoder", new FrameDecoder(node.getFrameCodec()))
.addLast("encoder", new FrameEncoder(node.getFrameCodec()))
.addLast("requestHandler", new RequestHandler(node));
} finally {
MDC.remove("node");
}
}
示例3: unregisterChannelHandler
import io.netty.channel.Channel; //导入方法依赖的package包/类
private void unregisterChannelHandler() {
if (serverChannelHandler == null)
return;
for (Channel serverChannel : serverChannels) {
final ChannelPipeline pipeline = serverChannel.pipeline();
// Remove channel handler
serverChannel.eventLoop().execute(new Runnable() {
@Override
public void run() {
try {
pipeline.remove(serverChannelHandler);
} catch (NoSuchElementException e) {
// That's fine
}
}
});
}
}
示例4: channelCreated
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void channelCreated(Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (sslContext != null) {
SslHandler handler = sslContext.newHandler(ch.alloc());
p.addLast(handler);
handler.handshakeFuture().addListener(future -> {
if (!future.isSuccess()) {
log.error(() -> "SSL handshake failed.", future.cause());
}
});
}
p.addLast(new HttpClientCodec());
p.addLast(handlers);
// Disabling auto-read is needed for backpressure to work
ch.config().setOption(ChannelOption.AUTO_READ, false);
}
示例5: channelCreated
import io.netty.channel.Channel; //导入方法依赖的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());
}
示例6: initChannel
import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
* 通道注册的时候配置websocket解码handler
*/
@Override
protected final void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline=ch.pipeline();
pipeline.addLast(new HttpClientCodec());
pipeline.addLast(new ChunkedWriteHandler());
pipeline.addLast(new HttpObjectAggregator(64*1024));
pipeline.addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(new URI(url), WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
pipeline.addLast(new WebSocketConnectedClientHandler());//连接成功监听handler
}
示例7: initChannel
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
protected final void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline=ch.pipeline();
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new ChunkedWriteHandler());
pipeline.addLast(new HttpObjectAggregator(64*1024));
pipeline.addLast(new WebSocketServerProtocolHandler(uri));
pipeline.addLast(new WebSocketConnectedServerHandler());//连接成功监听handler
}
示例8: initChannel
import io.netty.channel.Channel; //导入方法依赖的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());
}
示例9: initChannel
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
protected void initChannel(Channel channel) throws Exception {
ChannelPipeline p = channel.pipeline();
p.addLast(new ObjectEncoder());
p.addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)));
p.addLast(new NettyServerHandler());
}
示例10: channelCreated
import io.netty.channel.Channel; //导入方法依赖的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());
}
示例11: fireChannelRead
import io.netty.channel.Channel; //导入方法依赖的package包/类
static void fireChannelRead(Channel ch, CodecOutputList<ByteBuf> bufList) {
ChannelPipeline childPipeline = ch.pipeline();
int size = bufList.size();
for (int i = 0; i < size; i++) {
ByteBuf msg = bufList.getUnsafe(i);
childPipeline.fireChannelRead(msg);
}
childPipeline.fireChannelReadComplete();
}
示例12: initChannel
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
OFChannelHandler handler = new OFChannelHandler(
switchManager,
connectionListener,
pipeline,
debugCounters,
timer,
ofBitmaps,
defaultFactory);
if (keyStore != null && keyStorePassword != null) {
try {
/* Set up factories and stores. */
TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore tmpKS = null;
tmFactory.init(tmpKS);
/* Use keystore/pass defined in properties file. */
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(keyStore), keyStorePassword.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(ks, keyStorePassword.toCharArray());
KeyManager[] km = kmf.getKeyManagers();
TrustManager[] tm = tmFactory.getTrustManagers();
/* Set up SSL prereqs for Netty. */
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(km, tm, null);
SSLEngine sslEngine = sslContext.createSSLEngine();
/* We are the server and we will create secure sessions. */
sslEngine.setUseClientMode(false);
sslEngine.setEnableSessionCreation(true);
/* These are redundant (default), but for clarity... */
sslEngine.setEnabledProtocols(sslEngine.getSupportedProtocols());
sslEngine.setEnabledCipherSuites(sslEngine.getSupportedCipherSuites());
/* First, decrypt w/handler+engine; then, proceed with rest of handlers. */
pipeline.addLast(PipelineHandler.SSL_TLS_ENCODER_DECODER, new SslHandler(sslEngine));
log.info("SSL OpenFlow socket initialized and handler ready for switch.");
} catch (Exception e) { /* There are lots of possible exceptions to catch, so this should get them all. */
log.error("Exception initializing SSL OpenFlow socket: {}", e.getMessage());
throw e; /* If we wanted secure but didn't get it, we should bail. */
}
}
pipeline.addLast(PipelineHandler.OF_MESSAGE_DECODER,
new OFMessageDecoder());
pipeline.addLast(PipelineHandler.OF_MESSAGE_ENCODER,
new OFMessageEncoder());
pipeline.addLast(PipelineHandler.MAIN_IDLE,
new IdleStateHandler(PipelineIdleReadTimeout.MAIN,
PipelineIdleWriteTimeout.MAIN,
0));
pipeline.addLast(PipelineHandler.READ_TIMEOUT, new ReadTimeoutHandler(30));
pipeline.addLast(PipelineHandler.CHANNEL_HANDSHAKE_TIMEOUT,
new HandshakeTimeoutHandler(
handler,
timer,
PipelineHandshakeTimeout.CHANNEL));
pipeline.addLast(PipelineHandler.CHANNEL_HANDLER, handler);
}
示例13: initChannel
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
protected void initChannel(Channel channel) throws Exception {
ChannelPipeline pipeline = channel.pipeline();
pipeline.addLast("timeout", new ReadTimeoutHandler(10));
NetworkManager networkManager = new NetworkManager(connectionProvider.getCore());
pipeline.addLast("packet_codec", new PacketCodec(networkManager.getProtocolManager()));
pipeline.addLast("network_manager", networkManager);
for (ConnectionInitListener initializerListener : connectionProvider.getInitializerListeners()) {
initializerListener.init(networkManager);
}
}
示例14: initChannel
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
protected void initChannel(Channel ch) throws Exception {
BootstrapChannelHandler handler =
new BootstrapChannelHandler(bootstrap);
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("syncMessageDecoder", new SyncMessageDecoder(maxFrameSize));
pipeline.addLast("syncMessageEncoder", new SyncMessageEncoder());
pipeline.addLast("timeout", new BootstrapTimeoutHandler(timer, 10));
pipeline.addLast("handler", handler);
}
示例15: initChannel
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
protected void initChannel(Channel ch) throws Exception {
RemoteSyncChannelHandler channelHandler =
new RemoteSyncChannelHandler(syncManager);
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("syncMessageDecoder", new SyncMessageDecoder(maxFrameSize));
pipeline.addLast("syncMessageEncoder", new SyncMessageEncoder());
pipeline.addLast("timeout", new RSHandshakeTimeoutHandler(channelHandler, timer, 3));
pipeline.addLast("handler", channelHandler);
}