Search in sources :

Example 1 with PreciseFrameDecoder

use of com.baidu.hugegraph.computer.core.network.netty.codec.PreciseFrameDecoder in project hugegraph-computer by hugegraph.

the class NettyProtocol method initializeServerPipeline.

/**
 * Initialize the server channel handlers.
 *
 * <pre>
 *     +----------------------+
 *     | File / Local Buffer  |
 *     +-----------+----------+
 *                /|\ (2) zero-copy
 * +---------------+---------------------------------------------------+
 * |               |        SERVER CHANNEL PIPELINE                    |
 * |               |                                                   |
 * |    +----------+----------+ (3)write ack +----------------------+  |
 * |    | ServerHandler       |------------->| MessageEncoder       |  |
 * |    +----------+----------+              +-----------+----------+  |
 * |              /|\                                 \|/              |
 * |               |                                   |               |
 * |    +----------+----------+                        |               |
 * |    | MessageDecoder      |                        |               |
 * |    +----------+----------+                        |               |
 * |              /|\                                  |               |
 * |               |                                   |               |
 * |   +-----------+-----------+                       |               |
 * |   | PreciseFrameDecoder   |                       |               |
 * |   +-----------+-----------+                       |               |
 * |              /|\                                  |               |
 * +---------------+-----------------------------------+---------------+
 * |               | (1) read request                 \|/              |
 * +---------------+-----------------------------------+---------------+
 * |               |                                   |               |
 * |       [ Socket.read() ]                    [ Socket.write() ]     |
 * |                                                                   |
 * |  Netty Internal I/O Threads (Transport Implementation)            |
 * +-------------------------------------------------------------------+
 * </pre>
 */
protected void initializeServerPipeline(Channel channel, MessageHandler handler) {
    ChannelPipeline pipeline = channel.pipeline();
    pipeline.addLast("encoder", MessageEncoder.INSTANCE);
    if (this.conf.recvBufferFileMode()) {
        pipeline.addLast("frameDecoder", new PreciseFrameDecoder());
        pipeline.addLast("decoder", MessageDecoder.INSTANCE_FILE_REGION);
    } else {
        pipeline.addLast("frameDecoder", new FrameDecoder());
        pipeline.addLast("decoder", MessageDecoder.INSTANCE_MEMORY_BUFFER);
    }
    pipeline.addLast("serverIdleStateHandler", this.newServerIdleStateHandler());
    // NOTE: The heartbeatHandler can reuse of a server
    pipeline.addLast("serverIdleHandler", SERVER_IDLE_HANDLER);
    pipeline.addLast(SERVER_HANDLER_NAME, this.newNettyServerHandler(handler));
}
Also used : PreciseFrameDecoder(com.baidu.hugegraph.computer.core.network.netty.codec.PreciseFrameDecoder) PreciseFrameDecoder(com.baidu.hugegraph.computer.core.network.netty.codec.PreciseFrameDecoder) FrameDecoder(com.baidu.hugegraph.computer.core.network.netty.codec.FrameDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline)

Aggregations

FrameDecoder (com.baidu.hugegraph.computer.core.network.netty.codec.FrameDecoder)1 PreciseFrameDecoder (com.baidu.hugegraph.computer.core.network.netty.codec.PreciseFrameDecoder)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1