Example usage for io.netty.channel ChannelPipeline fireUserEventTriggered

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

Introduction

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

Prototype

@Override
    ChannelPipeline fireUserEventTriggered(Object event);

Source Link

Usage

From source file:com.linecorp.armeria.client.http.HttpClientPipelineConfigurator.java

License:Apache License

void finishSuccessfully(ChannelPipeline pipeline, SessionProtocol protocol) {

    if (protocol == H1 || protocol == H1C) {
        addBeforeSessionHandler(pipeline, new Http1ResponseDecoder(pipeline.channel()));
    }/*  ww w  . java 2 s  .  c  om*/

    final long idleTimeoutMillis = options.idleTimeoutMillis();
    if (idleTimeoutMillis > 0) {
        pipeline.addFirst(new HttpClientIdleTimeoutHandler(idleTimeoutMillis));
    }

    pipeline.channel().eventLoop().execute(() -> pipeline.fireUserEventTriggered(protocol));
}

From source file:com.linecorp.armeria.client.http.HttpClientPipelineConfigurator.java

License:Apache License

void finishWithNegotiationFailure(ChannelHandlerContext ctx, SessionProtocol expected, SessionProtocol actual,
        String reason) {//w  w w  . j  av  a 2s  . c  om

    final ChannelPipeline pipeline = ctx.pipeline();
    pipeline.channel().eventLoop().execute(() -> pipeline
            .fireUserEventTriggered(new SessionProtocolNegotiationException(expected, actual, reason)));
    ctx.close();
}

From source file:com.linecorp.armeria.client.HttpClientPipelineConfigurator.java

License:Apache License

void finishSuccessfully(ChannelPipeline pipeline, SessionProtocol protocol) {

    if (protocol == H1 || protocol == H1C) {
        addBeforeSessionHandler(pipeline, new Http1ResponseDecoder(pipeline.channel()));
    } else if (protocol == H2 || protocol == H2C) {
        final int initialWindow = clientFactory.initialHttp2ConnectionWindowSize();
        if (initialWindow > DEFAULT_WINDOW_SIZE) {
            incrementLocalWindowSize(pipeline, initialWindow - DEFAULT_WINDOW_SIZE);
        }/*from  w  w  w  .  ja  va  2s.  com*/
    }

    final long idleTimeoutMillis = clientFactory.idleTimeoutMillis();
    if (idleTimeoutMillis > 0) {
        pipeline.addFirst(new HttpClientIdleTimeoutHandler(idleTimeoutMillis));
    }

    pipeline.channel().eventLoop().execute(() -> pipeline.fireUserEventTriggered(protocol));
}

From source file:com.linecorp.armeria.client.HttpConfigurator.java

License:Apache License

void finishSuccessfully(ChannelPipeline pipeline, SessionProtocol protocol) {

    switch (protocol) {
    case H1:/*from  w  w  w  .  j a va  2 s  .  c  o  m*/
    case H1C:
        addBeforeSessionHandler(pipeline, new HttpObjectAggregator(options.maxFrameLength()));
        break;
    case H2:
    case H2C:
        // HTTP/2 does not require the aggregator because
        // InboundHttp2ToHttpAdapter always creates a FullHttpRequest.
        break;
    default:
        // Should never reach here.
        throw new Error();
    }

    final long idleTimeoutMillis = options.idleTimeoutMillis();
    if (idleTimeoutMillis > 0) {
        final HttpClientIdleTimeoutHandler timeoutHandler;
        if (protocol == H2 || protocol == H2C) {
            timeoutHandler = new Http2ClientIdleTimeoutHandler(idleTimeoutMillis);
        } else {
            // Note: We should not use Http2ClientIdleTimeoutHandler for HTTP/1 connections,
            //       because we cannot tell if the headers defined in ExtensionHeaderNames such as
            //       'x-http2-stream-id' have been set by us or a malicious server.
            timeoutHandler = new HttpClientIdleTimeoutHandler(idleTimeoutMillis);
        }
        addBeforeSessionHandler(pipeline, timeoutHandler);
    }

    pipeline.channel().eventLoop().execute(() -> pipeline.fireUserEventTriggered(protocol));
}

From source file:org.apache.hadoop.hbase.ipc.NettyRpcConnection.java

License:Apache License

private void established(Channel ch) throws IOException {
    ChannelPipeline p = ch.pipeline();
    String addBeforeHandler = p.context(BufferCallBeforeInitHandler.class).name();
    p.addBefore(addBeforeHandler, null,//w w  w. ja va2  s .  com
            new IdleStateHandler(0, rpcClient.minIdleTimeBeforeClose, 0, TimeUnit.MILLISECONDS));
    p.addBefore(addBeforeHandler, null, new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
    p.addBefore(addBeforeHandler, null,
            new NettyRpcDuplexHandler(this, rpcClient.cellBlockBuilder, codec, compressor));
    p.fireUserEventTriggered(BufferCallEvent.success());
}

From source file:org.fusesource.hawtdispatch.netty.HawtSocketChannel.java

License:Apache License

private void onReadReady() {
    final ChannelPipeline pipeline = pipeline();
    final ByteBuf byteBuf = pipeline.inboundByteBuffer();
    boolean closed = false;
    boolean read = false;
    boolean firedInboundBufferSuspended = false;
    try {//from  w w  w. ja v a 2s.co  m
        expandReadBuffer(byteBuf);
        loop: for (;;) {

            int localReadAmount = byteBuf.writeBytes(javaChannel(), byteBuf.writableBytes());
            if (localReadAmount > 0) {
                read = true;
            } else if (localReadAmount < 0) {
                closed = true;
                break;
            }

            switch (expandReadBuffer(byteBuf)) {
            case 0:
                // Read all - stop reading.
                break loop;
            case 1:
                // Keep reading until everything is read.
                break;
            case 2:
                // Let the inbound handler drain the buffer and continue reading.
                if (read) {
                    read = false;
                    pipeline.fireInboundBufferUpdated();
                    if (!byteBuf.isWritable()) {
                        throw new IllegalStateException(
                                "an inbound handler whose buffer is full must consume at " + "least one byte.");
                    }
                }
            }
        }
    } catch (Throwable t) {
        if (read) {
            read = false;
            pipeline.fireInboundBufferUpdated();
        }

        if (t instanceof IOException) {
            closed = true;
        } else if (!closed) {
            firedInboundBufferSuspended = true;
            pipeline.fireChannelReadSuspended();
        }
        pipeline().fireExceptionCaught(t);
    } finally {
        if (read) {
            pipeline.fireInboundBufferUpdated();
        }

        if (closed) {
            setInputShutdown();
            if (isOpen()) {
                if (Boolean.TRUE.equals(config().getOption(ChannelOption.ALLOW_HALF_CLOSURE))) {
                    pipeline.fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE);
                } else {
                    close(newPromise());
                }
            }
        } else if (!firedInboundBufferSuspended) {
            pipeline.fireChannelReadSuspended();
        }

        if (!config().isAutoRead()) {
            readSource.suspend();
        }
    }
}

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

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

    if (msg instanceof ProtocolVersion) {
        handleServerVersion(ctx, (ProtocolVersion) msg);
        return;//from  ww w .  j  a va  2  s.  c o m
    }
    if (msg instanceof SecurityTypesEvent) {
        handleSecurityTypes(ctx, (SecurityTypesEvent) msg);
        return;
    }

    if (msg instanceof RfbSecurityMessage) {
        handleSecurityMessage(ctx, (RfbSecurityMessage) msg);
        return;
    }

    if (msg instanceof SecurityResultEvent) {
        handleSecurityResult(ctx, (SecurityResultEvent) msg);
        return;
    }

    if (msg instanceof ServerInitEvent) {
        handshaker.finishHandshake(ctx.channel(), config.versionProperty().get());
        ChannelPipeline cp = ctx.pipeline();
        cp.fireUserEventTriggered(ProtocolState.HANDSHAKE_COMPLETE);
        cp.remove(this);
        cp.fireChannelRead(msg);
        return;
    }

    throw new ProtocolException("unknown message occurred: " + msg);

}