当前位置: 首页>>代码示例>>Java>>正文


Java LoggingHandler类代码示例

本文整理汇总了Java中io.netty.handler.logging.LoggingHandler的典型用法代码示例。如果您正苦于以下问题:Java LoggingHandler类的具体用法?Java LoggingHandler怎么用?Java LoggingHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LoggingHandler类属于io.netty.handler.logging包,在下文中一共展示了LoggingHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: NettyServer

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
private NettyServer(){
	pGroup = new NioEventLoopGroup();
	cGroup = new NioEventLoopGroup();
	serverBootstrap = new ServerBootstrap();
	serverBootstrap.group(pGroup, cGroup)
	 .channel(NioServerSocketChannel.class)
	 .option(ChannelOption.SO_BACKLOG, 1024)
	 //设置日志
	 .handler(new LoggingHandler(LogLevel.INFO))
	 .childHandler(new ChannelInitializer<SocketChannel>() {
		protected void initChannel(SocketChannel sc) throws Exception {
			sc.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingDecoder());
			sc.pipeline().addLast(MarshallingCodeCFactory.buildMarshallingEncoder());
			sc.pipeline().addLast(new ReadTimeoutHandler(60));
			sc.pipeline().addLast(new NettyServerHandler());
		}
	});		
}
 
开发者ID:craware,项目名称:webapp-tyust,代码行数:19,代码来源:NettyServer.java

示例2: start

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
public void start(SlaveNode slaveNode) {
    if(slaveNode==null){
        throw new IllegalArgumentException("slaveNode is null");
    }
    EventLoopGroup bossGroup = new NioEventLoopGroup(CommonConstants.BOSS_GROUP_SIZE, new DefaultThreadFactory("boss", true));
    EventLoopGroup workerGroup = new NioEventLoopGroup(CommonConstants.WORKER_GROUP_SIZE, new DefaultThreadFactory("worker", true));
    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 SlaveServerInitializer());

        ChannelFuture future = b.bind(slaveNode.getPort()).sync();
        LOGGER.info("SlaveServer Startup at port:{}",slaveNode.getPort());

        // 等待服务端Socket关闭
        future.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        LOGGER.error("InterruptedException:",e);
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:all4you,项目名称:redant,代码行数:27,代码来源:SlaveServer.java

示例3: start

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
public void start() {
    EventLoopGroup bossGroup = new NioEventLoopGroup(CommonConstants.BOSS_GROUP_SIZE, new DefaultThreadFactory("boss", true));
    EventLoopGroup workerGroup = new NioEventLoopGroup(CommonConstants.WORKER_GROUP_SIZE, new DefaultThreadFactory("worker", true));
    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 MasterServerInitializer());

        ChannelFuture future = b.bind(CommonConstants.SERVER_PORT).sync();
        LOGGER.info("MasterServer Startup at port:{}",CommonConstants.SERVER_PORT);

        // 等待服务端Socket关闭
        future.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        LOGGER.error("InterruptedException:",e);
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:all4you,项目名称:redant,代码行数:24,代码来源:MasterServer.java

示例4: start

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
public void start() {
    EventLoopGroup bossGroup = new NioEventLoopGroup(CommonConstants.BOSS_GROUP_SIZE, new DefaultThreadFactory("boss", true));
    EventLoopGroup workerGroup = new NioEventLoopGroup(CommonConstants.WORKER_GROUP_SIZE, new DefaultThreadFactory("worker", true));
    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 ServerInitializer());

        ChannelFuture future = b.bind(CommonConstants.SERVER_PORT).sync();
        logger.info("NettyServer Startup at port:{}",CommonConstants.SERVER_PORT);

        // 等待服务端Socket关闭
        future.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        logger.error("InterruptedException:",e);
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:all4you,项目名称:redant,代码行数:24,代码来源:NettyServer.java

示例5: initChannel

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    pipeline.addLast(new LoggingHandler());
    // Add SSL handler first to encrypt and decrypt everything.
    // In this example, we use a bogus certificate in the server side
    // and accept any invalid certificates in the client side.
    // You will need something more complicated to identify both
    // and server in the real world.
    if (sslCtx != null)
        pipeline.addLast(sslCtx.newHandler(ch.alloc(), SecureChatClient.HOST, SecureChatClient.PORT));

    // On top of the SSL handler, add the text line codec.
    pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    pipeline.addLast(new StringDecoder());
    pipeline.addLast(new StringEncoder());

    // and then business logic.
    pipeline.addLast(new SecureChatClientHandler());
}
 
开发者ID:veritasware,项目名称:neto,代码行数:22,代码来源:SecureChatClientInitializer.java

示例6: run

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
public void run() {
    try {
        // Configure the server.
        EventLoopGroup group = new NioEventLoopGroup();
        try {
            ServerBootstrap b = new ServerBootstrap();
            b.option(ChannelOption.SO_BACKLOG, 1024);
            b.group(group)
                    .channel(NioServerSocketChannel.class)
                    .handler(new LoggingHandler(LogLevel.INFO))
                    .childHandler(new Http2ServerInitializer(mSslCtx));

            sServerChannel = b.bind(PORT).sync().channel();
            Log.i(TAG, "Netty HTTP/2 server started on " + getServerUrl());
            sBlock.open();
            sServerChannel.closeFuture().sync();
        } finally {
            group.shutdownGracefully();
        }
        Log.i(TAG, "Stopped Http2TestServerRunnable!");
    } catch (Exception e) {
        Log.e(TAG, e.toString());
    }
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:25,代码来源:Http2TestServer.java

示例7: init

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
/**
 * 初始化连接池
 */
public void init() {
    bootstrap = new Bootstrap();
    eventLoopGroup = new NioEventLoopGroup();
    bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class)
            .option(ChannelOption.SO_KEEPALIVE, true)
            .option(ChannelOption.TCP_NODELAY, true)
            .handler(new LoggingHandler());
    //所有的公用一个eventloopgroup, 对于客户端来说应该问题不大!
    poolMap = new AbstractChannelPoolMap<InetSocketAddress, FixedChannelPool>() {
        @Override
        protected FixedChannelPool newPool(InetSocketAddress key) {
            return new FixedChannelPool(bootstrap.remoteAddress(key), new FixedChannelPoolHandler(), 2);
        }
    };
    //预先建立好链接
    serverListConfig.getAddressList().stream().forEach(address -> {
        poolMap.get(address);
    });
}
 
开发者ID:recklessMo,项目名称:nettyRpc,代码行数:23,代码来源:ClientConnectionPool.java

示例8: start

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
@PostConstruct
public void start() {
    new Thread(() -> {
        logger.info("HttpProxyServer started on port: {}", port);
        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.DEBUG))
                    .childHandler(channelInitializer)
                    .bind(port).sync().channel().closeFuture().sync();
        } catch (InterruptedException e) {
            logger.error("shit happens", e);
        } finally {
            bossGroup.shutdownGracefully();
            workerGroup.shutdownGracefully();
        }
    }).start();
}
 
开发者ID:shuaicj,项目名称:http-proxy-netty,代码行数:22,代码来源:HttpProxyServer.java

示例9: start

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
@Override
public synchronized void start() {
    bossGroup = new NioEventLoopGroup(); // (1)
    workerGroup = new NioEventLoopGroup();
    try {
        b = new ServerBootstrap(); // (2)
        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 100)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new SocketServerChannelInitializer(heartTime,socketService,applicationContext));
        // Bind and start to accept incoming connections.
        b.bind(port);

        logger.info("socket: "+port+" starting....");
        // Wait until the server socket is closed.
        // In this example, this does not happen, but you can do that to gracefully
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:1991wangliang,项目名称:sds,代码行数:22,代码来源:NettyServerServiceImpl.java

示例10: initChannel

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
@Override
    public void initChannel(SocketChannel ch) throws Exception {
        // Create a default pipeline implementation.
        ChannelPipeline p = ch.pipeline();

        p.addLast("log", new LoggingHandler(LogLevel.INFO));
        // Enable HTTPS if necessary.
/*        if (ssl) {
            SSLEngine engine =
                SecureChatSslContextFactory.getClientContext().createSSLEngine();
            engine.setUseClientMode(true);

            p.addLast("ssl", new SslHandler(engine));
        }*/

        p.addLast("codec", new HttpClientCodec());

        // Remove the following line if you don't want automatic content decompression.
        p.addLast("inflater", new HttpContentDecompressor());

        // Uncomment the following line if you don't want to handle HttpChunks.
        //p.addLast("aggregator", new HttpObjectAggregator(1048576));

        p.addLast("handler", new HttpSnoopClientHandler());
    }
 
开发者ID:eBay,项目名称:ServiceCOLDCache,代码行数:26,代码来源:HttpSnoopClientInitializer.java

示例11: bind

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
public void bind(int port) throws Exception {
	EventLoopGroup bossGroup = new NioEventLoopGroup();
	EventLoopGroup workerGroup = new NioEventLoopGroup();
	try{
		ServerBootstrap b = new ServerBootstrap();
		b.group(bossGroup, workerGroup)
		.channel(NioServerSocketChannel.class)
		.option(ChannelOption.SO_BACKLOG, 1024)
		.handler(new LoggingHandler(LogLevel.INFO))
		.childHandler(new ChildChannelHandler());
		// 绑定端口 同步等待成功
		ChannelFuture f = b.bind(port).sync();
		// 等待服务端监听端口关闭
		f.channel().closeFuture().sync ();
	}finally{
		//优雅的退出 释放线程池资源
		bossGroup.shutdownGracefully();
		workerGroup.shutdownGracefully();
	}
	
}
 
开发者ID:hdcuican,项目名称:java_learn,代码行数:22,代码来源:SubReqServer.java

示例12: channelRegistered

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
/**
 * Called once the TCP connection is established.
 * Configures the per-connection pipeline that is responsible for handling incoming and outgoing data.
 * After an incoming packet is decrypted, decoded and verified,
 * it will be sent to its target {@link de.unipassau.isl.evs.ssh.core.handler.MessageHandler}
 * by the {@link IncomingDispatcher}.
 */
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
    Log.v(TAG, "channelRegistered " + ctx);
    ctx.attr(ATTR_HANDSHAKE_FINISHED).set(false);

    // Add (de-)serialization Handlers before this Handler
    ctx.pipeline().addBefore(ctx.name(), ObjectEncoder.class.getSimpleName(), new ObjectEncoder());
    ctx.pipeline().addBefore(ctx.name(), ObjectDecoder.class.getSimpleName(), new ObjectDecoder(
            ClassResolvers.weakCachingConcurrentResolver(getClass().getClassLoader())));
    ctx.pipeline().addBefore(ctx.name(), LoggingHandler.class.getSimpleName(), new LoggingHandler(LogLevel.TRACE));

    // Timeout Handler
    ctx.pipeline().addBefore(ctx.name(), IdleStateHandler.class.getSimpleName(),
            new IdleStateHandler(READER_IDLE_TIME, WRITER_IDLE_TIME, ALL_IDLE_TIME));
    ctx.pipeline().addBefore(ctx.name(), TimeoutHandler.class.getSimpleName(), new TimeoutHandler());

    // Add exception handler
    ctx.pipeline().addAfter(ctx.name(), PipelinePlug.class.getSimpleName(), new PipelinePlug());

    super.channelRegistered(ctx);
    Log.v(TAG, "Pipeline after register: " + ctx.pipeline());
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:30,代码来源:ClientHandshakeHandler.java

示例13: start

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
@Override
public void start() {
	ServerBootstrap bootstrap = new ServerBootstrap();
	bootstrap.group(bossGroup, workerGroup)
			.channel(NioServerSocketChannel.class)
			.childHandler(new ChannelInitializer<SocketChannel>() {
				protected void initChannel(SocketChannel ch) throws Exception {
					ch.pipeline()
							.addLast(new LoggingHandler(LogLevel.INFO))
							.addLast(new ProtocolDecoder(10 * 1024 * 1024))
							.addLast(new ProtocolEncoder())
							.addLast(new RpcServerHandler(serviceImpl))
					;
				}
			});
	try {
		ChannelFuture sync = bootstrap.bind(port).sync();
		registerService();
		LOGGER.info("Server Started At {}", port);
		started = true;
		this.channel = sync.channel();
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
}
 
开发者ID:liuzhengyang,项目名称:simple-rpc,代码行数:26,代码来源:ServerImpl.java

示例14: start

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
public void start(int port, ChannelHandler channelInitializer, int bossThreads, int workThreads)
		throws Exception {
	bossGroup = new NioEventLoopGroup(bossThreads);
	workerGroup = new NioEventLoopGroup(workThreads);
	try {
		ServerBootstrap b = new ServerBootstrap();
		b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
				.option(ChannelOption.SO_BACKLOG, Integer.parseInt(System.getProperty("so.BACKLOG", "100")))
				// .option(ChannelOption.SO_KEEPALIVE,
				// Boolean.parseBoolean(System.getProperty("so.KEEPALIVE",
				// "true")))
				// .option(ChannelOption.SO_LINGER,
				// Integer.parseInt(System.getProperty("so.LINGER", "0")))
				.option(ChannelOption.SO_REUSEADDR,
						Boolean.parseBoolean(System.getProperty("so.REUSEADDR", "true")))
				 .handler(new LoggingHandler(LogLevel.DEBUG))
				.childHandler(channelInitializer);
		f = b.bind(port).sync();
		logger.info("Server started and listen on port:{}", port);
		f.channel().closeFuture().sync();
	} finally {
		close_();
	}
}
 
开发者ID:houkx,项目名称:nettythrift,代码行数:25,代码来源:CommonServer.java

示例15: NetworkServiceImpl

import io.netty.handler.logging.LoggingHandler; //导入依赖的package包/类
NetworkServiceImpl(final NetworkServiceBuilder builder) {
    int bossLoopGroupCount = builder.getBossLoopGroupCount();
    int workerLoopGroupCount = builder.getWorkerLoopGroupCount();
    this.port = builder.getPort();

    bossGroup = new NioEventLoopGroup(bossLoopGroupCount);
    workerGroup = new NioEventLoopGroup(workerLoopGroupCount);

    bootstrap = new ServerBootstrap();
    bootstrap.group(bossGroup, workerGroup);
    bootstrap.channel(NioServerSocketChannel.class);
    bootstrap.option(ChannelOption.SO_BACKLOG, 1024);
    bootstrap.childOption(ChannelOption.TCP_NODELAY, true);
    bootstrap.childOption(ChannelOption.SO_RCVBUF, 128 * 1024);
    bootstrap.childOption(ChannelOption.SO_SNDBUF, 128 * 1024);

    bootstrap.handler(new LoggingHandler(LogLevel.DEBUG));
    if (builder.isWebSocket()) {
        bootstrap.childHandler(new WebSocketHandler(builder));
    } else {
        bootstrap.childHandler(new SocketHandler(builder));
    }
}
 
开发者ID:beimi,项目名称:ServerCore,代码行数:24,代码来源:NetworkServiceImpl.java


注:本文中的io.netty.handler.logging.LoggingHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。