Java源码示例:org.jboss.netty.handler.codec.frame.Delimiters

示例1
public ChannelPipeline getPipeline() {
    
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("idleTimer",idleStateHandler);
    pipeline.addLast("idleHandler",myIdleHandler);
    pipeline.addLast("framer", new DelimiterBasedFrameDecoder(
            1024, Delimiters.lineDelimiter()));
    pipeline.addLast("stringDecoder", TcpMeta.stringDecoder);
    pipeline.addLast("stringEncoder", TcpMeta.stringEncoder);
    pipeline.addLast("handler",
            new TcpChannelHandler(tcpWorker));

    return pipeline;
}
 
示例2
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = pipeline();
    pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    pipeline.addLast("decoder", new StringDecoder());
    pipeline.addLast("encoder", new StringEncoder());
    pipeline.addLast("handler", new NettyTCPWriterHandler(this.bootstrap, this.channel, this.timer));
    return pipeline;
}
 
示例3
public ChannelPipeline getPipeline() throws Exception {
    // this is pretty verbose from the netty examples
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    pipeline.addLast("decoder", new StringDecoder());
    pipeline.addLast("encoder", new StringEncoder());
    pipeline.addLast("handler", new FakeCarbonHandler(appConfig));
    return pipeline;
}
 
示例4
public void request() throws Exception {
    
    // Parse options.
    String host = "localhost";
    int port = 10081;
    int connectTimeoutMillis = 2000;
    // Configure the client.
    ClientBootstrap bootstrap = new ClientBootstrap(
            new NioClientSocketChannelFactory(
                    Executors.newCachedThreadPool(),
                    Executors.newCachedThreadPool()));

    final TelnetClientHandler handler = new TelnetClientHandler();

    // Configure the pipeline factory.
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        public ChannelPipeline getPipeline() {
            ChannelPipeline pipeline = Channels.pipeline();
            pipeline.addLast("framer", new DelimiterBasedFrameDecoder(1024,
                    Delimiters.lineDelimiter()));
            pipeline.addLast("stringDecoder", stringDecoder);
            pipeline.addLast("stringEncoder", stringEncoder);
            pipeline.addLast("handler", handler);
            return pipeline;
        }
    });
    
    
    bootstrap.setOption("connectTimeoutMillis",connectTimeoutMillis);
    bootstrap.setOption("tcpNoDelay", true);
    bootstrap.setOption("keepAlive", true);
    // Start the connection attempt.
    ChannelFuture future = bootstrap.connect(new InetSocketAddress(host,
            port));

    // Wait until the connection attempt succeeds or fails.
    Channel channel = future.awaitUninterruptibly().getChannel();
    // Read commands from the stdin.
    ChannelFuture lastWriteFuture = null;
    String command = "hadoopMonitorFromClient";

    // Sends the line to server.
    lastWriteFuture = channel.write(command + "\r\n");

    // Wait until all messages are flushed before closing the channel.
    if (lastWriteFuture != null) {
        lastWriteFuture.await();
    }

    // note that we need to wait for the response before

    // wait time before close the channel too early that msg will not be
    // received.

    while (!handler.channelCompleted) {
        Thread.sleep(1l);
    }

    // Close the connection. Make sure the close operation ends because
    // all I/O operations are asynchronous in Netty.
    channel.close().awaitUninterruptibly();
    // Shut down all thread pools to exit.
    bootstrap.releaseExternalResources();
    
}