Browse Source

手表接入程序 给设备回复添加监听者

chudk 7 years ago
parent
commit
070fba3bb8

+ 12 - 3
src/main/java/com/tidecloud/dataacceptance/service/impl/WatchServerHandler.java

@@ -28,7 +28,10 @@ import com.tidecloud.dataacceptance.entity.HrtStart;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.Channel;
+import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelHandler.Sharable;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.GenericFutureListener;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelInboundHandlerAdapter;
 import redis.clients.jedis.Jedis;
@@ -166,16 +169,22 @@ public class WatchServerHandler extends ChannelInboundHandlerAdapter {
         String deviceId = advice.getDeviceId();
         StringBuilder replyCommand = new StringBuilder();
         replyCommand.append("[");
-        replyCommand.append(facotry).append("*");
+        replyCommand.append("3g").append("*");
         replyCommand.append(deviceId).append("*");
         replyCommand.append("0002").append("*");
         replyCommand.append(adviceType);
         replyCommand.append("]");
         String replyCommandStr = replyCommand.toString();
-        logger.info("Normal reply :" + replyCommandStr);
         ByteBuf buffer = Unpooled.buffer(replyCommandStr.getBytes().length);
         buffer.writeBytes(replyCommandStr.getBytes());
-        channel.write(buffer);
+        ChannelFuture channelFuture = channel.writeAndFlush(buffer);
+        channelFuture.addListener(new GenericFutureListener<Future<? super Void>>() {
+
+            @Override
+            public void operationComplete(Future<? super Void> future) throws Exception {
+                logger.info("Normal reply :" + replyCommandStr);
+            }
+        });
     }
 
     private Advice getAdevice(Object msg) {