1. 重写格式化代码

This commit is contained in:
HuangXin 2023-08-12 12:48:50 +08:00
parent 3eb0572969
commit 38f8973963
5 changed files with 31 additions and 15 deletions

View File

@ -28,9 +28,12 @@ public class ChannelInit<T> extends ChannelInitializer<SocketChannel> {
@Override
protected void initChannel(SocketChannel channel) {
channel.pipeline().addLast("idle", new IdleStateHandler(0, 0, 60, TimeUnit.SECONDS)).addLast("decode",
channel.pipeline()
.addLast("idle", new IdleStateHandler(0, 0, 60, TimeUnit.SECONDS))
.addLast("decode",
new YuanRongProtocolDecode())
.addLast("startFlag", new ProtocolStartEncode(2)).addLast("encode", new YuanRongProtocolEncode<T>())
.addLast("startFlag", new ProtocolStartEncode(2))
.addLast("encode", new YuanRongProtocolEncode<T>())
.addLast("message", messageHandler);
}
}

View File

@ -46,9 +46,11 @@ public class MessageHandler<T> extends SimpleChannelInboundHandler<BaseBinaryPro
if (evt instanceof IdleStateEvent idleStateEvent) {
if (idleStateEvent.state() == IdleState.ALL_IDLE) {
log.info("{}:: Trigger Heart Signe", ctx.channel().id());
MessageContent<HeartProtocol> msgCont = MessageContent.<HeartProtocol>builder().msgBody(
new HeartProtocol()).build();
BaseBinaryProtocol<HeartProtocol> h = BaseBinaryProtocol.<HeartProtocol>builder().msgContent(msgCont)
MessageContent<HeartProtocol> msgCont = MessageContent.<HeartProtocol>builder()
.msgBody(new HeartProtocol())
.build();
BaseBinaryProtocol<HeartProtocol> h = BaseBinaryProtocol.<HeartProtocol>builder()
.msgContent(msgCont)
.build();
ctx.writeAndFlush(h);
@ -73,9 +75,12 @@ public class MessageHandler<T> extends SimpleChannelInboundHandler<BaseBinaryPro
InetSocketAddress sa = (InetSocketAddress) ctx.channel().remoteAddress();
//List<ControlDevice> list = controlDeviceMapper.selectAll();
log.info("{}:: Connected <-- {}:{}", ctx.channel().id(), sa.getAddress().getHostAddress(), sa.getPort());
controlDeviceMapper.addControlDevice(ControlDevice.builder().deviceType(ControlDeviceTypeName.DEVICE_SOCKET_TCP)
.deviceAddr(sa.getAddress().getHostAddress()).build());
MessageContent<HeartProtocol> msgCont = MessageContent.<HeartProtocol>builder().msgBody(new HeartProtocol())
controlDeviceMapper.addControlDevice(ControlDevice.builder()
.deviceType(ControlDeviceTypeName.DEVICE_SOCKET_TCP)
.deviceAddr(sa.getAddress().getHostAddress())
.build());
MessageContent<HeartProtocol> msgCont = MessageContent.<HeartProtocol>builder()
.msgBody(new HeartProtocol())
.build();
BaseBinaryProtocol<HeartProtocol> h = BaseBinaryProtocol.<HeartProtocol>builder().msgContent(msgCont).build();

View File

@ -23,7 +23,8 @@ import org.springframework.stereotype.Component;
@Slf4j
public class YuanRongProtocolEncode<T> extends MessageToByteEncoder<BaseBinaryProtocol<T>> {
@Override
protected void encode(ChannelHandlerContext channelHandlerContext, BaseBinaryProtocol<T> baseBinaryProtocol,
protected void encode(ChannelHandlerContext channelHandlerContext,
BaseBinaryProtocol<T> baseBinaryProtocol,
ByteBuf byteBuf) {
if (baseBinaryProtocol == null || baseBinaryProtocol.getMsgContent() == null ||

View File

@ -51,10 +51,15 @@ public class TcpServer implements ISocketServer {
*/
private void tcpServer(int port) {
try {
new ServerBootstrap().group(boosGroup, workerGroup).channel(NioServerSocketChannel.class).localAddress(
new InetSocketAddress(port)).childHandler(channelInit).option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.TCP_NODELAY, false).childOption(ChannelOption.SO_KEEPALIVE,
true).bind().sync();
new ServerBootstrap().group(boosGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.localAddress(new InetSocketAddress(port))
.childHandler(channelInit)
.option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.TCP_NODELAY, false)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.bind()
.sync();
log.info("Netty TCP Server Beginning Listen: {}", port);
} catch (Exception e) {
log.error(e.getMessage());

View File

@ -69,7 +69,9 @@ public final class CommonEnumHandler<E extends EnumerationBase> extends BaseType
* @throws SQLException the sql exception
*/
@Override
public void setNonNullParameter(PreparedStatement preparedStatement, int i, E e,
public void setNonNullParameter(PreparedStatement preparedStatement,
int i,
E e,
JdbcType jdbcType) throws SQLException {
preparedStatement.setInt(i, e.getValue());
}