List of usage examples for io.netty.handler.logging LogLevel INFO
LogLevel INFO
To view the source code for io.netty.handler.logging LogLevel INFO.
Click Source Link
From source file:com.shun.liu.shunzhitianxia.recevier.http.HttpRecevierServer.java
License:Apache License
public static void startServer(int port) throws CertificateException, SSLException, InterruptedException { // Configure SSL. final SslContext sslCtx; if (SSL) {/*from www . j a v a 2 s. c om*/ 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.INFO)) .childHandler(new HttpRecevierServerInitializer(sslCtx)); b.bind(port).sync().channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.siondream.superjumper.net.SecureChatServer.java
License:Apache License
public static void main(String[] args) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(1); try {/*from w w w. j a va2 s. c om*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new SecureChatServerInitializer()); workerGroup.scheduleAtFixedRate(new ServerNetOptLoop(), 100000000, 100000000, TimeUnit.NANOSECONDS); b.bind(PORT).sync().channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.smoketurner.packet.application.config.NettyConfiguration.java
License:Apache License
@JsonIgnore public ChannelFuture build(@Nonnull final Environment environment, @Nonnull final Uploader uploader, @Nonnull final Size maxUploadSize) throws SSLException, CertificateException { // Configure SSL final SslContext sslCtx; if (ssl) {/*w w w . j a v a 2 s. c o m*/ if (selfSignedCert) { final SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); } else { sslCtx = SslContextBuilder.forServer(new File(keyCertChainFile), new File(keyFile)).build(); } } else { sslCtx = null; } final UploadInitializer initializer = new UploadInitializer(sslCtx, uploader, maxLength.toBytes(), maxUploadSize.toBytes()); final EventLoopGroup bossGroup; final EventLoopGroup workerGroup; if (Epoll.isAvailable()) { LOGGER.info("Using epoll event loop"); bossGroup = new EpollEventLoopGroup(1); workerGroup = new EpollEventLoopGroup(); } else { LOGGER.info("Using NIO event loop"); bossGroup = new NioEventLoopGroup(1); workerGroup = new NioEventLoopGroup(); } environment.lifecycle().manage(new EventLoopGroupManager(bossGroup)); environment.lifecycle().manage(new EventLoopGroupManager(workerGroup)); final ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.group(bossGroup, workerGroup).handler(new LoggingHandler(LogLevel.INFO)) .option(ChannelOption.SO_BACKLOG, 100).childOption(ChannelOption.SO_KEEPALIVE, true) .childHandler(initializer); if (Epoll.isAvailable()) { bootstrap.channel(EpollServerSocketChannel.class); } else { bootstrap.channel(NioServerSocketChannel.class); } // Start the server final ChannelFuture future = bootstrap.bind(listenPort); environment.lifecycle().manage(new ChannelFutureManager(future)); return future; }
From source file:com.splicemachine.stream.StreamListenerServer.java
License:Apache License
public void start() throws StandardException { ThreadFactory tf = new ThreadFactoryBuilder().setDaemon(true) .setNameFormat("StreamerListenerServer-boss-%s").build(); this.bossGroup = new NioEventLoopGroup(4, tf); tf = new ThreadFactoryBuilder().setDaemon(true).setNameFormat("StreamerListenerServer-worker-%s").build(); this.workerGroup = new NioEventLoopGroup(4, tf); try {/*from w w w . j a va 2 s.co m*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new OpenHandler(this)) .option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true); // Bind and start to accept incoming connections. ChannelFuture f = b.bind(port).sync(); this.serverChannel = f.channel(); InetSocketAddress socketAddress = (InetSocketAddress) this.serverChannel.localAddress(); String host = InetAddress.getLocalHost().getHostName(); int port = socketAddress.getPort(); this.hostAndPort = HostAndPort.fromParts(host, port); LOG.info("StreamListenerServer listening on " + hostAndPort); } catch (IOException e) { throw Exceptions.parseException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } }
From source file:com.springapp.mvc.netty.example.localecho.LocalEcho.java
License:Apache License
public static void main(String[] args) throws Exception { // Address to bind on / connect to. final LocalAddress addr = new LocalAddress(PORT); EventLoopGroup serverGroup = new LocalEventLoopGroup(); EventLoopGroup clientGroup = new NioEventLoopGroup(); // NIO event loops are also OK try {/*from ww w . j a v a2 s. c om*/ // Note that we can use any event loop to ensure certain local channels // are handled by the same event loop thread which drives a certain socket channel // to reduce the communication latency between socket channels and local channels. ServerBootstrap sb = new ServerBootstrap(); sb.group(serverGroup).channel(LocalServerChannel.class) .handler(new ChannelInitializer<LocalServerChannel>() { @Override public void initChannel(LocalServerChannel ch) throws Exception { ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO)); } }).childHandler(new ChannelInitializer<LocalChannel>() { @Override public void initChannel(LocalChannel ch) throws Exception { ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO), new LocalEchoServerHandler()); } }); Bootstrap cb = new Bootstrap(); cb.group(clientGroup).channel(LocalChannel.class).handler(new ChannelInitializer<LocalChannel>() { @Override public void initChannel(LocalChannel ch) throws Exception { ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO), new LocalEchoClientHandler()); } }); // Start the server. sb.bind(addr).sync(); // Start the client. Channel ch = cb.connect(addr).sync().channel(); // Read commands from the stdin. System.out.println("Enter text (quit to end)"); ChannelFuture lastWriteFuture = null; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); for (;;) { String line = in.readLine(); if (line == null || "quit".equalsIgnoreCase(line)) { break; } // Sends the received line to the server. lastWriteFuture = ch.writeAndFlush(line); } // Wait until all messages are flushed before closing the channel. if (lastWriteFuture != null) { lastWriteFuture.awaitUninterruptibly(); } } finally { serverGroup.shutdownGracefully(); clientGroup.shutdownGracefully(); } }
From source file:com.springapp.mvc.netty.example.spdy.server.SpdyServer.java
License:Apache License
public static void main(String[] args) throws Exception { // Configure SSL. SelfSignedCertificate ssc = new SelfSignedCertificate(); SslContext sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) .applicationProtocolConfig(//from w ww . ja v a2 s . c o m new ApplicationProtocolConfig(Protocol.NPN, SelectorFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, SelectedListenerFailureBehavior.CHOOSE_MY_LAST_PROTOCOL, SelectedProtocol.SPDY_3_1.protocolName(), SelectedProtocol.HTTP_1_1.protocolName())) .build(); // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.option(ChannelOption.SO_BACKLOG, 1024); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new SpdyServerInitializer(sslCtx)); Channel ch = b.bind(PORT).sync().channel(); System.err .println("Open your SPDY-enabled web browser and navigate to https://127.0.0.1:" + PORT + '/'); System.err.println("If using Chrome browser, check your SPDY sessions at chrome://net-internals/#spdy"); ch.closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.srotya.linea.network.InternalTCPTransportServer.java
License:Apache License
public void init() throws Exception { final SslContext sslCtx; if (SSL) {//w w w. jav a2 s .c o m SelfSignedCertificate ssc = new SelfSignedCertificate(); sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build(); } else { sslCtx = null; } EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(1); ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc())); } p.addLast(new LoggingHandler(LogLevel.INFO)); p.addLast(new KryoObjectEncoder()); p.addLast(new KryoObjectDecoder()); p.addLast(new IWCHandler(null)); //TODO add router } }).bind(Inet4Address.getByName("localhost"), 9999).sync().channel().closeFuture().await(); }
From source file:com.system.distribute.server.FileServer.java
License:Apache License
public void run() throws Exception { // Configure the server. EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {// w ww.ja v a 2 s. co m ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new StringEncoder(CharsetUtil.UTF_8), new LineBasedFrameDecoder(8192), new StringDecoder(CharsetUtil.UTF_8), new FileHandler()); } }); // Start the server. ChannelFuture f = b.bind(port).sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); } finally { // Shut down all event loops to terminate all threads. bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.tch.test.chat.netty.NettyServer.java
License:Apache License
public static void main(String[] args) throws Exception { EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup(); try {//from ww w.j a va 2s . c o m ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .handler(new LoggingHandler(LogLevel.INFO)).childHandler(new MyServerChannelInitializer()); b.bind(PORT).sync().channel().closeFuture().sync(); } finally { bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:com.tesora.dve.db.mysql.MysqlConnection.java
License:Open Source License
@Override public void connect(String url, final String userid, final String password, final long clientCapabilities) throws PEException { PEUrl peUrl = PEUrl.fromUrlString(url); if (!"mysql".equalsIgnoreCase(peUrl.getSubProtocol())) throw new PEException(MysqlConnection.class.getSimpleName() + " does not support the sub protocol of url \"" + url + "\""); InetSocketAddress serverAddress = new InetSocketAddress(peUrl.getHost(), peUrl.getPort()); final MyBackendDecoder.CharsetDecodeHelper charsetHelper = new CharsetDecodeHelper(); mysqlBootstrap = new Bootstrap(); mysqlBootstrap // .group(inboundChannel.eventLoop()) .channel(NioSocketChannel.class).group(connectionEventGroup) .option(ChannelOption.ALLOCATOR, USE_POOLED_BUFFERS ? PooledByteBufAllocator.DEFAULT : UnpooledByteBufAllocator.DEFAULT) .handler(new ChannelInitializer<Channel>() { @Override/*from w ww. j a v a2s .c o m*/ protected void initChannel(Channel ch) throws Exception { authHandler = new MysqlClientAuthenticationHandler(new UserCredentials(userid, password), clientCapabilities, NativeCharSetCatalogImpl.getDefaultCharSetCatalog(DBType.MYSQL), targetCharset); if (PACKET_LOGGER) ch.pipeline().addLast(new LoggingHandler(LogLevel.INFO)); ch.pipeline().addLast(authHandler) .addLast(MyBackendDecoder.class.getSimpleName(), new MyBackendDecoder(site.getName(), charsetHelper)) .addLast(StreamValve.class.getSimpleName(), new StreamValve()) .addLast(MysqlCommandSenderHandler.class.getSimpleName(), new MysqlCommandSenderHandler(site)); } }); pendingConnection = mysqlBootstrap.connect(serverAddress); // System.out.println("Create connection: Allocated " + totalConnections.incrementAndGet() + ", active " + activeConnections.incrementAndGet()); channel = pendingConnection.channel(); physicalID = UUID.randomUUID(); //TODO: this was moved from execute to connect, which avoids blocking on the execute to be netty friendly, but causes lag on checkout. Should make this event driven like everything else. -sgossard syncToServerConnect(); authHandler.assertAuthenticated(); // channel.closeFuture().addListener(new GenericFutureListener<Future<Void>>() { // @Override // public void operationComplete(Future<Void> future) throws Exception { // System.out.println(channel + " is closed"); // } // }); }