Example usage for io.netty.channel ChannelPipeline get

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

Introduction

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

Prototype

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

Source Link

Document

Returns the ChannelHandler of the specified type in this pipeline.

Usage

From source file:c5db.client.C5NettyConnectionManager.java

License:Apache License

private boolean isHandShakeConnected(Channel channel) {
    final ChannelPipeline pipeline = channel.pipeline();
    final WebsocketProtostuffEncoder encoder = pipeline.get(WebsocketProtostuffEncoder.class);
    return encoder.getHandShaker().isHandshakeComplete();
}

From source file:com.barchart.netty.client.facets.AuthenticationFacet.java

License:BSD License

@Override
public void initPipeline(final ChannelPipeline pipeline) throws Exception {

    if (pipeline.get(CapabilitiesRequest.class) == null)
        pipeline.addLast(new CapabilitiesRequest());

    authenticator = builder.build();/*www .  j  av  a 2s  .co  m*/
    authenticator.authStateChanges().subscribe(stateRelay);

    pipeline.addLast(authenticator);

}

From source file:com.barchart.netty.client.facets.SecureFacet.java

License:BSD License

@Override
public void initPipeline(final ChannelPipeline pipeline) throws Exception {

    switch (security) {

    case REFUSE:/*from w  w w.j  ava2 s .c  o  m*/
        handler = null;
        break;

    case REQUIRE:
        handler = new SecureFlowHandler(true);
        break;

    case OPTIONAL:
    default:
        handler = new SecureFlowHandler(false);

    }

    if (handler != null) {

        if (pipeline.get(CapabilitiesRequest.class) == null)
            pipeline.addLast(new CapabilitiesRequest());

        pipeline.addLast(handler);

    }

}

From source file:com.barchart.netty.client.transport.WebSocketTransport.java

License:BSD License

@Override
public void initPipeline(final ChannelPipeline pipeline) throws Exception {

    final WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri,
            WebSocketVersion.V13, null, false, null);

    final WebSocketClientProtocolHandler wsHandler = new WebSocketClientProtocolHandler(handshaker);

    pipeline.addFirst(new HttpClientCodec(), //
            new HttpObjectAggregator(65536), //
            wsHandler,//from  www  . ja v  a 2s  .c o m
            // Fires channelActive() after handshake and removes self
            new WebSocketConnectedNotifier(),
            // BinaryWebSocketFrame <-> ByteBuf codec before user codecs
            new WebSocketBinaryCodec());

    if (uri.getScheme().equalsIgnoreCase("wss") && pipeline.get(SslHandler.class) == null) {

        final SSLEngine sslEngine = SSLContext.getDefault().createSSLEngine();
        sslEngine.setUseClientMode(true);
        pipeline.addFirst("ssl", new SslHandler(sslEngine));

    }

}

From source file:com.bay1ts.bay.core.Request.java

License:Apache License

public boolean isSecure() {
    // TODO: 2016/10/16 bug found
    Channel channel = ChannelThreadLocal.get();
    //../*ww  w  .j a  v  a2s . c  om*/
    ChannelPipeline channelPipeline = channel.pipeline();
    channelPipeline.get(SslHandler.class);
    return ChannelThreadLocal.get().pipeline().get(SslHandler.class) != null;
}

From source file:com.chuck.netty4.websocket.WebSocketIndexPageHandler.java

License:Apache License

private static String getWebSocketLocation(ChannelPipeline cp, HttpRequest req, String path) {
    String protocol = "ws";
    if (cp.get(SslHandler.class) != null) {
        // SSL in use so use Secure WebSockets
        protocol = "wss";
    }/*w ww  . ja va  2s.  c  om*/
    return protocol + "://" + req.headers().get(HttpHeaderNames.HOST) + path;
}

From source file:com.github.jrialland.ajpclient.impl.Conversation.java

License:Apache License

public boolean execute(final Channel channel) throws Exception {
    final ChannelPipeline pipeline = channel.pipeline();
    if (getLog().isTraceEnabled() && pipeline.get(OutgoingFramesLogger.class) == null) {
        pipeline.addLast(new OutgoingFramesLogger());
    }//  w  ww.  j  a v a 2  s . c  om
    if (pipeline.get(AjpMessagesHandler.class) == null) {
        pipeline.addLast(new AjpMessagesHandler());
    }
    beforeUse(channel);
    final boolean r = __doWithChannel(channel);
    beforeRelease(channel);
    return r;
}

From source file:com.jin.jlg.netty.websock.WebSocketIndexPageHandler.java

License:Apache License

private static String getWebSocketLocation(ChannelPipeline cp, HttpRequest req, String path) {
    String protocol = "ws";
    if (cp.get(SslHandler.class) != null) {
        // SSL in use so use Secure WebSockets
        protocol = "wss";
    }//w w  w.j a  v  a  2 s .  com
    return protocol + "://" + req.headers().get(HttpHeaders.Names.HOST) + path;
}

From source file:com.lambdaworks.redis.AbstractRedisClient.java

License:Apache License

/**
 * Shutdown this client and close all open connections. The client should be discarded after calling shutdown.
 *
 * @param quietPeriod the quiet period as described in the documentation
 * @param timeout the maximum amount of time to wait until the executor is shutdown regardless if a task was submitted
 *        during the quiet period//from  w ww .ja v  a 2 s  . c o m
 * @param timeUnit the unit of {@code quietPeriod} and {@code timeout}
 */
public void shutdown(long quietPeriod, long timeout, TimeUnit timeUnit) {

    if (shutdown.compareAndSet(false, true)) {

        while (!closeableResources.isEmpty()) {
            Closeable closeableResource = closeableResources.iterator().next();
            try {
                closeableResource.close();
            } catch (Exception e) {
                logger.debug("Exception on Close: " + e.getMessage(), e);
            }
            closeableResources.remove(closeableResource);
        }

        List<Future<?>> closeFutures = new ArrayList<>();

        for (Channel c : channels) {
            ChannelPipeline pipeline = c.pipeline();

            CommandHandler<?, ?> commandHandler = pipeline.get(CommandHandler.class);
            if (commandHandler != null && !commandHandler.isClosed()) {
                commandHandler.close();
            }

            PubSubCommandHandler<?, ?> psCommandHandler = pipeline.get(PubSubCommandHandler.class);
            if (psCommandHandler != null && !psCommandHandler.isClosed()) {
                psCommandHandler.close();
            }
        }

        try {
            closeFutures.add(channels.close());
        } catch (Exception e) {
            logger.debug("Cannot close channels", e);
        }

        if (!sharedResources) {
            Future<?> groupCloseFuture = clientResources.shutdown(quietPeriod, timeout, timeUnit);
            closeFutures.add(groupCloseFuture);
        } else {
            for (EventLoopGroup eventExecutors : eventLoopGroups.values()) {
                Future<?> groupCloseFuture = clientResources.eventLoopGroupProvider().release(eventExecutors,
                        quietPeriod, timeout, timeUnit);
                closeFutures.add(groupCloseFuture);
            }
        }

        for (Future<?> future : closeFutures) {
            try {
                future.get();
            } catch (Exception e) {
                throw new RedisException(e);
            }
        }
    }
}

From source file:com.lambdaworks.redis.PlainChannelInitializer.java

License:Apache License

static void removeIfExists(ChannelPipeline pipeline, Class<? extends ChannelHandler> handlerClass) {
    ChannelHandler channelHandler = pipeline.get(handlerClass);
    if (channelHandler != null) {
        pipeline.remove(channelHandler);
    }/*from   w w w.  j  a va2  s  .  c  o m*/
}