Java Code Examples for io.netty.channel.Channel.pipeline()

The following are Jave code examples for showing how to use pipeline() of the io.netty.channel.Channel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: fresco_floodlight   File: RPCChannelInitializer.java   Source Code and License Vote up 7 votes
@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);
}
 
Example 2
Project: simulacron   File: Server.java   Source Code and License Vote up 6 votes
@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");
  }
}
 
Example 3
Project: ZentrelaRPG   File: TinyProtocol.java   Source Code and License Vote up 6 votes
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
                }
            }

        });
    }
}
 
Example 4
Project: SamaGamesAPI   File: TinyProtocol.java   Source Code and License Vote up 6 votes
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
                }
            }

        });
    }
}
 
Example 5
Project: aws-sdk-java-v2   File: ChannelPipelineInitializer.java   Source Code and License Vote up 6 votes
@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);
}
 
Example 6
Project: fastdfs-spring-boot   File: FastdfsPool.java   Source Code and License Vote up 5 votes
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());
}
 
Example 7
Project: util4j   File: WebSocketClientInitializer.java   Source Code and License Vote up 5 votes
/**
 * 通道注册的时候配置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
}
 
Example 8
Project: util4j   File: WebSocketServerInitializer.java   Source Code and License Vote up 5 votes
@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
}
 
Example 9
Project: push-server   File: NettyClientInitializer.java   Source Code and License Vote up 5 votes
@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());
}
 
Example 10
Project: push-server   File: NettyServerInitializer.java   Source Code and License Vote up 5 votes
@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());
}
 
Example 11
Project: azeroth   File: FastdfsPool.java   Source Code and License Vote up 5 votes
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());
}
 
Example 12
Project: kcp-netty   File: Utils.java   Source Code and License Vote up 5 votes
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();
}
 
Example 13
Project: fresco_floodlight   File: OFChannelInitializer.java   Source Code and License Vote up 5 votes
@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);
}
 
Example 14
Project: UnknownPandaServer   File: ConnectionInitializer.java   Source Code and License Vote up 5 votes
@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);
    }
}
 
Example 15
Project: fresco_floodlight   File: BootstrapChannelInitializer.java   Source Code and License Vote up 3 votes
@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);
}
 
Example 16
Project: fresco_floodlight   File: RemoteSyncChannelInitializer.java   Source Code and License Vote up 3 votes
@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);
}