Package io.netty.channel

Examples of io.netty.channel.ChannelPipeline


        }

        @Override
        void epollInReady() {
            final ChannelConfig config = config();
            final ChannelPipeline pipeline = pipeline();
            final ByteBufAllocator allocator = config.getAllocator();
            RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();

            ByteBuf byteBuf = null;
            boolean close = false;
            try {
                int totalReadAmount = 0;
                for (;;) {
                    // we use a direct buffer here as the native implementations only be able
                    // to handle direct buffers.
                    byteBuf = allocHandle.allocate(allocator);
                    int writable = byteBuf.writableBytes();
                    int localReadAmount = doReadBytes(byteBuf);
                    if (localReadAmount <= 0) {
                        // not was read release the buffer
                        byteBuf.release();
                        close = localReadAmount < 0;
                        break;
                    }
                    readPending = false;
                    pipeline.fireChannelRead(byteBuf);
                    byteBuf = null;

                    if (totalReadAmount >= Integer.MAX_VALUE - localReadAmount) {
                        allocHandle.record(totalReadAmount);

                        // Avoid overflow.
                        totalReadAmount = localReadAmount;
                    } else {
                        totalReadAmount += localReadAmount;
                    }

                    if (localReadAmount < writable) {
                        // Read less than what the buffer can hold,
                        // which might mean we drained the recv buffer completely.
                        break;
                    }
                }
                pipeline.fireChannelReadComplete();
                allocHandle.record(totalReadAmount);

                if (close) {
                    closeOnRead(pipeline);
                    close = false;
View Full Code Here


             * Since SSE is an endless stream, we can never reuse a connection and hence as soon as SSE traffic is
             * received, the connection is marked as discardable on close.
             */
            ctx.channel().attr(ClientRequestResponseConverter.DISCARD_CONNECTION).set(true); // SSE traffic should always discard connection on close.

            ChannelPipeline pipeline = ctx.channel().pipeline();
            if (!HttpHeaders.isTransferEncodingChunked((HttpResponse) msg)) {
                pipeline.addFirst(SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder());
                /*
                 * If there are buffered messages in the previous handler at the time this message is read, we would
                 * not be able to convert the content into an SseEvent. For this reason, we also add the decoder after
                 * this handler, so that we can handle the buffered messages.
                 * See the class level javadoc for more details.
                 */
                pipeline.addAfter(NAME, SSE_DECODER_POST_INBOUND_HANDLER, new ServerSentEventDecoder());
            } else {
                pipeline.addAfter(NAME, SSE_DECODER_HANDLER_NAME, new ServerSentEventDecoder());
            }
            ctx.fireChannelRead(msg);
        } else if (msg instanceof LastHttpContent) {
            LastHttpContent lastHttpContent = (LastHttpContent) msg;

View Full Code Here

                        eventsSubject.onEvent(ClientMetricsEvent.CONNECT_FAILED, Clock.onEndMillis(startTimeMillis),
                                              future.cause());
                        subscriber.onError(future.cause());
                    } else {
                        eventsSubject.onEvent(ClientMetricsEvent.CONNECT_SUCCESS, Clock.onEndMillis(startTimeMillis));
                        ChannelPipeline pipeline = future.channel().pipeline();
                        final ObservableConnection<I, O> newConnection = connectionFactory.newConnection(future.channel());
                        ChannelHandler lifecycleHandler = pipeline.get(RxRequiredConfigurator.CONN_LIFECYCLE_HANDLER_NAME);
                        if (null == lifecycleHandler) {
                            onNewConnection(newConnection, subscriber);
                        } else {
                            @SuppressWarnings("unchecked")
                            ConnectionLifecycleHandler<I, O> handler = (ConnectionLifecycleHandler<I, O>) lifecycleHandler;
                            SslHandler sslHandler = pipeline.get(SslHandler.class);
                            if (null == sslHandler) {
                                handler.setConnection(newConnection);
                                onNewConnection(newConnection, subscriber);
                            } else {
                                sslHandler.handshakeFuture().addListener(new GenericFutureListener<Future<? super Channel>>() {
View Full Code Here

     * Shutdown this client and close all open connections. The client should be
     * discarded after calling shutdown.
     */
    public void shutdown() {
        for (Channel c : channels) {
            ChannelPipeline pipeline = c.pipeline();
            RedisAsyncConnection<?, ?> connection = pipeline.get(RedisAsyncConnection.class);
            connection.close();
        }
        ChannelGroupFuture future = channels.close();
        future.awaitUninterruptibly();
    }
View Full Code Here

            this.originalHandler = originalHandler;
        }

        @Override
        public Observable<Void> handle(final ObservableConnection<I, O> connection) {
            final ChannelPipeline p = connection.getChannel().pipeline();
            ChannelHandlerContext hctx = p.context(WebSocketServerHandler.class);
            if (hctx != null) {
                WebSocketServerHandler handler = p.get(WebSocketServerHandler.class);
                final PublishSubject<Void> subject = PublishSubject.create();
                handler.addHandshakeFinishedListener(new ChannelFutureListener() {
                    @Override
                    public void operationComplete(ChannelFuture future) throws Exception {
                        originalHandler.handle(connection).subscribe(subject);
View Full Code Here

                    originalSubscriber.onError(e);
                }

                @Override
                public void onNext(final ObservableConnection<T, T> connection) {
                    final ChannelPipeline p = connection.getChannel().pipeline();
                    ChannelHandlerContext hctx = p.context(WebSocketClientHandler.class);
                    if (hctx != null) {
                        WebSocketClientHandler handler = p.get(WebSocketClientHandler.class);
                        handler.addHandshakeFinishedListener(new ChannelFutureListener() {
                            @Override
                            public void operationComplete(ChannelFuture future) throws Exception {
                                originalSubscriber.onNext(connection);
                                originalSubscriber.onCompleted();
View Full Code Here

        ctx.fireChannelActive();
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        ChannelPipeline pipeLine = channel.pipeline();
        CommandHandler<?, ?> handler = pipeLine.get(CommandHandler.class);
        RedisAsyncConnection<?, ?> connection = pipeLine.get(RedisAsyncConnection.class);
        if (connection.isReconnect()) {
            EventLoop loop = ctx.channel().eventLoop();
            reconnect(loop, handler, connection);
        }
        ctx.fireChannelInactive();
View Full Code Here

            ctx.fireChannelRead(msg);
        }
    }

    private void updatePipeline(ChannelHandlerContext ctx) {
        ChannelPipeline p = ctx.pipeline();
        ChannelHandlerContext nettyEncoderCtx = p.context(WebSocketFrameEncoder.class);
        p.addAfter(nettyEncoderCtx.name(), "websocket-write-metrics", new ServerWriteMetricsHandler(eventsSubject));
        ChannelHandlerContext nettyDecoderCtx = p.context(WebSocketFrameDecoder.class);
        p.addAfter(nettyDecoderCtx.name(), "websocket-read-metrics", new ServerReadMetricsHandler(eventsSubject));
        if (messageAggregator) {
            p.addAfter("websocket-read-metrics", "websocket-frame-aggregator", new WebSocketFrameAggregator(maxFramePayloadLength));
        }
        p.remove(this);
    }
View Full Code Here

            ctx.close();
            return;
        }
        eventsSubject.onEvent(WebSocketClientMetricsEvent.HANDSHAKE_SUCCESS, Clock.onEndMillis(handshakeStartTime));

        ChannelPipeline p = ctx.pipeline();
        ChannelHandlerContext nettyDecoderCtx = p.context(WebSocketFrameDecoder.class);
        p.addAfter(nettyDecoderCtx.name(), "websocket-read-metrics", new ClientReadMetricsHandler(eventsSubject));
        ChannelHandlerContext nettyEncoderCtx = p.context(WebSocketFrameEncoder.class);
        p.addAfter(nettyEncoderCtx.name(), "websocket-write-metrics", new ClientWriteMetricsHandler(eventsSubject));
        if (messageAggregation) {
            p.addAfter("websocket-read-metrics", "websocket-frame-aggregator", new WebSocketFrameAggregator(maxFramePayloadLength));
        }
        p.remove(HttpObjectAggregator.class);
        p.remove(this);

        handshakeFuture.setSuccess();
    }
View Full Code Here

      }

      @Override
      public void initChannel(Channel channel) throws Exception {
         // Create a default pipeline implementation.
         ChannelPipeline pipeline = channel.pipeline();

         pipeline.addLast("decoder", new HttpRequestDecoder());
         pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
         pipeline.addLast("encoder", new HttpResponseEncoder());
         pipeline.addLast("handler", new WebSocketServerHandler(cacheContainer, operationHandlers, startedCaches));
      }
View Full Code Here

TOP

Related Classes of io.netty.channel.ChannelPipeline

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.