Example usage for io.netty.handler.codec.memcache.binary BinaryMemcacheClientCodec BinaryMemcacheClientCodec

List of usage examples for io.netty.handler.codec.memcache.binary BinaryMemcacheClientCodec BinaryMemcacheClientCodec

Introduction

In this page you can find the example usage for io.netty.handler.codec.memcache.binary BinaryMemcacheClientCodec BinaryMemcacheClientCodec.

Prototype

public BinaryMemcacheClientCodec() 

Source Link

Document

Create a new BinaryMemcacheClientCodec with the default settings applied.

Usage

From source file:com.couchbase.client.core.endpoint.binary.BinaryEndpoint.java

License:Open Source License

@Override
protected void customEndpointHandlers(final ChannelPipeline pipeline) {
    pipeline.addLast(new BinaryMemcacheClientCodec())
            .addLast(new BinaryMemcacheObjectAggregator(Integer.MAX_VALUE))
            .addLast(new BinarySaslClient(bucket(), password(), this)).addLast(new BinaryCodec());
}

From source file:com.couchbase.client.core.io.endpoint.memcache.MemcacheEndpoint.java

License:Open Source License

@Override
protected void customEndpointHandlers(final ChannelPipeline pipeline) {
    pipeline.addLast(new BinaryMemcacheClientCodec())
            .addLast(new BinaryMemcacheObjectAggregator(Integer.MAX_VALUE)).addLast(new MemcacheCodec());
}

From source file:com.flysoloing.learning.network.netty.binary.MemcacheClient.java

License:Apache License

public static void main(String[] args) throws Exception {
    // Configure SSL.
    final SslContext sslCtx;
    if (SSL) {/*from   w w  w. j  a v a 2 s.  c  om*/
        sslCtx = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
    } else {
        sslCtx = null;
    }

    EventLoopGroup group = new NioEventLoopGroup();
    try {
        Bootstrap b = new Bootstrap();
        b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
            @Override
            protected void initChannel(SocketChannel ch) throws Exception {
                ChannelPipeline p = ch.pipeline();
                if (sslCtx != null) {
                    p.addLast(sslCtx.newHandler(ch.alloc(), HOST, PORT));
                }
                p.addLast(new BinaryMemcacheClientCodec());
                p.addLast(new BinaryMemcacheObjectAggregator(Integer.MAX_VALUE));
                p.addLast(new MemcacheClientHandler());
            }
        });

        // Start the connection attempt.
        Channel ch = b.connect(HOST, PORT).sync().channel();

        // Read commands from the stdin.
        System.out.println("Enter commands (quit to end)");
        System.out.println("get <key>");
        System.out.println("set <key> <value>");
        ChannelFuture lastWriteFuture = null;
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        for (;;) {
            String line = in.readLine();
            if (line == null) {
                break;
            }
            if ("quit".equals(line.toLowerCase())) {
                ch.close().sync();
                break;
            }
            // Sends the received line to the server.
            lastWriteFuture = ch.writeAndFlush(line);
        }

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