IOT-3142 reverify4 31/26631/6
authorRap <peter.rafaj@kistler.com>
Tue, 30 Jan 2018 09:44:08 +0000 (10:44 +0100)
committerOndrej Tomcik <ondrej.tomcik@kistler.com>
Fri, 3 Aug 2018 21:07:07 +0000 (21:07 +0000)
Change-Id: Icc4cbb5795051c910f866983fed554d9f46311d5
Signed-off-by: Peter Rafaj <peter.rafaj@kistler.com>
cloud/stack/src/main/java/org/iotivity/cloud/base/connector/CoapClient.java
cloud/stack/src/main/java/org/iotivity/cloud/base/connector/CoapConnector.java

index 773e57f..b0e2f64 100644 (file)
@@ -141,7 +141,7 @@ public class CoapClient implements IRequestChannel, IResponseEventHandler {
         // Subscription response should stored
         if (reqInfo.observe != Observe.SUBSCRIBE) {
             mTokenExchanger.remove(Bytes.bytesToLong(coapResponse.getToken()));
-            if (mSubscription
+            if (reqInfo.originToken != null && mSubscription
                     .containsKey(Bytes.bytesToLong(reqInfo.originToken))) {
                 mSubscription.remove(Bytes.bytesToLong(reqInfo.originToken));
             }
index cd33ed0..09ebc43 100644 (file)
@@ -73,7 +73,7 @@ public class CoapConnector {
             if (evt instanceof IdleStateEvent) {
                 IdleStateEvent event = (IdleStateEvent) evt;
                 if (event.state() == IdleState.WRITER_IDLE) {
-                    ctx.writeAndFlush(PingMessage.build());
+                    mChannelMap.get(ctx.channel()).sendRequest(PingMessage.build(),null);
                 }
                 if (event.state() == IdleState.READER_IDLE) {
                     Log.debug("Connection with" +  ctx.channel().remoteAddress().toString() + "is idle. Closing connection.");
@@ -152,7 +152,7 @@ public class CoapConnector {
         }
     }
 
-    HashMap<Channel, CoapClient> mChannelMap     = new HashMap<>();
+    private static Map<Channel, CoapClient> mChannelMap     = new HashMap<>();
     Bootstrap                    mBootstrap      = new Bootstrap();
     EventLoopGroup               mConnectorGroup = new NioEventLoopGroup();
     Timer                        mTimer          = new Timer();