Example usage for io.netty.handler.logging LogLevel DEBUG

List of usage examples for io.netty.handler.logging LogLevel DEBUG

Introduction

In this page you can find the example usage for io.netty.handler.logging LogLevel DEBUG.

Prototype

LogLevel DEBUG

To view the source code for io.netty.handler.logging LogLevel DEBUG.

Click Source Link

Usage

From source file:org.opendaylight.controller.netconf.tcp.netty.ProxyServer.java

License:Open Source License

public ProxyServer(InetSocketAddress address, final LocalAddress localAddress) {
    // Configure the server.
    final Bootstrap clientBootstrap = new Bootstrap();
    clientBootstrap.group(bossGroup).channel(LocalChannel.class);

    ServerBootstrap serverBootstrap = new ServerBootstrap();
    serverBootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
            .handler(new LoggingHandler(LogLevel.DEBUG)).childHandler(new ChannelInitializer<SocketChannel>() {
                @Override//from   w w w  .  j  a v a2 s.  c om
                public void initChannel(SocketChannel ch) throws Exception {
                    ch.pipeline().addLast(new ProxyServerHandler(clientBootstrap, localAddress));
                }
            });

    // Start the server.
    channelFuture = serverBootstrap.bind(address).syncUninterruptibly();
}

From source file:org.opendaylight.ocpjava.protocol.impl.core.TcpHandler.java

License:Open Source License

/**
 * Starts server on selected port./*from www  .j  a va 2  s  . co m*/
 */
@Override
public void run() {
    /*
     * We generally do not perform IO-unrelated tasks, so we want to have
     * all outstanding tasks completed before the executing thread goes
     * back into select.
     *
     * Any other setting means netty will measure the time it spent selecting
     * and spend roughly proportional time executing tasks.
     */
    workerGroup.setIoRatio(100);

    final ChannelFuture f;
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.DEBUG)).childHandler(channelInitializer)
                .option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_REUSEADDR, true)
                //modify to "false" for OCP health-check
                .childOption(ChannelOption.SO_KEEPALIVE, false).childOption(ChannelOption.TCP_NODELAY, true)
                .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
                .childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, DEFAULT_WRITE_HIGH_WATERMARK * 1024)
                .childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, DEFAULT_WRITE_LOW_WATERMARK * 1024)
                .childOption(ChannelOption.WRITE_SPIN_COUNT, DEFAULT_WRITE_SPIN_COUNT);

        if (startupAddress != null) {
            f = b.bind(startupAddress.getHostAddress(), port).sync();
        } else {
            f = b.bind(port).sync();
        }
    } catch (InterruptedException e) {
        LOG.error("Interrupted while binding port {}", port, e);
        return;
    }

    try {
        InetSocketAddress isa = (InetSocketAddress) f.channel().localAddress();
        address = isa.getHostString();

        // Update port, as it may have been specified as 0
        this.port = isa.getPort();

        LOG.debug("address from tcphandler: {}", address);
        isOnlineFuture.set(true);
        LOG.info("RadioHead listener started and ready to accept incoming tcp/tls connections on port: {}",
                port);
        f.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        LOG.error("Interrupted while waiting for port {} shutdown", port, e);
    } finally {
        shutdown();
    }
}

From source file:org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.java

License:Open Source License

/**
 * Starts server on selected port./*from  ww  w.  j  a va2s .  c  o m*/
 */
@Override
public void run() {
    bossGroup = new NioEventLoopGroup();
    workerGroup = new NioEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.DEBUG)).childHandler(channelInitializer)
                .option(ChannelOption.SO_BACKLOG, 128).option(ChannelOption.SO_REUSEADDR, true)
                .childOption(ChannelOption.SO_KEEPALIVE, true);

        ChannelFuture f;
        if (startupAddress != null) {
            f = b.bind(startupAddress.getHostAddress(), port).sync();
        } else {
            f = b.bind(port).sync();
        }

        InetSocketAddress isa = (InetSocketAddress) f.channel().localAddress();
        address = isa.getHostString();
        LOGGER.debug("address from tcphandler: " + address);
        port = isa.getPort();
        isOnlineFuture.set(true);
        LOGGER.info("Switch listener started and ready to accept incoming connections on port: " + port);
        f.channel().closeFuture().sync();
    } catch (InterruptedException ex) {
        LOGGER.error(ex.getMessage(), ex);
    } finally {
        shutdown();
    }
}

From source file:org.opendaylight.ovsdb.lib.jsonrpc.TestClient.java

License:Open Source License

public void setupServer() throws Exception {
    bootstrapper.startServer(serverport, jsonRpcDecoder, new LoggingHandler(LogLevel.DEBUG));
}

From source file:org.pidome.server.system.network.sockets.SocketBase.java

/**
 * Returns a default with minimal requirements set server bootstrap.
 * @param parents The parent worker controller amount.
 * @param childs The amount of childs per parent worker.
 * @return Server Bootstrap with a socket service channel.
 *///ww  w .  j a va  2 s .c o m
public final ServerBootstrap getSocketServerBootstrapContext(int parents, int childs) {
    if (workersGroup == null) {
        workersGroup = new NioEventLoopGroup();
    }
    return new ServerBootstrap().group(workersGroup)
            .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
            .channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.DEBUG));
}

From source file:org.pumpkindb.Client.java

License:Mozilla Public License

public void connect() {
    workerGroup = new NioEventLoopGroup();
    Bootstrap b = new Bootstrap();
    b.group(workerGroup);// w  ww.  ja  v a  2 s. co m
    b.channel(NioSocketChannel.class);
    b.option(ChannelOption.SO_KEEPALIVE, true);

    b.handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addFirst(new LoggingHandler(LogLevel.DEBUG));

            ch.pipeline().addLast(new LengthFieldPrepender(4));
            ch.pipeline().addLast(new FrameEncoder());

            ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));

            ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                @Override
                public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                    ByteBuf buf = (ByteBuf) msg;
                    messageHandler.accept(buf);
                }
            });
        }

    });

    ChannelFuture channelFuture = b.connect(host, port).syncUninterruptibly();

    channel = channelFuture.channel();

}

From source file:org.skfiy.typhon.net.Netty4Connector.java

License:Apache License

@Override
protected void startInternal() throws LifecycleException {
    setState(LifecycleState.STARTING);/* www  . j  ava  2s .  co  m*/
    fireLifecycleListener(START_EVENT);

    System.setProperty("io.netty.noJdkZlibDecoder", "false");

    final byte[] delimiters = new byte[] { '\n' };

    final String compressionMode = Typhons.getProperty("typhon.spi.net.compressionMode");
    final Netty4EndpointHandler handler = new Netty4EndpointHandler();
    final Netty4ConnectionLimitHandler limitHandler = new Netty4ConnectionLimitHandler();

    // ????
    final LengthFieldPrepender lengthFieldPrepender;
    final DelimiterBasedFrameEncoder delimiterBasedFrameEncoder;
    if ("zlib".equals(compressionMode)) {
        lengthFieldPrepender = new LengthFieldPrepender(4);
        delimiterBasedFrameEncoder = null;
    } else {
        lengthFieldPrepender = null;
        delimiterBasedFrameEncoder = new DelimiterBasedFrameEncoder(delimiters);
    }

    // 
    final LoggingHandler loggingHandler;
    if (isLogEnabled()) {
        loggingHandler = new LoggingHandler(LogLevel.DEBUG);
    } else {
        loggingHandler = null;
    }

    serverBootstrap = new ServerBootstrap();
    serverBootstrap.group(new NioEventLoopGroup(1), new NioEventLoopGroup())
            .channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100)
            .childHandler(new ChannelInitializer() {

                @Override
                protected void initChannel(Channel c) throws Exception {
                    ChannelPipeline pipeline = c.pipeline();
                    if ("zlib".equals(compressionMode)) {
                        pipeline.addLast("lengthFieldPrepender", lengthFieldPrepender);
                        pipeline.addLast("lengthFieldBasedFrameDecoder",
                                new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
                        pipeline.addLast("deflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.ZLIB));
                    } else {
                        pipeline.addLast("delimiterBasedFrameDecoder", new DelimiterBasedFrameDecoder(65535,
                                new ByteBuf[] { Unpooled.wrappedBuffer(delimiters) }));
                        pipeline.addLast("delimiterBasedFrameEncoder", delimiterBasedFrameEncoder);
                    }

                    if (isLogEnabled()) {
                        pipeline.addLast(loggingHandler);
                    }

                    pipeline.addLast(new IdleStateHandler(60 * 10, 60 * 10, 0));
                    pipeline.addLast(limitHandler, handler);
                }
            });

    channel = serverBootstrap.bind(host, port).channel();
    CLOG.debug("Netty4Connector started on port {}", port);

    MBeanServer mbs = MBeanUtils.REGISTRY.getMBeanServer();
    Object obj = null;
    try {
        obj = mbs.invoke(Container.OBJECT_NAME, "getInstance", new Object[] { ProtocolHandler.class },
                new String[] { Class.class.getName() });
    } catch (Exception ex) {
        CLOG.error("ProtocolHandler", ex);
        throw new TyphonException(ex);
    }
    handler.setProtocolHandler((ProtocolHandler) obj);
}

From source file:org.wso2.carbon.transport.http.netty.listener.HTTPServerChannelInitializer.java

License:Open Source License

/**
 * Configure the pipeline if user sent HTTP requests
 *
 * @param pipeline Channel// w w  w .  j  a va2 s .c  o  m
 */
public void configureHTTPPipeline(ChannelPipeline pipeline) {
    // Removed the default encoder since http/2 version upgrade already added to pipeline
    if (requestSizeValidationConfig != null && requestSizeValidationConfig.isHeaderSizeValidation()) {
        pipeline.addLast("decoder", new CustomHttpRequestDecoder(requestSizeValidationConfig));
    } else {
        pipeline.addLast("decoder", new HttpRequestDecoder());
    }
    if (requestSizeValidationConfig != null && requestSizeValidationConfig.isRequestSizeValidation()) {
        pipeline.addLast("custom-aggregator", new CustomHttpObjectAggregator(requestSizeValidationConfig));
    }
    pipeline.addLast("compressor", new CustomHttpContentCompressor());
    pipeline.addLast("chunkWriter", new ChunkedWriteHandler());

    if (httpTraceLogEnabled) {
        pipeline.addLast(Constants.HTTP_TRACE_LOG_HANDLER,
                new HTTPTraceLoggingHandler("tracelog.http.downstream", LogLevel.DEBUG));
    }

    pipeline.addLast(Constants.WEBSOCKET_SERVER_HANDSHAKE_HANDLER,
            new WebSocketServerHandshakeHandler(this.serverConnectorFuture, this.interfaceId));

    try {
        pipeline.addLast(Constants.HTTP_SOURCE_HANDLER,
                new SourceHandler(this.serverConnectorFuture, this.interfaceId));
    } catch (Exception e) {
        log.error("Cannot Create SourceHandler ", e);
    }
}

From source file:org.wso2.carbon.transport.http.netty.sender.HTTPClientInitializer.java

License:Open Source License

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    // Add the generic handlers to the pipeline
    // e.g. SSL handler
    if (proxyServerConfiguration != null) {
        if (proxyServerConfiguration.getProxyUsername() != null
                && proxyServerConfiguration.getProxyPassword() != null) {
            ch.pipeline().addLast("proxyServer",
                    new HttpProxyHandler(proxyServerConfiguration.getInetSocketAddress(),
                            proxyServerConfiguration.getProxyUsername(),
                            proxyServerConfiguration.getProxyPassword()));
        } else {/*from ww  w .  ja v  a2  s.c  o  m*/
            ch.pipeline().addLast("proxyServer",
                    new HttpProxyHandler(proxyServerConfiguration.getInetSocketAddress()));
        }
    }
    if (sslEngine != null) {
        log.debug("adding ssl handler");
        ch.pipeline().addLast("ssl", new SslHandler(this.sslEngine));
    }
    ch.pipeline().addLast("compressor", new CustomHttpContentCompressor(chunkDisabled));
    ch.pipeline().addLast("decoder", new HttpResponseDecoder());
    ch.pipeline().addLast("encoder", new HttpRequestEncoder());
    ch.pipeline().addLast("chunkWriter", new ChunkedWriteHandler());
    if (httpTraceLogEnabled) {
        ch.pipeline().addLast(Constants.HTTP_TRACE_LOG_HANDLER,
                new HTTPTraceLoggingHandler("tracelog.http.upstream", LogLevel.DEBUG));
    }
    if (followRedirect) {
        if (log.isDebugEnabled()) {
            log.debug("Follow Redirect is enabled, so adding the redirect handler to the pipeline.");
        }
        RedirectHandler redirectHandler = new RedirectHandler(sslEngine, httpTraceLogEnabled, maxRedirectCount,
                chunkDisabled);
        ch.pipeline().addLast(Constants.REDIRECT_HANDLER, redirectHandler);
    }
    handler = new TargetHandler();
    ch.pipeline().addLast(Constants.TARGET_HANDLER, handler);
}

From source file:org.wso2.carbon.transport.http.netty.sender.RedirectChannelInitializer.java

License:Open Source License

@Override
protected void initChannel(SocketChannel ch) throws Exception {
    // Add the generic handlers to the pipeline
    // e.g. SSL handler
    if (sslEngine != null) {
        if (log.isDebugEnabled()) {
            log.debug("adding ssl handler");
        }/* ww w. j  a v  a 2 s  .com*/
        ch.pipeline().addLast("ssl", new SslHandler(this.sslEngine));
    }
    ch.pipeline().addLast("compressor", new HttpContentCompressor());
    ch.pipeline().addLast("decoder", new HttpResponseDecoder());
    ch.pipeline().addLast("encoder", new HttpRequestEncoder());
    if (httpTraceLogEnabled) {
        ch.pipeline().addLast(Constants.HTTP_TRACE_LOG_HANDLER,
                new HTTPTraceLoggingHandler("tracelog.http.upstream", LogLevel.DEBUG));
    }
    RedirectHandler redirectHandler = new RedirectHandler(sslEngine, httpTraceLogEnabled, maxRedirectCount,
            chunkDisabled, originalChannelContext, isIdleHandlerOfTargetChannelRemoved);
    ch.pipeline().addLast(Constants.REDIRECT_HANDLER, redirectHandler);
}