Committed by
Gerrit Code Review
Hz: remove listeners on deactivate
Change-Id: I544917508cd4b9513e3fcd3a100c44928954f413
Showing
4 changed files
with
17 additions
and
4 deletions
... | @@ -64,6 +64,8 @@ public class DistributedClusterStore | ... | @@ -64,6 +64,8 @@ public class DistributedClusterStore |
64 | private final MembershipListener listener = new InternalMembershipListener(); | 64 | private final MembershipListener listener = new InternalMembershipListener(); |
65 | private final Map<NodeId, State> states = new ConcurrentHashMap<>(); | 65 | private final Map<NodeId, State> states = new ConcurrentHashMap<>(); |
66 | 66 | ||
67 | + private String nodesListenerId; | ||
68 | + | ||
67 | @Override | 69 | @Override |
68 | @Activate | 70 | @Activate |
69 | public void activate() { | 71 | public void activate() { |
... | @@ -74,7 +76,7 @@ public class DistributedClusterStore | ... | @@ -74,7 +76,7 @@ public class DistributedClusterStore |
74 | OptionalCacheLoader<NodeId, DefaultControllerNode> nodeLoader | 76 | OptionalCacheLoader<NodeId, DefaultControllerNode> nodeLoader |
75 | = new OptionalCacheLoader<>(serializer, rawNodes); | 77 | = new OptionalCacheLoader<>(serializer, rawNodes); |
76 | nodes = new AbsentInvalidatingLoadingCache<>(newBuilder().build(nodeLoader)); | 78 | nodes = new AbsentInvalidatingLoadingCache<>(newBuilder().build(nodeLoader)); |
77 | - rawNodes.addEntryListener(new RemoteCacheEventHandler<>(nodes), true); | 79 | + nodesListenerId = rawNodes.addEntryListener(new RemoteCacheEventHandler<>(nodes), true); |
78 | 80 | ||
79 | loadClusterNodes(); | 81 | loadClusterNodes(); |
80 | 82 | ||
... | @@ -90,6 +92,7 @@ public class DistributedClusterStore | ... | @@ -90,6 +92,7 @@ public class DistributedClusterStore |
90 | 92 | ||
91 | @Deactivate | 93 | @Deactivate |
92 | public void deactivate() { | 94 | public void deactivate() { |
95 | + rawNodes.removeEntryListener(nodesListenerId); | ||
93 | theInstance.getCluster().removeMembershipListener(listenerId); | 96 | theInstance.getCluster().removeMembershipListener(listenerId); |
94 | log.info("Stopped"); | 97 | log.info("Stopped"); |
95 | } | 98 | } | ... | ... |
... | @@ -22,6 +22,7 @@ import com.hazelcast.core.EntryEvent; | ... | @@ -22,6 +22,7 @@ import com.hazelcast.core.EntryEvent; |
22 | import com.hazelcast.core.EntryListener; | 22 | import com.hazelcast.core.EntryListener; |
23 | import com.hazelcast.core.IAtomicLong; | 23 | import com.hazelcast.core.IAtomicLong; |
24 | import com.hazelcast.core.MapEvent; | 24 | import com.hazelcast.core.MapEvent; |
25 | + | ||
25 | import org.apache.felix.scr.annotations.Activate; | 26 | import org.apache.felix.scr.annotations.Activate; |
26 | import org.apache.felix.scr.annotations.Component; | 27 | import org.apache.felix.scr.annotations.Component; |
27 | import org.apache.felix.scr.annotations.Deactivate; | 28 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -54,6 +55,8 @@ public class DistributedApplicationIdStore | ... | @@ -54,6 +55,8 @@ public class DistributedApplicationIdStore |
54 | 55 | ||
55 | protected Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>(); | 56 | protected Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>(); |
56 | 57 | ||
58 | + private String listenerId; | ||
59 | + | ||
57 | 60 | ||
58 | @Override | 61 | @Override |
59 | @Activate | 62 | @Activate |
... | @@ -73,7 +76,7 @@ public class DistributedApplicationIdStore | ... | @@ -73,7 +76,7 @@ public class DistributedApplicationIdStore |
73 | lastAppId = theInstance.getAtomicLong("applicationId"); | 76 | lastAppId = theInstance.getAtomicLong("applicationId"); |
74 | 77 | ||
75 | appIdsByName = new SMap<>(theInstance.<byte[], byte[]>getMap("appIdsByName"), this.serializer); | 78 | appIdsByName = new SMap<>(theInstance.<byte[], byte[]>getMap("appIdsByName"), this.serializer); |
76 | - appIdsByName.addEntryListener((new RemoteAppIdEventHandler()), true); | 79 | + listenerId = appIdsByName.addEntryListener((new RemoteAppIdEventHandler()), true); |
77 | 80 | ||
78 | primeAppIds(); | 81 | primeAppIds(); |
79 | 82 | ||
... | @@ -82,6 +85,7 @@ public class DistributedApplicationIdStore | ... | @@ -82,6 +85,7 @@ public class DistributedApplicationIdStore |
82 | 85 | ||
83 | @Deactivate | 86 | @Deactivate |
84 | public void deactivate() { | 87 | public void deactivate() { |
88 | + appIdsByName.removeEntryListener(listenerId); | ||
85 | log.info("Stopped"); | 89 | log.info("Stopped"); |
86 | } | 90 | } |
87 | 91 | ... | ... |
... | @@ -107,6 +107,8 @@ public class HazelcastIntentStore | ... | @@ -107,6 +107,8 @@ public class HazelcastIntentStore |
107 | private Timer getIntentTimer; | 107 | private Timer getIntentTimer; |
108 | private Timer getIntentStateTimer; | 108 | private Timer getIntentStateTimer; |
109 | 109 | ||
110 | + private String listenerId; | ||
111 | + | ||
110 | private Timer createResponseTimer(String methodName) { | 112 | private Timer createResponseTimer(String methodName) { |
111 | return createTimer("IntentStore", methodName, "responseTime"); | 113 | return createTimer("IntentStore", methodName, "responseTime"); |
112 | } | 114 | } |
... | @@ -150,7 +152,7 @@ public class HazelcastIntentStore | ... | @@ -150,7 +152,7 @@ public class HazelcastIntentStore |
150 | IMap<byte[], byte[]> rawStates = super.theInstance.getMap("intent-states"); | 152 | IMap<byte[], byte[]> rawStates = super.theInstance.getMap("intent-states"); |
151 | states = new SMap<>(rawStates , super.serializer); | 153 | states = new SMap<>(rawStates , super.serializer); |
152 | EntryListener<IntentId, IntentState> listener = new RemoteIntentStateListener(); | 154 | EntryListener<IntentId, IntentState> listener = new RemoteIntentStateListener(); |
153 | - states.addEntryListener(listener , true); | 155 | + listenerId = states.addEntryListener(listener , true); |
154 | 156 | ||
155 | transientStates.clear(); | 157 | transientStates.clear(); |
156 | 158 | ||
... | @@ -163,6 +165,7 @@ public class HazelcastIntentStore | ... | @@ -163,6 +165,7 @@ public class HazelcastIntentStore |
163 | 165 | ||
164 | @Deactivate | 166 | @Deactivate |
165 | public void deactivate() { | 167 | public void deactivate() { |
168 | + states.removeEntryListener(listenerId); | ||
166 | log.info("Stopped"); | 169 | log.info("Stopped"); |
167 | } | 170 | } |
168 | 171 | ... | ... |
... | @@ -74,6 +74,8 @@ public class DistributedMastershipStore | ... | @@ -74,6 +74,8 @@ public class DistributedMastershipStore |
74 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 74 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
75 | protected ClusterService clusterService; | 75 | protected ClusterService clusterService; |
76 | 76 | ||
77 | + private String listenerId; | ||
78 | + | ||
77 | @Override | 79 | @Override |
78 | @Activate | 80 | @Activate |
79 | public void activate() { | 81 | public void activate() { |
... | @@ -91,7 +93,7 @@ public class DistributedMastershipStore | ... | @@ -91,7 +93,7 @@ public class DistributedMastershipStore |
91 | }; | 93 | }; |
92 | 94 | ||
93 | roleMap = new SMap<>(theInstance.<byte[], byte[]>getMap("nodeRoles"), this.serializer); | 95 | roleMap = new SMap<>(theInstance.<byte[], byte[]>getMap("nodeRoles"), this.serializer); |
94 | - roleMap.addEntryListener((new RemoteMasterShipEventHandler()), true); | 96 | + listenerId = roleMap.addEntryListener((new RemoteMasterShipEventHandler()), true); |
95 | terms = new SMap<>(theInstance.<byte[], byte[]>getMap("terms"), this.serializer); | 97 | terms = new SMap<>(theInstance.<byte[], byte[]>getMap("terms"), this.serializer); |
96 | 98 | ||
97 | log.info("Started"); | 99 | log.info("Started"); |
... | @@ -99,6 +101,7 @@ public class DistributedMastershipStore | ... | @@ -99,6 +101,7 @@ public class DistributedMastershipStore |
99 | 101 | ||
100 | @Deactivate | 102 | @Deactivate |
101 | public void deactivate() { | 103 | public void deactivate() { |
104 | + roleMap.removeEntryListener(listenerId); | ||
102 | log.info("Stopped"); | 105 | log.info("Stopped"); |
103 | } | 106 | } |
104 | 107 | ... | ... |
-
Please register or login to post a comment