rainbow954 há 7 anos atrás
pai
commit
5805bfe99e

+ 5 - 11
src/main/java/com/tidecloud/dataacceptance/service/AcceptanceInboundHandlerAdapter.java

@@ -96,10 +96,6 @@ public  class AcceptanceInboundHandlerAdapter extends ChannelInboundHandlerAdapt
 
 	
 
-	
-	
-	
-
 	protected void receiveMsg(String msg, String deviceId, Channel channel) {
 		manageChannel(channel, deviceId);
 		kafkaSendThreadPool.execute(() -> sendKakfaMsg(msg, deviceId));
@@ -118,8 +114,8 @@ public  class AcceptanceInboundHandlerAdapter extends ChannelInboundHandlerAdapt
 		channelDeviceMap.put(channel, deviceId);
 		String addressStr = ConnectMsg.ipToLong(ip);
 		ConnectMsg cMsg = new ConnectMsg(ip, socketkey);
-		Jedis jedis = jedisPool.getResource();
-		try {
+		
+		try (Jedis jedis = jedisPool.getResource()){
 			jedis.select(REDIS_INDEX_LINK);
 			String insertKey = PREFIX_LINK + addressStr;
 			String selectKey = PREFIX_DEVICE + deviceId;
@@ -128,9 +124,7 @@ public  class AcceptanceInboundHandlerAdapter extends ChannelInboundHandlerAdapt
 			jedis.sadd(insertBackupKey, deviceId);
 			jedis.set(selectKey, StringUtil.convert2String(cMsg));
 		} catch (Exception e) {
-			e.printStackTrace();
-		} finally {
-			jedis.close();
+			logger.error(e.getMessage());
 		}
 	}
 
@@ -305,7 +299,7 @@ public  class AcceptanceInboundHandlerAdapter extends ChannelInboundHandlerAdapt
 						@Override
 						protected void initChannel(SocketChannel ch) throws Exception {
 							ch.pipeline().addLast("idleStateHandler", new IdleStateHandler(10, 0, 0, TimeUnit.MINUTES));
-							ch.pipeline().addLast(this);
+							ch.pipeline().addLast(AcceptanceInboundHandlerAdapter.this);
 						}
 					}).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
 
@@ -316,7 +310,7 @@ public  class AcceptanceInboundHandlerAdapter extends ChannelInboundHandlerAdapt
 		} catch (Exception e) {
 			logger.error(e.getMessage());
 		} finally {
-			cleanRedisLinkData();
+		//	cleanRedisLinkData();
 			workerGroup.shutdownGracefully();
 			bossGroup.shutdownGracefully();
 		}

+ 24 - 9
src/main/java/com/tidecloud/dataacceptance/service/impl/WatchServerHandler.java

@@ -33,7 +33,6 @@ public class WatchServerHandler extends StringAcceptanceHandlerAdapter {
 	private static final Logger logger = LoggerFactory.getLogger(WatchServerHandler.class);
 
 	public void handle(String msg, Channel channel) throws Exception {
-		logger.info("设备上传数据:" + msg);
 		Advice advice = getAdevice(msg);
 		String deviceId = advice.getDeviceId();
 		String adviceType = advice.getAdviceType();
@@ -44,7 +43,7 @@ public class WatchServerHandler extends StringAcceptanceHandlerAdapter {
 		case "heart":
 		case "UD2":
 			receiveMsg(msg, deviceId, channel);
-			logger.info("正常存储设备信息:" + getDevice(msg).toString());
+			//logger.info("正常存储设备信息:" + getDevice(msg).toString());
 			break;
 		case "LK":
 			normalReply(advice, channel);
@@ -106,13 +105,29 @@ public class WatchServerHandler extends StringAcceptanceHandlerAdapter {
 		return null;
 	}
 
-	/*
-	 * 数据[手表具体数据] [对应位数] [数据内容] 3G*3918197044*0107*UD [0] [厂商*设备 ID*内容长度*内容类型]
-	 * 200917 [1] 日期 054140 [2] 时间 V [3] gps定位是否有效[A]有效,[V]无效 31.171093 [4] 纬度 N [5]
-	 * 纬度表示 121.4215967 [6] 经度 E [7] 经度表示 0.00 [8] 速度 0.0 [9] 方向 0.0 [10] 海拔 0 [11]
-	 * 卫星个数 42,50 [12] gsm信号强度 14420 [13] 电量 0 [14] 计步数 00000010 [15] 终端状态 7,255
-	 * [16] 460 [17] 0 [18] ... ...
-	 */
+	   
+    /*   数据[手表具体数据]             [对应位数]             [数据内容]
+     *   3G*3918197044*0107*UD       [0]         [厂商*设备  ID*内容长度*内容类型]
+         200917                      [1]                   日期
+         054140                      [2]                   时间
+         V                           [3]          gps定位是否有效[A]有效,[V]无效
+         31.171093                   [4]                   纬度
+         N                           [5]                  纬度表示
+         121.4215967                 [6]                   经度
+         E                           [7]                  经度表示
+         0.00                        [8]                   速度
+         0.0                         [9]                   方向
+         0.0                         [10]                  海拔
+         0                           [11]                 卫星个数
+         42,50                       [12]                gsm信号强度
+         14420                       [13]                  电量
+         0                           [14]                 计步数
+         00000010                    [15]                终端状态
+         7,255                       [16]           
+         460                         [17]
+         0                           [18]
+         ...                       ...
+     */
 	public Device getDevice(String msg) throws Exception {
 		int startIndex = msg.indexOf("[");
 		int endIndex = msg.indexOf("]");