IOT-3210 filter inactive channel 27/27227/1
authorRap <peter.rafaj@kistler.com>
Fri, 13 Jul 2018 13:34:50 +0000 (15:34 +0200)
committerPeter Rafaj <peter.rafaj@kistler.com>
Mon, 15 Oct 2018 11:25:01 +0000 (13:25 +0200)
Change-Id: Ib251b691164b41e614a527d8857362268a9639ab
Signed-off-by: Peter Rafaj <peter.rafaj@kistler.com>
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/DeviceServerSystem.java
cloud/interface/src/main/java/org/iotivity/cloud/ciserver/resources/KeepAliveResource.java

index cf88c1f..da16b98 100644 (file)
@@ -73,7 +73,7 @@ public class DeviceServerSystem extends ServerSystem {
     private HashMap<ChannelHandlerContext, CoapSignaling> mCsmMap = new HashMap<>();
 
     public static final String LOGOUT_DEVICE = "LOGOUT_DEVICE";
-
+    public static final String EMPTY_CHANNEL = "EMPTY_CHANNEL";
     /**
      *
      * This class provides a set of APIs to manage device pool.
@@ -280,7 +280,9 @@ public class DeviceServerSystem extends ServerSystem {
             if (device != null) {
                 Log.debug("Device: {} offline ", device.getDeviceId());
                 try {
-                    sendDevicePresence(device.getDeviceId(), "off");
+                    if(!device.existParameter(DeviceServerSystem.EMPTY_CHANNEL)){
+                        sendDevicePresence(device.getDeviceId(), "off");
+                    }
                 } catch (ServerException.ServiceUnavailableException e) {
                     Log.warn(e.getMessage());
                     ctx.close();
index 9503358..f5b86ac 100644 (file)
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Timer;
 import java.util.TimerTask;
+import java.util.stream.Collectors;
 
 import org.iotivity.cloud.base.device.Device;
 import org.iotivity.cloud.base.exception.ServerException;
@@ -39,8 +40,12 @@ import org.iotivity.cloud.base.protocols.MessageBuilder;
 import org.iotivity.cloud.base.protocols.enums.ContentFormat;
 import org.iotivity.cloud.base.protocols.enums.ResponseStatus;
 import org.iotivity.cloud.base.resource.Resource;
+import org.iotivity.cloud.ciserver.CloudInterfaceServer;
 import org.iotivity.cloud.ciserver.Constants;
+import org.iotivity.cloud.ciserver.DeviceServerSystem;
 import org.iotivity.cloud.util.Cbor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  *
@@ -49,6 +54,7 @@ import org.iotivity.cloud.util.Cbor;
  *
  */
 public class KeepAliveResource extends Resource {
+    private final static Logger Log = LoggerFactory.getLogger(KeepAliveResource.class);
     private int[]                         mIntervals      = null;
     private Timer                         mTimer          = new Timer();
     private Cbor<HashMap<String, Object>> mCbor           = new Cbor<>();
@@ -145,6 +151,15 @@ public class KeepAliveResource extends Resource {
                 }
             }
 
+            for(final Device device : deleteList){
+                final List<Device> samedevice = map.keySet().stream().filter(d -> (d.getDeviceId().compareTo(device.getDeviceId()) == 0
+                        && d.getCtx().channel().id().asLongText().compareTo(device.getCtx().channel().id().asLongText()) != 0)).collect(Collectors.toList());
+                if(samedevice != null && samedevice.size() > 0){
+                    Log.info("Channel for device: {} is empty", device.getDeviceId());
+                    device.setParameter(DeviceServerSystem.EMPTY_CHANNEL,true);
+                }
+            }
+
             for (Device device : deleteList) {
                 mConnectionPool.remove(device);
                 device.getCtx().fireChannelInactive();