Example usage for io.netty.channel ChannelPipeline remove

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

Introduction

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

Prototype

<T extends ChannelHandler> T remove(Class<T> handlerType);

Source Link

Document

Removes the ChannelHandler of the specified type from this pipeline.

Usage

From source file:org.apache.tinkerpop.gremlin.server.channel.HttpChannelizer.java

License:Apache License

@Override
public void finalize(final ChannelPipeline pipeline) {
    pipeline.remove(PIPELINE_OP_SELECTOR);
    pipeline.remove(PIPELINE_RESULT_ITERATOR_HANDLER);
    pipeline.remove(PIPELINE_OP_EXECUTOR);
}

From source file:org.apache.tinkerpop.gremlin.server.handler.WsAndHttpChannelizerHandler.java

License:Apache License

@Override
public void channelRead(final ChannelHandlerContext ctx, final Object obj) {
    final ChannelPipeline pipeline = ctx.pipeline();
    if (obj instanceof HttpMessage && !WebSocketHandlerUtil.isWebSocket((HttpMessage) obj)) {
        if (null != pipeline.get(PIPELINE_AUTHENTICATOR)) {
            pipeline.remove(PIPELINE_REQUEST_HANDLER);
            final ChannelHandler authenticator = pipeline.get(PIPELINE_AUTHENTICATOR);
            pipeline.remove(PIPELINE_AUTHENTICATOR);
            pipeline.addAfter(PIPELINE_HTTP_RESPONSE_ENCODER, PIPELINE_AUTHENTICATOR, authenticator);
            pipeline.addAfter(PIPELINE_AUTHENTICATOR, PIPELINE_REQUEST_HANDLER,
                    this.httpGremlinEndpointHandler);
        } else {//from ww  w .  ja v a  2  s .  c  om
            pipeline.remove(PIPELINE_REQUEST_HANDLER);
            pipeline.addAfter(PIPELINE_HTTP_RESPONSE_ENCODER, PIPELINE_REQUEST_HANDLER,
                    this.httpGremlinEndpointHandler);
        }
    }
    ctx.fireChannelRead(obj);
}

From source file:org.asynchttpclient.netty.channel.ChannelManager.java

License:Open Source License

public void upgradeProtocol(ChannelPipeline pipeline, Uri requestUri) throws SSLException {
    if (pipeline.get(HTTP_CLIENT_CODEC) != null)
        pipeline.remove(HTTP_CLIENT_CODEC);

    if (requestUri.isSecured())
        if (isSslHandlerConfigured(pipeline)) {
            pipeline.addAfter(SSL_HANDLER, HTTP_CLIENT_CODEC, newHttpClientCodec());
        } else {/*from  w  w  w  .j  av  a2s .c o  m*/
            pipeline.addAfter(PINNED_ENTRY, HTTP_CLIENT_CODEC, newHttpClientCodec());
            pipeline.addAfter(PINNED_ENTRY, SSL_HANDLER,
                    createSslHandler(requestUri.getHost(), requestUri.getExplicitPort()));
        }

    else
        pipeline.addAfter(PINNED_ENTRY, HTTP_CLIENT_CODEC, newHttpClientCodec());

    if (requestUri.isWebSocket()) {
        pipeline.addAfter(AHC_HTTP_HANDLER, AHC_WS_HANDLER, wsHandler);
        pipeline.remove(AHC_HTTP_HANDLER);
    }
}

From source file:org.asynchttpclient.netty.channel.ChannelManager.java

License:Open Source License

public void upgradePipelineForWebSockets(ChannelPipeline pipeline) {
    pipeline.addAfter(HTTP_CLIENT_CODEC, WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true));
    pipeline.addBefore(AHC_WS_HANDLER, WS_DECODER_HANDLER,
            new WebSocket08FrameDecoder(false, false, config.getWebSocketMaxFrameSize()));
    pipeline.addAfter(WS_DECODER_HANDLER, WS_FRAME_AGGREGATOR,
            new WebSocketFrameAggregator(config.getWebSocketMaxBufferSize()));
    pipeline.remove(HTTP_CLIENT_CODEC);
}

From source file:org.asynchttpclient.providers.netty.channel.ChannelManager.java

License:Open Source License

public void upgradeProtocol(ChannelPipeline pipeline, String scheme, String host, int port)
        throws IOException, GeneralSecurityException {
    if (pipeline.get(HTTP_HANDLER) != null)
        pipeline.remove(HTTP_HANDLER);

    if (isSecure(scheme))
        if (isSslHandlerConfigured(pipeline)) {
            pipeline.addAfter(SSL_HANDLER, HTTP_HANDLER, newHttpClientCodec());
        } else {/*  w w w  .  j  a  v  a 2s  .c o  m*/
            pipeline.addFirst(HTTP_HANDLER, newHttpClientCodec());
            pipeline.addFirst(SSL_HANDLER, createSslHandler(host, port));
        }

    else
        pipeline.addFirst(HTTP_HANDLER, newHttpClientCodec());

    if (isWebSocket(scheme)) {
        pipeline.addAfter(HTTP_PROCESSOR, WS_PROCESSOR, wsProcessor);
        pipeline.remove(HTTP_PROCESSOR);
    }
}

From source file:org.asynchttpclient.providers.netty.channel.ChannelManager.java

License:Open Source License

/**
 * Always make sure the channel who got cached support the proper protocol.
 * It could only occurs when a HttpMethod. CONNECT is used against a proxy
 * that requires upgrading from http to https.
 *///from  w  ww  . j av a  2 s .c om
public void verifyChannelPipeline(ChannelPipeline pipeline, String scheme)
        throws IOException, GeneralSecurityException {

    boolean sslHandlerConfigured = isSslHandlerConfigured(pipeline);

    if (isSecure(scheme)) {
        if (!sslHandlerConfigured)
            pipeline.addFirst(SSL_HANDLER, new SslInitializer(this));

    } else if (sslHandlerConfigured)
        pipeline.remove(SSL_HANDLER);
}

From source file:org.asynchttpclient.providers.netty.channel.ChannelManager.java

License:Open Source License

public void upgradePipelineForWebSockets(ChannelPipeline pipeline) {
    pipeline.addAfter(HTTP_HANDLER, WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true));
    pipeline.remove(HTTP_HANDLER);
    pipeline.addBefore(WS_PROCESSOR, WS_DECODER_HANDLER,
            new WebSocket08FrameDecoder(false, false, nettyConfig.getWebSocketMaxFrameSize()));
    pipeline.addAfter(WS_DECODER_HANDLER, WS_FRAME_AGGREGATOR,
            new WebSocketFrameAggregator(nettyConfig.getWebSocketMaxBufferSize()));
}

From source file:org.asynchttpclient.providers.netty.channel.Channels.java

License:Apache License

/**
 * Always make sure the channel who got cached support the proper protocol. It could only occurs when a HttpMethod.
 * CONNECT is used against a proxy that requires upgrading from http to https.
 *//*from  w w w  .  j  av a  2 s.  co  m*/
public void verifyChannelPipeline(ChannelPipeline pipeline, String scheme)
        throws IOException, GeneralSecurityException {

    boolean isSecure = isSecure(scheme);
    if (pipeline.get(SSL_HANDLER) != null) {
        if (!isSecure)
            pipeline.remove(SSL_HANDLER);

    } else if (isSecure)
        pipeline.addFirst(SSL_HANDLER, new SslInitializer(Channels.this));
}

From source file:org.asynchttpclient.providers.netty.channel.Channels.java

License:Apache License

public void upgradeProtocol(ChannelPipeline p, String scheme, String host, int port)
        throws IOException, GeneralSecurityException {
    if (p.get(HTTP_HANDLER) != null) {
        p.remove(HTTP_HANDLER);
    }/*from  ww w.  j  av a2s .c om*/

    if (isSecure(scheme)) {
        if (p.get(SSL_HANDLER) == null) {
            p.addFirst(HTTP_HANDLER, newHttpClientCodec());
            p.addFirst(SSL_HANDLER, createSslHandler(host, port));
        } else {
            p.addAfter(SSL_HANDLER, HTTP_HANDLER, newHttpClientCodec());
        }

    } else {
        p.addFirst(HTTP_HANDLER, newHttpClientCodec());
    }

    if (isWebSocket(scheme)) {
        p.replace(HTTP_PROCESSOR, WS_PROCESSOR, wsProcessor);
    }
}

From source file:org.hawkular.metrics.clients.ptrans.DemuxHandler.java

License:Apache License

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, @SuppressWarnings("rawtypes") List out)
        throws Exception {

    if (msg.readableBytes() < 5) {
        msg.clear();//from w  ww .j  a v  a2s.com
        ctx.close();
        return;
    }
    ChannelPipeline pipeline = ctx.pipeline();

    String data = msg.toString(CharsetUtil.UTF_8);
    if (logger.isDebugEnabled()) {
        logger.debug("Incoming: [" + data + "]");
    }

    boolean done = false;

    if (data.contains("type=metric")) {
        pipeline.addLast(new SyslogEventDecoder());
        pipeline.addLast("forwarder", new RestForwardingHandler(configuration));
        pipeline.remove(this);
        done = true;
    } else if (!data.contains("=")) {
        String[] items = data.split(" |\\n");
        if (items.length % 3 == 0) {
            pipeline.addLast("encoder", new GraphiteEventDecoder());
            pipeline.addLast("forwarder", forwardingHandler);
            pipeline.remove(this);
            done = true;
        }
    }
    if (!done) {
        logger.warn("Unknown input [" + data + "], ignoring");
        msg.clear();
        ctx.close();
    }
}