|
@@ -14,8 +14,6 @@ import io.netty.handler.timeout.ReadTimeoutHandler;
|
|
|
import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
|
import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
|
|
import io.netty.util.concurrent.EventExecutorGroup;
|
|
import io.netty.util.concurrent.EventExecutorGroup;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.slf4j.Logger;
|
|
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
@@ -26,20 +24,19 @@ public class NettyServerThread {
|
|
|
@Value("${netty.port}")
|
|
@Value("${netty.port}")
|
|
|
private int port;
|
|
private int port;
|
|
|
@Value("${collection.worker-threads:16}")
|
|
@Value("${collection.worker-threads:16}")
|
|
|
- private int businessThreads = 16;
|
|
|
|
|
|
|
+ private int businessThreads;
|
|
|
@Value("${device.connection.read-timeout-seconds:60}")
|
|
@Value("${device.connection.read-timeout-seconds:60}")
|
|
|
- private int connectionReadTimeoutSeconds = 60;
|
|
|
|
|
|
|
+ private int connectionReadTimeoutSeconds;
|
|
|
// 厂家handler.txt支持80KiB无头PCM,收齐后补WAV头;带头WAV仍按RIFF长度接收。
|
|
// 厂家handler.txt支持80KiB无头PCM,收齐后补WAV头;带头WAV仍按RIFF长度接收。
|
|
|
@Value("${wlds.raw-pcm-bytes:81920}")
|
|
@Value("${wlds.raw-pcm-bytes:81920}")
|
|
|
- private int rawPcmBytes = 80 * 1024;
|
|
|
|
|
- private static Logger logger = LoggerFactory.getLogger(NettyServerThread.class);
|
|
|
|
|
|
|
+ private int rawPcmBytes;
|
|
|
private final MessageHandler messageHandler;
|
|
private final MessageHandler messageHandler;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
public NettyServerThread(MessageHandler messageHandler) {
|
|
public NettyServerThread(MessageHandler messageHandler) {
|
|
|
this.messageHandler = messageHandler;
|
|
this.messageHandler = messageHandler;
|
|
|
}
|
|
}
|
|
|
public void startServer() {
|
|
public void startServer() {
|
|
|
- System.out.println("Netty服务启动端口号" + port);
|
|
|
|
|
|
|
+ log.info("Netty服务启动端口号{}", port);
|
|
|
EventLoopGroup acceptor = new NioEventLoopGroup();
|
|
EventLoopGroup acceptor = new NioEventLoopGroup();
|
|
|
EventLoopGroup worker = new NioEventLoopGroup();
|
|
EventLoopGroup worker = new NioEventLoopGroup();
|
|
|
EventExecutorGroup business = new DefaultEventExecutorGroup(businessThreads, null, 1024, io.netty.util.concurrent.RejectedExecutionHandlers.reject());
|
|
EventExecutorGroup business = new DefaultEventExecutorGroup(businessThreads, null, 1024, io.netty.util.concurrent.RejectedExecutionHandlers.reject());
|
|
@@ -61,7 +58,7 @@ public class NettyServerThread {
|
|
|
bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
|
|
bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
|
|
|
@Override
|
|
@Override
|
|
|
public void initChannel(SocketChannel ch) throws Exception {
|
|
public void initChannel(SocketChannel ch) throws Exception {
|
|
|
- logger.info("来自" + ch.remoteAddress() + "的新连接接入");
|
|
|
|
|
|
|
+ log.info("来自{}的新连接接入", ch.remoteAddress());
|
|
|
// 注册handler
|
|
// 注册handler
|
|
|
configurePipeline(ch.pipeline(), business);
|
|
configurePipeline(ch.pipeline(), business);
|
|
|
}
|
|
}
|
|
@@ -74,15 +71,12 @@ public class NettyServerThread {
|
|
|
// 等待服务器 socket 关闭 。
|
|
// 等待服务器 socket 关闭 。
|
|
|
f.channel().closeFuture().sync();
|
|
f.channel().closeFuture().sync();
|
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
|
|
+ log.error("Netty服务启动被中断", e);
|
|
|
} finally {
|
|
} finally {
|
|
|
business.shutdownGracefully();
|
|
business.shutdownGracefully();
|
|
|
- if (acceptor != null) {
|
|
|
|
|
- acceptor.shutdownGracefully();
|
|
|
|
|
- }
|
|
|
|
|
- if (worker != null) {
|
|
|
|
|
- worker.shutdownGracefully();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ acceptor.shutdownGracefully();
|
|
|
|
|
+ worker.shutdownGracefully();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|