|
@@ -1,6 +1,7 @@
|
|
-package com.tidecloud.dataacceptance.service.handle;
|
|
|
|
|
|
+package com.tidecloud.dataacceptance.service.impl;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import javax.xml.bind.DatatypeConverter;
|
|
import javax.xml.bind.DatatypeConverter;
|
|
|
|
|
|
@@ -23,15 +24,26 @@ import com.tidecloud.dataacceptance.entity.Session;
|
|
import com.tidecloud.dataacceptance.entity.SessionManager;
|
|
import com.tidecloud.dataacceptance.entity.SessionManager;
|
|
import com.tidecloud.dataacceptance.entity.TerminalAuthenticationMsg;
|
|
import com.tidecloud.dataacceptance.entity.TerminalAuthenticationMsg;
|
|
import com.tidecloud.dataacceptance.entity.TerminalRegisterMsg;
|
|
import com.tidecloud.dataacceptance.entity.TerminalRegisterMsg;
|
|
|
|
+import com.tidecloud.dataacceptance.service.AcceptanceInboundHandlerAdapter;
|
|
import com.tidecloud.dataacceptance.service.TerminalMsgProcessService;
|
|
import com.tidecloud.dataacceptance.service.TerminalMsgProcessService;
|
|
|
|
|
|
|
|
+import io.netty.bootstrap.ServerBootstrap;
|
|
import io.netty.buffer.ByteBuf;
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
+import io.netty.buffer.Unpooled;
|
|
import io.netty.channel.Channel;
|
|
import io.netty.channel.Channel;
|
|
|
|
+import io.netty.channel.ChannelFuture;
|
|
import io.netty.channel.ChannelHandler;
|
|
import io.netty.channel.ChannelHandler;
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
-import io.netty.channel.ChannelInboundHandlerAdapter;
|
|
|
|
|
|
+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.timeout.IdleState;
|
|
import io.netty.handler.timeout.IdleState;
|
|
import io.netty.handler.timeout.IdleStateEvent;
|
|
import io.netty.handler.timeout.IdleStateEvent;
|
|
|
|
+import io.netty.handler.timeout.IdleStateHandler;
|
|
import redis.clients.jedis.Jedis;
|
|
import redis.clients.jedis.Jedis;
|
|
import redis.clients.jedis.JedisPool;
|
|
import redis.clients.jedis.JedisPool;
|
|
|
|
|
|
@@ -40,9 +52,9 @@ import redis.clients.jedis.JedisPool;
|
|
*/
|
|
*/
|
|
@Component
|
|
@Component
|
|
@ChannelHandler.Sharable
|
|
@ChannelHandler.Sharable
|
|
-public class YiTongGpsServerHandler extends ChannelInboundHandlerAdapter {
|
|
|
|
|
|
+public class BSJGpsServerHandler extends AcceptanceInboundHandlerAdapter {
|
|
|
|
|
|
- private static final Logger logger = LoggerFactory.getLogger(YiTongGpsServerHandler.class);
|
|
|
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(BSJGpsServerHandler.class);
|
|
public static String PREFIX_LINK = "s.";
|
|
public static String PREFIX_LINK = "s.";
|
|
public static String PREFIX_LINK_BACK = "s.b.";
|
|
public static String PREFIX_LINK_BACK = "s.b.";
|
|
public static String PREFIX_DEVICE = "d.";
|
|
public static String PREFIX_DEVICE = "d.";
|
|
@@ -64,7 +76,7 @@ public class YiTongGpsServerHandler extends ChannelInboundHandlerAdapter {
|
|
* @Title: YiTongGpsServerHandler
|
|
* @Title: YiTongGpsServerHandler
|
|
* @Description: initialzation sessionManager and msgDecoder
|
|
* @Description: initialzation sessionManager and msgDecoder
|
|
*/
|
|
*/
|
|
- public YiTongGpsServerHandler() {
|
|
|
|
|
|
+ public BSJGpsServerHandler() {
|
|
this.sessionManager = SessionManager.getInstance();
|
|
this.sessionManager = SessionManager.getInstance();
|
|
this.decoder = new MsgDecoder();
|
|
this.decoder = new MsgDecoder();
|
|
this.msgProcessService = new TerminalMsgProcessService();
|
|
this.msgProcessService = new TerminalMsgProcessService();
|
|
@@ -283,4 +295,42 @@ public class YiTongGpsServerHandler extends ChannelInboundHandlerAdapter {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void startAcceptor() {
|
|
|
|
+ EventLoopGroup bossGroup = new NioEventLoopGroup();
|
|
|
|
+ EventLoopGroup workerGroup = new NioEventLoopGroup();
|
|
|
|
+ byte[] splitBytes1 = new byte[]{0x7e};
|
|
|
|
+ byte[] splitBytes2 = new byte[]{0x7e, 0x7e};
|
|
|
|
+ try {
|
|
|
|
+ ServerBootstrap b = new ServerBootstrap();
|
|
|
|
+ b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
|
|
|
|
+ .childHandler(new ChannelInitializer<SocketChannel>() {
|
|
|
|
+ @Override
|
|
|
|
+ protected void initChannel(SocketChannel ch) throws Exception {
|
|
|
|
+ ch.pipeline().addLast("idleStateHandler",
|
|
|
|
+ new IdleStateHandler(Constants.TCP_CLIENT_IDLE_MINUTES, 0, 0, TimeUnit.MINUTES));
|
|
|
|
+
|
|
|
|
+ ch.pipeline().addLast(new DelimiterBasedFrameDecoder(1204, Unpooled.copiedBuffer(splitBytes1),
|
|
|
|
+ Unpooled.copiedBuffer(splitBytes2)));
|
|
|
|
+ ch.pipeline().addLast(this);
|
|
|
|
+ }
|
|
|
|
+ }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
|
|
|
|
+
|
|
|
|
+ ChannelFuture f = b.bind(this.getPort()).sync();
|
|
|
|
+ logger.info("start accept service for {}, bind address {}:{}", this.getPrefixName(), this.getIp(),
|
|
|
|
+ this.getPort());
|
|
|
|
+ f.channel().closeFuture().sync();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ logger.error(e.getMessage());
|
|
|
|
+ } finally {
|
|
|
|
+ workerGroup.shutdownGracefully();
|
|
|
|
+ bossGroup.shutdownGracefully();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void reply(ChannelHandlerContext ctx, String msg) throws Exception {
|
|
|
|
+ // TODO Auto-generated method stub
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|