List of usage examples for io.netty.handler.logging LogLevel TRACE
LogLevel TRACE
To view the source code for io.netty.handler.logging LogLevel TRACE.
Click Source Link
From source file:nwses.java
License:Open Source License
/** * Main/*from w ww . j a v a 2 s .c om*/ * @param args Optional command-line parameters for server port and tag * @throws Exception */ public static void main(String[] args) throws Exception { final int port; final String tag; boolean SSL = false; if (args.length == 0) { port = 80; tag = "server1"; } else if (args.length == 1) { if (isValidPortNumber(args[0])) { port = Integer.parseInt(args[0]); tag = "server1"; } else { return; } } else { if (isValidPortNumber(args[0])) { port = Integer.parseInt(args[0]); tag = args[1]; } else { return; } } // If port 443 is specified to be used, use SSL. if (port == 443) { SSL = true; System.out.println("Websocket secure connection server initialized."); } final SslContext sslCtx; if (SSL) { SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); } else { sslCtx = null; } EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.TRACE)) .childHandler(new WebSocketServerInitializer(sslCtx, tag)); System.out.println("Server: " + tag + " started at port: " + port + " \n"); Channel chnl = b.bind(port).sync().channel(); chnl.closeFuture().sync(); } catch (Exception e) { //Catch exceptions e.g. trying to open second server on same port System.err.println("Caught exception: " + e.getMessage()); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); System.out.println("Server closed.."); } }
From source file:com.cloudera.livy.client.local.rpc.Rpc.java
License:Apache License
private static Rpc createRpc(LocalConf config, SaslHandler saslHandler, SocketChannel client, EventExecutorGroup egroup) throws IOException { LogLevel logLevel = LogLevel.TRACE; String logLevelStr = config.get(RPC_CHANNEL_LOG_LEVEL); if (logLevelStr != null) { try {/*from w w w. j ava 2s. co m*/ logLevel = LogLevel.valueOf(logLevelStr); } catch (Exception e) { LOG.warn("Invalid log level {}, reverting to default.", logLevelStr); } } boolean logEnabled = false; switch (logLevel) { case DEBUG: logEnabled = LOG.isDebugEnabled(); break; case ERROR: logEnabled = LOG.isErrorEnabled(); break; case INFO: logEnabled = LOG.isInfoEnabled(); break; case TRACE: logEnabled = LOG.isTraceEnabled(); break; case WARN: logEnabled = LOG.isWarnEnabled(); break; } if (logEnabled) { client.pipeline().addLast("logger", new LoggingHandler(Rpc.class, logLevel)); } KryoMessageCodec kryo = new KryoMessageCodec(config.getInt(RPC_MAX_MESSAGE_SIZE), MessageHeader.class, NullMessage.class, SaslMessage.class); saslHandler.setKryoMessageCodec(kryo); client.pipeline().addLast("codec", kryo).addLast("sasl", saslHandler); return new Rpc(config, client, egroup); }
From source file:com.cloudera.livy.rsc.rpc.Rpc.java
License:Apache License
private static Rpc createRpc(RSCConf config, SaslHandler saslHandler, SocketChannel client, EventExecutorGroup egroup) throws IOException { LogLevel logLevel = LogLevel.TRACE; String logLevelStr = config.get(RPC_CHANNEL_LOG_LEVEL); if (logLevelStr != null) { try {//from w ww . j av a 2 s . co m logLevel = LogLevel.valueOf(logLevelStr); } catch (Exception e) { LOG.warn("Invalid log level {}, reverting to default.", logLevelStr); } } boolean logEnabled = false; switch (logLevel) { case DEBUG: logEnabled = LOG.isDebugEnabled(); break; case ERROR: logEnabled = LOG.isErrorEnabled(); break; case INFO: logEnabled = LOG.isInfoEnabled(); break; case TRACE: logEnabled = LOG.isTraceEnabled(); break; case WARN: logEnabled = LOG.isWarnEnabled(); break; } if (logEnabled) { client.pipeline().addLast("logger", new LoggingHandler(Rpc.class, logLevel)); } KryoMessageCodec kryo = new KryoMessageCodec(config.getInt(RPC_MAX_MESSAGE_SIZE), MessageHeader.class, NullMessage.class, SaslMessage.class); saslHandler.setKryoMessageCodec(kryo); client.pipeline().addLast("codec", kryo).addLast("sasl", saslHandler); return new Rpc(config, client, egroup); }
From source file:com.couchbase.client.core.io.endpoint.AbstractEndpoint.java
License:Open Source License
/** * Create a new {@link AbstractEndpoint} and supply essential params. * * @param addr the socket address to connect to. * @param env the environment to attach to. * @param group the {@link EventLoopGroup} to use. */// w w w .j a va 2 s . co m protected AbstractEndpoint(final InetSocketAddress addr, final Environment env, final EventLoopGroup group) { this.env = env; endpointStateDeferred = Streams.defer(env, defaultPromiseEnv); endpointStateStream = endpointStateDeferred.compose(); connectionBootstrap = new BootstrapAdapter(new Bootstrap().group(group).channel(NioSocketChannel.class) .handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(final SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (LOGGER.isTraceEnabled()) { pipeline.addLast(new LoggingHandler(LogLevel.TRACE)); } customEndpointHandlers(pipeline); pipeline.addLast(new GenericEndpointHandler<REQ, RES>()); } }).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.TCP_NODELAY, false).option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 1500) .remoteAddress(addr)); }
From source file:com.digitalpetri.modbus.slave.ModbusTcpSlave.java
License:Apache License
public CompletableFuture<ModbusTcpSlave> bind(String host, int port) { CompletableFuture<ModbusTcpSlave> bindFuture = new CompletableFuture<>(); ServerBootstrap bootstrap = new ServerBootstrap(); ChannelInitializer<SocketChannel> initializer = new ChannelInitializer<SocketChannel>() { @Override/*from w ww .j av a 2s . c o m*/ protected void initChannel(SocketChannel channel) throws Exception { channelCounter.inc(); logger.info("channel initialized: {}", channel); channel.pipeline().addLast(new LoggingHandler(LogLevel.TRACE)); channel.pipeline() .addLast(new ModbusTcpCodec(new ModbusResponseEncoder(), new ModbusRequestDecoder())); channel.pipeline().addLast(new ModbusTcpSlaveHandler(ModbusTcpSlave.this)); channel.closeFuture().addListener(future -> channelCounter.dec()); } }; config.getBootstrapConsumer().accept(bootstrap); bootstrap.group(config.getEventLoop()).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.DEBUG)).childHandler(initializer) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); bootstrap.bind(host, port).addListener((ChannelFuture future) -> { if (future.isSuccess()) { Channel channel = future.channel(); serverChannels.put(channel.localAddress(), channel); bindFuture.complete(ModbusTcpSlave.this); } else { bindFuture.completeExceptionally(future.cause()); } }); return bindFuture; }
From source file:com.intuit.karate.netty.FeatureServer.java
License:Open Source License
private FeatureServer(Feature feature, int requestedPort, SslContext sslCtx, Map<String, Object> arg) { ssl = sslCtx != null;// w ww.ja v a2 s . co m bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(); FeatureServerInitializer initializer = new FeatureServerInitializer(sslCtx, feature, arg, () -> stop()); try { ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(getClass().getName(), LogLevel.TRACE)).childHandler(initializer); channel = b.bind(requestedPort).sync().channel(); InetSocketAddress isa = (InetSocketAddress) channel.localAddress(); host = "127.0.0.1"; //isa.getHostString(); port = isa.getPort(); logger.info("server started - {}://{}:{}", ssl ? "https" : "http", host, port); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.king.platform.net.http.netty.ChannelManager.java
License:Apache License
private void addLoggingIfDesired(ChannelPipeline pipeline, boolean desired) { if (desired) { pipeline.addLast("logging", new LoggingHandler(LogLevel.TRACE)); }/*from w w w . java 2 s. c o m*/ }
From source file:com.linecorp.armeria.internal.TrafficLoggingHandler.java
License:Apache License
private TrafficLoggingHandler(boolean server) { super("com.linecorp.armeria.logging.traffic." + (server ? "server" : "client"), LogLevel.TRACE); }
From source file:com.sitech.crmpd.idmm2.ble.EchoClient.java
License:Apache License
public static void consumer(String[] args) throws Exception { // Configure the client. EventLoopGroup group = new NioEventLoopGroup(); try {// ww w . ja v a 2 s. c o m Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new LoggingHandler(LogLevel.TRACE)); p.addLast(new FrameCodeC()); p.addLast(new ConsumerClientHandler(clientid, target_topic)); } }); // Start the client. ChannelFuture f = b.connect(ble_ip, ble_port).sync(); // Wait until the connection is closed. f.channel().closeFuture().sync(); } finally { // Shut down the event loop to terminate all threads. group.shutdownGracefully(); } }
From source file:com.sitech.crmpd.idmm2.ble.EchoClient.java
License:Apache License
public static void producer(String[] args) throws Exception { // Configure the client. EventLoopGroup group = new NioEventLoopGroup(); try {// w w w . j av a 2 s. com Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); p.addLast(new LoggingHandler(LogLevel.TRACE)); p.addLast(new FrameCodeC()); p.addLast(new ProducerClientHandler(clientid, target_topic)); } }); // Start the client. ChannelFuture f = b.connect(ble_ip, ble_port).sync(); // Wait until the connection is closed. f.channel().closeFuture().sync(); } finally { // Shut down the event loop to terminate all threads. group.shutdownGracefully(); } }