Example usage for io.netty.channel ChannelPipeline addAfter

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

Introduction

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

Prototype

ChannelPipeline addAfter(String baseName, String name, ChannelHandler handler);

Source Link

Document

Inserts a ChannelHandler after an existing handler of this pipeline.

Usage

From source file:io.moquette.server.netty.NettyAcceptor.java

License:Open Source License

private void initializePlainTCPTransport(final NettyMQTTHandler handler, IConfig props) throws IOException {
    final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();
    String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
    int port = Integer.parseInt(props.getProperty(BrokerConstants.PORT_PROPERTY_NAME));
    initFactory(host, port, new PipelineInitializer() {
        @Override//from  w w w . j a va2s  . com
        void init(ChannelPipeline pipeline) {
            pipeline.addFirst("idleStateHandler",
                    new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
            pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
            //pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR));
            pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
            pipeline.addLast("decoder", new MQTTDecoder());
            pipeline.addLast("encoder", new MQTTEncoder());
            pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
            pipeline.addLast("handler", handler);
        }
    });
}

From source file:io.moquette.server.netty.NettyAcceptor.java

License:Open Source License

private void initializeWebSocketTransport(final NettyMQTTHandler handler, IConfig props) throws IOException {
    String webSocketPortProp = props.getProperty(BrokerConstants.WEB_SOCKET_PORT_PROPERTY_NAME);
    if (webSocketPortProp == null) {
        //Do nothing no WebSocket configured
        LOG.info("WebSocket is disabled");
        return;//from w  w  w  .  j a va2 s.  co  m
    }
    int port = Integer.parseInt(webSocketPortProp);

    final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();

    String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
    initFactory(host, port, new PipelineInitializer() {
        @Override
        void init(ChannelPipeline pipeline) {
            pipeline.addLast("httpEncoder", new HttpResponseEncoder());
            pipeline.addLast("httpDecoder", new HttpRequestDecoder());
            pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
            pipeline.addLast("webSocketHandler",
                    new WebSocketServerProtocolHandler("/mqtt", "mqtt, mqttv3.1, mqttv3.1.1"));
            pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
            pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
            pipeline.addFirst("idleStateHandler",
                    new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
            pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
            pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
            pipeline.addLast("decoder", new MQTTDecoder());
            pipeline.addLast("encoder", new MQTTEncoder());
            pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
            pipeline.addLast("handler", handler);
        }
    });
}

From source file:io.moquette.server.netty.NettyAcceptor.java

License:Open Source License

private void initializeSSLTCPTransport(final NettyMQTTHandler handler, IConfig props,
        final SSLContext sslContext) throws IOException {
    String sslPortProp = props.getProperty(BrokerConstants.SSL_PORT_PROPERTY_NAME);
    if (sslPortProp == null) {
        //Do nothing no SSL configured
        LOG.info("SSL is disabled");
        return;/*  w  ww  .ja  v  a2 s  .  c o  m*/
    }

    int sslPort = Integer.parseInt(sslPortProp);
    LOG.info("Starting SSL on port {}", sslPort);

    final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();
    String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
    String sNeedsClientAuth = props.getProperty(BrokerConstants.NEED_CLIENT_AUTH, "false");
    final boolean needsClientAuth = Boolean.valueOf(sNeedsClientAuth);
    initFactory(host, sslPort, new PipelineInitializer() {
        @Override
        void init(ChannelPipeline pipeline) throws Exception {
            pipeline.addLast("ssl", createSslHandler(sslContext, needsClientAuth));
            pipeline.addFirst("idleStateHandler",
                    new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
            pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
            //pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR));
            pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
            pipeline.addLast("decoder", new MQTTDecoder());
            pipeline.addLast("encoder", new MQTTEncoder());
            pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
            pipeline.addLast("handler", handler);
        }
    });
}

From source file:io.moquette.server.netty.NettyAcceptor.java

License:Open Source License

private void initializeWSSTransport(final NettyMQTTHandler handler, IConfig props, final SSLContext sslContext)
        throws IOException {
    String sslPortProp = props.getProperty(BrokerConstants.WSS_PORT_PROPERTY_NAME);
    if (sslPortProp == null) {
        //Do nothing no SSL configured
        LOG.info("SSL is disabled");
        return;/*from  w  w w  .  j  av a  2 s . com*/
    }
    int sslPort = Integer.parseInt(sslPortProp);
    final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();
    String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
    String sNeedsClientAuth = props.getProperty(BrokerConstants.NEED_CLIENT_AUTH, "false");
    final boolean needsClientAuth = Boolean.valueOf(sNeedsClientAuth);
    initFactory(host, sslPort, new PipelineInitializer() {
        @Override
        void init(ChannelPipeline pipeline) throws Exception {
            pipeline.addLast("ssl", createSslHandler(sslContext, needsClientAuth));
            pipeline.addLast("httpEncoder", new HttpResponseEncoder());
            pipeline.addLast("httpDecoder", new HttpRequestDecoder());
            pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
            pipeline.addLast("webSocketHandler",
                    new WebSocketServerProtocolHandler("/mqtt", "mqtt mqttv3.1, mqttv3.1.1"));
            pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
            pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
            pipeline.addFirst("idleStateHandler",
                    new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
            pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
            pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
            pipeline.addLast("decoder", new MQTTDecoder());
            pipeline.addLast("encoder", new MQTTEncoder());
            pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
            pipeline.addLast("handler", handler);
        }
    });
}

From source file:io.moquette.server.netty.NettyAcceptor__.java

License:Open Source License

private void initializePlainTCPTransport(final NettyMQTTHandler__ handler, IConfig props) throws IOException {
    final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();
    String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
    String tcpPortProp = props.getProperty(PORT_PROPERTY_NAME, DISABLED_PORT_BIND);
    if (DISABLED_PORT_BIND.equals(tcpPortProp)) {
        LOG.info("tcp MQTT is disabled because the value for the property with key {}",
                BrokerConstants.PORT_PROPERTY_NAME);
        return;/* w w w. j a  v a 2 s .  c o m*/
    }
    int port = Integer.parseInt(tcpPortProp);
    initFactory(host, port, new PipelineInitializer() {
        @Override
        void init(ChannelPipeline pipeline) {
            pipeline.addFirst("idleStateHandler",
                    new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
            pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
            pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
            pipeline.addLast("decoder", new MQTTDecoder());
            pipeline.addLast("encoder", new MQTTEncoder());
            pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
            pipeline.addLast("messageLogger", new MQTTMessageLogger());
            pipeline.addLast("handler", handler);
        }
    });
}

From source file:io.moquette.server.netty.NettyAcceptor__.java

License:Open Source License

private void initializeWebSocketTransport(final NettyMQTTHandler__ handler, IConfig props) throws IOException {
    String webSocketPortProp = props.getProperty(WEB_SOCKET_PORT_PROPERTY_NAME, DISABLED_PORT_BIND);
    if (DISABLED_PORT_BIND.equals(webSocketPortProp)) {
        //Do nothing no WebSocket configured
        LOG.info("WebSocket is disabled");
        return;/*from   w  ww. ja  v a 2 s .c om*/
    }
    int port = Integer.parseInt(webSocketPortProp);

    final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();

    String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
    initFactory(host, port, new PipelineInitializer() {
        @Override
        void init(ChannelPipeline pipeline) {
            pipeline.addLast(new HttpServerCodec());
            pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
            pipeline.addLast("webSocketHandler",
                    new WebSocketServerProtocolHandler("/mqtt", MQTT_SUBPROTOCOL_CSV_LIST));
            pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
            pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
            pipeline.addFirst("idleStateHandler",
                    new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
            pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
            pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
            pipeline.addLast("decoder", new MQTTDecoder());
            pipeline.addLast("encoder", new MQTTEncoder());
            pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
            pipeline.addLast("messageLogger", new MQTTMessageLogger());
            pipeline.addLast("handler", handler);
        }
    });
}

From source file:io.moquette.server.netty.NettyAcceptor__.java

License:Open Source License

private void initializeSSLTCPTransport(final NettyMQTTHandler__ handler, IConfig props,
        final SSLContext sslContext) throws IOException {
    String sslPortProp = props.getProperty(SSL_PORT_PROPERTY_NAME, DISABLED_PORT_BIND);
    if (DISABLED_PORT_BIND.equals(sslPortProp)) {
        //Do nothing no SSL configured
        LOG.info("SSL MQTT is disabled because there is no value in properties for key {}",
                BrokerConstants.SSL_PORT_PROPERTY_NAME);
        return;/*from   ww w.  j  av  a2  s . c  o m*/
    }

    int sslPort = Integer.parseInt(sslPortProp);
    LOG.info("Starting SSL on port {}", sslPort);

    final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();
    String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
    String sNeedsClientAuth = props.getProperty(BrokerConstants.NEED_CLIENT_AUTH, "false");
    final boolean needsClientAuth = Boolean.valueOf(sNeedsClientAuth);
    initFactory(host, sslPort, new PipelineInitializer() {
        @Override
        void init(ChannelPipeline pipeline) throws Exception {
            pipeline.addLast("ssl", createSslHandler(sslContext, needsClientAuth));
            pipeline.addFirst("idleStateHandler",
                    new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
            pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
            //pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR));
            pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
            pipeline.addLast("decoder", new MQTTDecoder());
            pipeline.addLast("encoder", new MQTTEncoder());
            pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
            pipeline.addLast("messageLogger", new MQTTMessageLogger());
            pipeline.addLast("handler", handler);
        }
    });
}

From source file:io.moquette.server.netty.NettyAcceptor__.java

License:Open Source License

private void initializeWSSTransport(final NettyMQTTHandler__ handler, IConfig props,
        final SSLContext sslContext) throws IOException {
    String sslPortProp = props.getProperty(WSS_PORT_PROPERTY_NAME, DISABLED_PORT_BIND);
    if (DISABLED_PORT_BIND.equals(sslPortProp)) {
        //Do nothing no SSL configured
        LOG.info("SSL websocket is disabled because there is no value in properties for key {}",
                BrokerConstants.WSS_PORT_PROPERTY_NAME);
        return;//from  w  w  w  .  j  av a  2s  .c  o  m
    }
    int sslPort = Integer.parseInt(sslPortProp);
    final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();
    String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
    String sNeedsClientAuth = props.getProperty(BrokerConstants.NEED_CLIENT_AUTH, "false");
    final boolean needsClientAuth = Boolean.valueOf(sNeedsClientAuth);
    initFactory(host, sslPort, new PipelineInitializer() {
        @Override
        void init(ChannelPipeline pipeline) throws Exception {
            pipeline.addLast("ssl", createSslHandler(sslContext, needsClientAuth));
            pipeline.addLast("httpEncoder", new HttpResponseEncoder());
            pipeline.addLast("httpDecoder", new HttpRequestDecoder());
            pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
            pipeline.addLast("webSocketHandler",
                    new WebSocketServerProtocolHandler("/mqtt", MQTT_SUBPROTOCOL_CSV_LIST));
            pipeline.addLast("ws2bytebufDecoder", new WebSocketFrameToByteBufDecoder());
            pipeline.addLast("bytebuf2wsEncoder", new ByteBufToWebSocketFrameEncoder());
            pipeline.addFirst("idleStateHandler",
                    new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
            pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
            pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
            pipeline.addLast("decoder", new MQTTDecoder());
            pipeline.addLast("encoder", new MQTTEncoder());
            pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
            pipeline.addLast("messageLogger", new MQTTMessageLogger());
            pipeline.addLast("handler", handler);
        }
    });
}

From source file:io.moquette.spi.impl.ProtocolProcessor.java

License:Open Source License

private void setupAutoFlusher(ChannelPipeline pipeline, int flushIntervalMs) {
    AutoFlushHandler autoFlushHandler = new AutoFlushHandler(flushIntervalMs, TimeUnit.MILLISECONDS);
    try {/*from w  w w .j a v a2  s.c om*/
        pipeline.addAfter("idleEventHandler", "autoFlusher", autoFlushHandler);
    } catch (NoSuchElementException nseex) {
        //the idleEventHandler is not present on the pipeline
        pipeline.addFirst("autoFlusher", autoFlushHandler);
    }
}

From source file:io.moquette.spi.impl.ProtocolProcessor__.java

License:Open Source License

private void setupAutoFlusher(ChannelPipeline pipeline, int flushIntervalMs) {
    try {//from   w  ww.jav a2 s  . co  m
        pipeline.addAfter("idleEventHandler", "autoFlusher",
                new AutoFlushHandler(flushIntervalMs, TimeUnit.MILLISECONDS));
    } catch (NoSuchElementException nseex) {
        //the idleEventHandler is not present on the pipeline
        pipeline.addFirst("autoFlusher", new AutoFlushHandler(flushIntervalMs, TimeUnit.MILLISECONDS));
    }
}