Yuta HIGUCHI

DistributedIntentStore: attempt to fix ONOS-103

Change-Id: I075ba95907c9edc2596ac8bb5f88a23d8e2af204
...@@ -16,7 +16,11 @@ ...@@ -16,7 +16,11 @@
16 package org.onlab.onos.store.intent.impl; 16 package org.onlab.onos.store.intent.impl;
17 17
18 import com.google.common.collect.ImmutableSet; 18 import com.google.common.collect.ImmutableSet;
19 +import com.hazelcast.core.EntryAdapter;
20 +import com.hazelcast.core.EntryEvent;
21 +import com.hazelcast.core.EntryListener;
19 import com.hazelcast.core.IMap; 22 import com.hazelcast.core.IMap;
23 +import com.hazelcast.core.Member;
20 24
21 import org.apache.felix.scr.annotations.Activate; 25 import org.apache.felix.scr.annotations.Activate;
22 import org.apache.felix.scr.annotations.Component; 26 import org.apache.felix.scr.annotations.Component;
...@@ -87,6 +91,8 @@ public class DistributedIntentStore ...@@ -87,6 +91,8 @@ public class DistributedIntentStore
87 // TODO: disable near cache, disable read from backup for this IMap 91 // TODO: disable near cache, disable read from backup for this IMap
88 IMap<byte[], byte[]> rawStates = super.theInstance.getMap("intent-states"); 92 IMap<byte[], byte[]> rawStates = super.theInstance.getMap("intent-states");
89 states = new SMap<>(rawStates , super.serializer); 93 states = new SMap<>(rawStates , super.serializer);
94 + EntryListener<IntentId, IntentState> listener = new RemoteIntentStateListener();
95 + states.addEntryListener(listener , false);
90 96
91 transientStates.clear(); 97 transientStates.clear();
92 98
...@@ -213,5 +219,21 @@ public class DistributedIntentStore ...@@ -213,5 +219,21 @@ public class DistributedIntentStore
213 installable.remove(intentId); 219 installable.remove(intentId);
214 } 220 }
215 221
216 - // FIXME add handler to react to remote event 222 + public final class RemoteIntentStateListener extends EntryAdapter<IntentId, IntentState> {
223 +
224 + @Override
225 + public void onEntryEvent(EntryEvent<IntentId, IntentState> event) {
226 + final Member myself = theInstance.getCluster().getLocalMember();
227 + if (!myself.equals(event.getMember())) {
228 + // When Intent state was modified by remote node,
229 + // clear local transient state.
230 + final IntentId intentId = event.getKey();
231 + IntentState oldState = transientStates.remove(intentId);
232 + if (oldState != null) {
233 + log.debug("{} state updated remotely, removing transient state {}",
234 + intentId, oldState);
235 + }
236 + }
237 + }
238 + }
217 } 239 }
......