Example usage for io.netty.channel ChannelPipeline toMap

List of usage examples for io.netty.channel ChannelPipeline toMap

Introduction

In this page you can find the example usage for io.netty.channel ChannelPipeline toMap.

Prototype

Map<String, ChannelHandler> toMap();

Source Link

Document

Converts this pipeline into an ordered Map whose keys are handler names and whose values are handlers.

Usage

From source file:com.linecorp.armeria.server.http.HttpServer.java

License:Apache License

static HttpServer get(Channel channel) {
    final ChannelPipeline p = channel.pipeline();
    final ChannelHandler lastHandler = p.last();
    if (lastHandler instanceof HttpServer) {
        return (HttpServer) lastHandler;
    }/* w  w  w .  jav a2s.c o  m*/

    for (ChannelHandler h : p.toMap().values()) {
        if (h instanceof HttpServer) {
            return (HttpServer) h;
        }
    }

    return null;
}

From source file:com.linecorp.armeria.server.HttpServer.java

License:Apache License

@Nullable
static HttpServer get(Channel channel) {
    final ChannelPipeline p = channel.pipeline();
    final ChannelHandler lastHandler = p.last();
    if (lastHandler instanceof HttpServer) {
        return (HttpServer) lastHandler;
    }/*from w w w .ja  v a  2s.  c  o m*/

    for (ChannelHandler h : p.toMap().values()) {
        if (h instanceof HttpServer) {
            return (HttpServer) h;
        }
    }

    return null;
}

From source file:org.jfxvnc.net.rfb.codec.ProtocolHandler.java

License:Apache License

@Override
protected void decode(final ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception {

    if (msg instanceof ImageRect) {
        render.render((ImageRect) msg, () -> {
            // logger.debug("render completed");
            // sendFramebufferUpdateRequest(ctx, true, 0, 0,
            // serverInit.getFrameBufferWidth(),
            // serverInit.getFrameBufferHeight());

        });/*from   www  .  j ava 2s  .  co  m*/
        return;
    }
    if (msg instanceof ServerDecoderEvent) {
        render.eventReceived((ServerDecoderEvent) msg);
        return;
    }

    if (!(msg instanceof ServerInitEvent)) {
        logger.error("unknown message: {}", msg);
        ctx.fireChannelRead(msg);
        return;
    }

    serverInit = (ServerInitEvent) msg;
    logger.debug("handshake completed with {}", serverInit);

    FrameDecoderHandler frameHandler = new FrameDecoderHandler(serverInit.getPixelFormat());
    if (!frameHandler.isPixelFormatSupported()) {
        ProtocolException e = new ProtocolException(String.format("pixelformat: (%s bpp) not supported yet",
                serverInit.getPixelFormat().getBitPerPixel()));
        exceptionCaught(ctx, e);
        return;
    }

    ChannelPipeline cp = ctx.pipeline();

    cp.addBefore(ctx.name(), "rfb-encoding-encoder", new PreferedEncodingEncoder());
    PreferedEncoding prefEncodings = getPreferedEncodings(frameHandler.getSupportedEncodings());
    ctx.write(prefEncodings);

    cp.addBefore(ctx.name(), "rfb-pixelformat-encoder", new PixelFormatEncoder());
    ctx.write(serverInit.getPixelFormat());
    ctx.flush();

    cp.addBefore(ctx.name(), "rfb-frame-handler", frameHandler);
    cp.addBefore(ctx.name(), "rfb-keyevent-encoder", new KeyButtonEventEncoder());
    cp.addBefore(ctx.name(), "rfb-pointerevent-encoder", new PointerEventEncoder());
    cp.addBefore(ctx.name(), "rfb-cuttext-encoder", new ClientCutTextEncoder());

    render.eventReceived(getConnectInfoEvent(ctx, prefEncodings));

    render.registerInputEventListener(event -> ctx.writeAndFlush(event, ctx.voidPromise()));

    logger.debug("request full framebuffer update");
    sendFramebufferUpdateRequest(ctx, false, 0, 0, serverInit.getFrameBufferWidth(),
            serverInit.getFrameBufferHeight());

    logger.trace("channel pipeline: {}", cp.toMap().keySet());
}