eclipse配置lombok插件

1.pom.xml


        
            org.projectlombok
            lombok
            true
        


或者用



		
			org.projectlombok
			lombok
			1.18.6
			provided
		

 

 

2.代码应用

package com.cloudtech.server;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.cloudtech.util.Consts;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.timeout.IdleStateHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * 
* @ClassName: Server  
* @Description:netty服务端   
* @author wude  
* @date 2018年9月7日  
*
 */
@Slf4j
public class Server {

	/**
	 * 启动
	 */
	public void start(int port) {

		// 服务类
		ServerBootstrap b = new ServerBootstrap();

		// 创建boss和worker
		EventLoopGroup bossGroup = new NioEventLoopGroup();
 		EventLoopGroup workerGroup = new NioEventLoopGroup();
		//业务线程池,实现消息串行化
		EventLoopGroup busyGroup = new NioEventLoopGroup();

		try {
			// 设置循环线程组事例
			b.group(bossGroup, workerGroup);

			// 设置channel工厂
			b.channel(NioServerSocketChannel.class);

			// 设置管道
			b.childHandler(new ChannelInitializer() {
				@Override
				public void initChannel(SocketChannel ch) throws Exception {
					//第一个参数 读超时
					//第二个参数 写超时
					//第三个参数读写超时
					ch.pipeline().addLast(new IdleStateHandler(5, 5, 60));
					ByteBuf delimiter = Unpooled.copiedBuffer(")".getBytes());
					ch.pipeline().addLast(new DelimiterBasedFrameDecoder(Consts.MAX_BUFF_LEN,delimiter));
					ch.pipeline().addLast(new StringDecoder());
					ch.pipeline().addLast(busyGroup,new ServerHandler());
				}
			});

			b.option(ChannelOption.SO_BACKLOG, 2048);//serverSocketchannel的设置,链接缓冲池的大小
			b.childOption(ChannelOption.SO_KEEPALIVE, true);//socketchannel的设置,维持链接的活跃,清除死链接
			b.childOption(ChannelOption.TCP_NODELAY, true);//socketchannel的设置,关闭延迟发送

			log.info("启动梯度塔秒级站采集成功!port={}",port);
			//绑定端口
			ChannelFuture future = b.bind(port);
			
			//等待服务端关闭
			future.channel().closeFuture().sync();
			
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			//释放资源
			bossGroup.shutdownGracefully();
			workerGroup.shutdownGracefully();
			busyGroup.shutdownGracefully();
		}
	}

}

在类上增加@Slf4j注解,就可以在代码中通过log调用日志的一些方法

你可能感兴趣的:(eclipse)