removeListener on deactivate
Change-Id: I82b2cc7960bc19ebb1c6875e8cf3dd79d7421dd1
Showing
2 changed files
with
12 additions
and
4 deletions
... | @@ -72,6 +72,10 @@ public class DistributedDeviceStore | ... | @@ -72,6 +72,10 @@ public class DistributedDeviceStore |
72 | private IMap<byte[], byte[]> rawDevicePorts; | 72 | private IMap<byte[], byte[]> rawDevicePorts; |
73 | private LoadingCache<DeviceId, Optional<Map<PortNumber, Port>>> devicePorts; | 73 | private LoadingCache<DeviceId, Optional<Map<PortNumber, Port>>> devicePorts; |
74 | 74 | ||
75 | + private String devicesListener; | ||
76 | + | ||
77 | + private String portsListener; | ||
78 | + | ||
75 | @Override | 79 | @Override |
76 | @Activate | 80 | @Activate |
77 | public void activate() { | 81 | public void activate() { |
... | @@ -86,7 +90,7 @@ public class DistributedDeviceStore | ... | @@ -86,7 +90,7 @@ public class DistributedDeviceStore |
86 | = new OptionalCacheLoader<>(storeService, rawDevices); | 90 | = new OptionalCacheLoader<>(storeService, rawDevices); |
87 | devices = new AbsentInvalidatingLoadingCache<>(newBuilder().build(deviceLoader)); | 91 | devices = new AbsentInvalidatingLoadingCache<>(newBuilder().build(deviceLoader)); |
88 | // refresh/populate cache based on notification from other instance | 92 | // refresh/populate cache based on notification from other instance |
89 | - rawDevices.addEntryListener(new RemoteDeviceEventHandler(devices), includeValue); | 93 | + devicesListener = rawDevices.addEntryListener(new RemoteDeviceEventHandler(devices), includeValue); |
90 | 94 | ||
91 | // TODO cache availableDevices | 95 | // TODO cache availableDevices |
92 | availableDevices = theInstance.getSet("availableDevices"); | 96 | availableDevices = theInstance.getSet("availableDevices"); |
... | @@ -96,7 +100,7 @@ public class DistributedDeviceStore | ... | @@ -96,7 +100,7 @@ public class DistributedDeviceStore |
96 | = new OptionalCacheLoader<>(storeService, rawDevicePorts); | 100 | = new OptionalCacheLoader<>(storeService, rawDevicePorts); |
97 | devicePorts = new AbsentInvalidatingLoadingCache<>(newBuilder().build(devicePortLoader)); | 101 | devicePorts = new AbsentInvalidatingLoadingCache<>(newBuilder().build(devicePortLoader)); |
98 | // refresh/populate cache based on notification from other instance | 102 | // refresh/populate cache based on notification from other instance |
99 | - rawDevicePorts.addEntryListener(new RemotePortEventHandler(devicePorts), includeValue); | 103 | + portsListener = rawDevicePorts.addEntryListener(new RemotePortEventHandler(devicePorts), includeValue); |
100 | 104 | ||
101 | loadDeviceCache(); | 105 | loadDeviceCache(); |
102 | loadDevicePortsCache(); | 106 | loadDevicePortsCache(); |
... | @@ -106,6 +110,8 @@ public class DistributedDeviceStore | ... | @@ -106,6 +110,8 @@ public class DistributedDeviceStore |
106 | 110 | ||
107 | @Deactivate | 111 | @Deactivate |
108 | public void deactivate() { | 112 | public void deactivate() { |
113 | + rawDevicePorts.removeEntryListener(portsListener); | ||
114 | + rawDevices.removeEntryListener(devicesListener); | ||
109 | log.info("Stopped"); | 115 | log.info("Stopped"); |
110 | } | 116 | } |
111 | 117 | ... | ... |
... | @@ -58,6 +58,8 @@ public class DistributedLinkStore | ... | @@ -58,6 +58,8 @@ public class DistributedLinkStore |
58 | private final Multimap<DeviceId, Link> srcLinks = HashMultimap.create(); | 58 | private final Multimap<DeviceId, Link> srcLinks = HashMultimap.create(); |
59 | private final Multimap<DeviceId, Link> dstLinks = HashMultimap.create(); | 59 | private final Multimap<DeviceId, Link> dstLinks = HashMultimap.create(); |
60 | 60 | ||
61 | + private String linksListener; | ||
62 | + | ||
61 | @Override | 63 | @Override |
62 | @Activate | 64 | @Activate |
63 | public void activate() { | 65 | public void activate() { |
... | @@ -71,7 +73,7 @@ public class DistributedLinkStore | ... | @@ -71,7 +73,7 @@ public class DistributedLinkStore |
71 | = new OptionalCacheLoader<>(storeService, rawLinks); | 73 | = new OptionalCacheLoader<>(storeService, rawLinks); |
72 | links = new AbsentInvalidatingLoadingCache<>(newBuilder().build(linkLoader)); | 74 | links = new AbsentInvalidatingLoadingCache<>(newBuilder().build(linkLoader)); |
73 | // refresh/populate cache based on notification from other instance | 75 | // refresh/populate cache based on notification from other instance |
74 | - rawLinks.addEntryListener(new RemoteLinkEventHandler(links), includeValue); | 76 | + linksListener = rawLinks.addEntryListener(new RemoteLinkEventHandler(links), includeValue); |
75 | 77 | ||
76 | loadLinkCache(); | 78 | loadLinkCache(); |
77 | 79 | ||
... | @@ -80,7 +82,7 @@ public class DistributedLinkStore | ... | @@ -80,7 +82,7 @@ public class DistributedLinkStore |
80 | 82 | ||
81 | @Deactivate | 83 | @Deactivate |
82 | public void deactivate() { | 84 | public void deactivate() { |
83 | - super.activate(); | 85 | + rawLinks.removeEntryListener(linksListener); |
84 | log.info("Stopped"); | 86 | log.info("Stopped"); |
85 | } | 87 | } |
86 | 88 | ... | ... |
-
Please register or login to post a comment