Add a logic to remove policies and tunnels with multiple instances
diff --git a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
index 3b7c5c4..48903c9 100644
--- a/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
+++ b/src/main/java/net/onrc/onos/apps/segmentrouting/SegmentRoutingManager.java
@@ -107,8 +107,8 @@
     private IPacketService packetService;
     private IDatagridService datagridService;
     private IControllerRegistryService registryService;
-    private IEventChannel<Long, PolicyNotification> policyEventChannel;
-    private IEventChannel<Long, TunnelNotification> tunnelEventChannel;
+    private IEventChannel<String, PolicyNotification> policyEventChannel;
+    private IEventChannel<String, TunnelNotification> tunnelEventChannel;
     private MatchActionService matchActionService;
     private MutableTopology mutableTopology;
     private ConcurrentLinkedQueue<IPv4> ipPacketQueue;
@@ -243,12 +243,12 @@
 
         policyEventChannel = datagridService.addListener(SR_POLICY_CHANNEL_NAME,
                 policyEventHandler,
-                Long.class,
+                String.class,
                 PolicyNotification.class);
 
         tunnelEventChannel = datagridService.addListener(SR_TUNNEL_CHANNEL_NAME,
                 tunnelEventHandler,
-                Long.class,
+                String.class,
                 TunnelNotification.class);
 
         discoveryTask = new SingletonTask(ses, new Runnable() {
@@ -293,7 +293,7 @@
     }
 
     private class PolicyEventHandler implements
-    IEventChannelListener<Long, PolicyNotification> {
+    IEventChannelListener<String, PolicyNotification> {
 
         SegmentRoutingManager srManager;
 
@@ -313,9 +313,9 @@
         }
 
         @Override
-        public void entryRemoved(PolicyNotification value) {
-            log.debug("Policy entry {} was removed", value);
-
+        public void entryRemoved(PolicyNotification policyNotication) {
+            log.debug("Policy entry {} was removed", policyNotication);
+            policyTable.remove(policyNotication.getPolicyId());
         }
 
        @Override
@@ -327,7 +327,7 @@
     }
 
     private class TunnelEventHandler implements
-    IEventChannelListener<Long, TunnelNotification> {
+    IEventChannelListener<String, TunnelNotification> {
         SegmentRoutingManager srManager;
 
         public TunnelEventHandler(SegmentRoutingManager srm) {
@@ -342,16 +342,15 @@
             if (srTunnel.checkAndCreateTunnel()) {
                 TunnelNotification tunnelNotificationBack =
                         new TunnelNotification(srTunnel);
-                tunnelEventChannel.updateEntry(Long.valueOf(srTunnel.getTunnelId()),
+                tunnelEventChannel.updateEntry(srTunnel.getTunnelId(),
                         tunnelNotificationBack);
             }
             tunnelTable.put(srTunnel.getTunnelId(), srTunnel);
         }
 
         @Override
-        public void entryRemoved(TunnelNotification value) {
-            // TODO Auto-generated method stub
-
+        public void entryRemoved(TunnelNotification tunnelNotification) {
+            tunnelTable.remove(tunnelNotification.getTunnelId());
         }
 
         @Override
@@ -1329,8 +1328,7 @@
             tunnelTable.put(tunnelId, srTunnel);
             TunnelNotification tunnelNotification =
                     new TunnelNotification(srTunnel);
-            tunnelEventChannel.addTransientEntry(Long.valueOf(1),
-                    tunnelNotification);
+            tunnelEventChannel.addEntry(tunnelId, tunnelNotification);
             return true;
         }
         else {
@@ -1399,7 +1397,7 @@
                 policyTable.put(pid, srPolicy);
                 PolicyNotification policyNotification =
                         new PolicyNotification(srPolicy);
-                policyEventChannel.addTransientEntry(Long.valueOf(1),
+                policyEventChannel.addEntry(pid,
                         policyNotification);
                 return true;
             }
@@ -1437,7 +1435,9 @@
         }
         if (policy.removePolicy()) {
             policyTable.remove(pid);
+            policyEventChannel.removeEntry(pid);
             log.debug("Policy {} is removed.", pid);
+
             return true;
         }
         else {
@@ -1506,6 +1506,7 @@
             if (tunnel.removeTunnel()) {
                 tunnelTable.remove(tunnelId);
                 log.debug("Tunnel {} was removed successfully.", tunnelId);
+                tunnelEventChannel.removeEntry(tunnelId);
                 return removeTunnelMessages.SUCCESS;
             }
             else {