Package io.netty.channel

Examples of io.netty.channel.ChannelHandlerContext


            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);
View Full Code Here


     */
    public void pushConfig(String projCode, String profile, final String config) {
      List<ClientInfo> addrs = clients.get(projCode + "$$" + profile);
      if(addrs != null) {
        for(ClientInfo client : addrs) {
          ChannelHandlerContext ctx = channels.get(client.getAddress());
          if(ctx != null) {
            sendMessage(ctx, config);
          }
        }
      }
View Full Code Here

     *
     * @return a {@link ChannelPromise} which is notified when the handshake
     *         succeeds or fails.
     */
    public ChannelFuture handshake(final ChannelPromise promise) {
        final ChannelHandlerContext ctx = this.ctx;

        final ScheduledFuture<?> timeoutFuture;
        if (handshakeTimeoutMillis > 0) {
            timeoutFuture = ctx.executor().schedule(new Runnable() {
                @Override
                public void run() {
                    if (promise.isDone()) {
                        return;
                    }

                    SSLException e = new SSLException("handshake timed out");
                    if (promise.tryFailure(e)) {
                        ctx.fireExceptionCaught(e);
                        ctx.close();
                    }
                }
            }, handshakeTimeoutMillis, TimeUnit.MILLISECONDS);
        } else {
            timeoutFuture = null;
        }

        ctx.executor().execute(new Runnable() {
            @Override
            public void run() {
                try {
                    if (timeoutFuture != null) {
                        timeoutFuture.cancel(false);
                    }
                    engine.beginHandshake();
                    handshakePromises.add(promise);
                    flush0(ctx, ctx.newPromise(), true);
                } catch (Exception e) {
                    if (promise.tryFailure(e)) {
                        ctx.fireExceptionCaught(e);
                        ctx.close();
                    }
                }
            }
        });

View Full Code Here

    /**
     * See {@link #close()}

     */
    public ChannelFuture close(final ChannelPromise future) {
        final ChannelHandlerContext ctx = this.ctx;
        ctx.executor().execute(new Runnable() {
            @Override
            public void run() {
                engine.closeOutbound();
                future.addListener(closeNotifyWriteListener);
                try {
View Full Code Here

        channel.write(request).addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) {
                if (future.isSuccess()) {
                    ChannelPipeline p = future.channel().pipeline();
                    ChannelHandlerContext ctx = p.context(HttpRequestEncoder.class);
                    if (ctx == null) {
                        ctx = p.context(HttpClientCodec.class);
                    }
                    if (ctx == null) {
                        promise.setFailure(new IllegalStateException("ChannelPipeline does not contain " +
                                "a HttpRequestEncoder or HttpClientCodec"));
                        return;
                    }
                    p.addAfter(ctx.name(), "ws-encoder", newWebSocketEncoder());

                    promise.setSuccess();
                } else {
                    promise.setFailure(future.cause());
                }
View Full Code Here

        verify(response);
        setActualSubprotocol(response.headers().get(HttpHeaders.Names.SEC_WEBSOCKET_PROTOCOL));
        setHandshakeComplete();

        ChannelPipeline p = channel.pipeline();
        ChannelHandlerContext ctx = p.context(HttpResponseDecoder.class);
        if (ctx == null) {
            ctx = p.context(HttpClientCodec.class);
            if (ctx == null) {
                throw new IllegalStateException("ChannelPipeline does not contain " +
                        "a HttpRequestEncoder or HttpClientCodec");
            }
            p.replaceAndForward(ctx.name(), "ws-decoder", newWebsocketDecoder());
        } else {
            if (p.get(HttpRequestEncoder.class) != null) {
                p.remove(HttpRequestEncoder.class);
            }
            p.replaceAndForward(ctx.name(),
                    "ws-decoder", newWebsocketDecoder());
        }
    }
View Full Code Here

                if (future.isSuccess()) {
                    ChannelPipeline p = future.channel().pipeline();
                    if (p.get(HttpObjectAggregator.class) != null) {
                        p.remove(HttpObjectAggregator.class);
                    }
                    ChannelHandlerContext ctx = p.context(HttpRequestDecoder.class);
                    if (ctx == null) {
                        // this means the user use a HttpServerCodec
                        ctx = p.context(HttpServerCodec.class);
                        if (ctx == null) {
                            promise.setFailure(
                                    new IllegalStateException("No HttpDecoder and no HttpServerCodec in the pipeline"));
                            return;
                        }
                        p.addBefore(ctx.name(), "wsencoder", newWebsocketDecoder());
                        p.replaceAndForward(ctx.name(), "wsdecoder", newWebSocketEncoder());
                    } else {
                        p.replaceAndForward(ctx.name(), "wsdecoder", newWebsocketDecoder());

                        p.replace(HttpResponseEncoder.class, "wsencoder", newWebSocketEncoder());
                    }
                    promise.setSuccess();
                } else {
View Full Code Here

    /**
     * Continues to fetch the chunks from the input.
     */
    public void resumeTransfer() {
        final ChannelHandlerContext ctx = this.ctx;
        if (ctx == null) {
            return;
        }
        if (ctx.executor().inEventLoop()) {
            try {
                doFlush(ctx);
            } catch (Exception e) {
                if (logger.isWarnEnabled()) {
                    logger.warn("Unexpected exception while sending chunks.", e);
                }
            }
        } else {
            // let the transfer resume on the next event loop round
            ctx.executor().execute(new Runnable() {

                @Override
                public void run() {
                    try {
                        doFlush(ctx);
View Full Code Here

    public ChannelFuture close(ChannelPromise promise) {
        return finishEncode(ctx(), promise);
    }

    private ChannelHandlerContext ctx() {
        ChannelHandlerContext ctx = this.ctx;
        if (ctx == null) {
            throw new IllegalStateException("not added to a pipeline");
        }
        return ctx;
    }
View Full Code Here

        for (ChannelHandler h: handlers) {
            if (h == null) {
                break;
            }
            nHandlers ++;
            ChannelHandlerContext ctx = p.addLast(h).context(h);

            if (ctx.hasInboundByteBuffer() || ctx.hasOutboundByteBuffer()
                    || ctx.hasInboundMessageBuffer() || ctx.hasOutboundMessageBuffer()) {
                hasBuffer = true;
            }
        }

        if (nHandlers == 0) {
View Full Code Here

TOP

Related Classes of io.netty.channel.ChannelHandlerContext

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.