Committed by
Gerrit Code Review
[ONOS-3228] Change ConcurrentMap to EventuallyConsistentMap in
FlowClassifierManager; It should be a distributed store. Change-Id: I07ee3a0ebee50a0416e38dc4b62cfe02d5c5c14e
Showing
1 changed file
with
24 additions
and
8 deletions
... | @@ -15,21 +15,26 @@ | ... | @@ -15,21 +15,26 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.vtnrsc.flowClassifier.impl; | 16 | package org.onosproject.vtnrsc.flowClassifier.impl; |
17 | 17 | ||
18 | -import java.util.concurrent.ConcurrentHashMap; | ||
19 | -import java.util.concurrent.ConcurrentMap; | ||
20 | - | ||
21 | import org.apache.felix.scr.annotations.Activate; | 18 | import org.apache.felix.scr.annotations.Activate; |
22 | import org.apache.felix.scr.annotations.Component; | 19 | import org.apache.felix.scr.annotations.Component; |
23 | import org.apache.felix.scr.annotations.Deactivate; | 20 | import org.apache.felix.scr.annotations.Deactivate; |
21 | +import org.apache.felix.scr.annotations.Reference; | ||
22 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
24 | import org.apache.felix.scr.annotations.Service; | 23 | import org.apache.felix.scr.annotations.Service; |
24 | +import org.onlab.util.KryoNamespace; | ||
25 | +import org.onosproject.store.serializers.KryoNamespaces; | ||
26 | +import org.onosproject.store.service.EventuallyConsistentMap; | ||
27 | +import org.onosproject.store.service.MultiValuedTimestamp; | ||
28 | +import org.onosproject.store.service.StorageService; | ||
29 | +import org.onosproject.store.service.WallClockTimestamp; | ||
25 | import org.onosproject.vtnrsc.FlowClassifierId; | 30 | import org.onosproject.vtnrsc.FlowClassifierId; |
26 | import org.onosproject.vtnrsc.FlowClassifier; | 31 | import org.onosproject.vtnrsc.FlowClassifier; |
27 | import org.onosproject.vtnrsc.flowClassifier.FlowClassifierService; | 32 | import org.onosproject.vtnrsc.flowClassifier.FlowClassifierService; |
28 | - | ||
29 | import org.slf4j.Logger; | 33 | import org.slf4j.Logger; |
30 | -import static org.slf4j.LoggerFactory.getLogger; | ||
31 | 34 | ||
35 | +import static org.slf4j.LoggerFactory.getLogger; | ||
32 | import static com.google.common.base.Preconditions.checkNotNull; | 36 | import static com.google.common.base.Preconditions.checkNotNull; |
37 | + | ||
33 | import com.google.common.collect.ImmutableList; | 38 | import com.google.common.collect.ImmutableList; |
34 | 39 | ||
35 | /** | 40 | /** |
... | @@ -44,16 +49,26 @@ public class FlowClassifierManager implements FlowClassifierService { | ... | @@ -44,16 +49,26 @@ public class FlowClassifierManager implements FlowClassifierService { |
44 | private static final String FLOW_CLASSIFIER_NOT_NULL = "Flow Classifier cannot be null"; | 49 | private static final String FLOW_CLASSIFIER_NOT_NULL = "Flow Classifier cannot be null"; |
45 | private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "Flow Classifier Id cannot be null"; | 50 | private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "Flow Classifier Id cannot be null"; |
46 | 51 | ||
47 | - private ConcurrentMap<FlowClassifierId, FlowClassifier> flowClassifierStore | 52 | + private EventuallyConsistentMap<FlowClassifierId, FlowClassifier> flowClassifierStore; |
48 | - = new ConcurrentHashMap<FlowClassifierId, FlowClassifier>(); | 53 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
54 | + protected StorageService storageService; | ||
49 | 55 | ||
50 | @Activate | 56 | @Activate |
51 | private void activate() { | 57 | private void activate() { |
58 | + KryoNamespace.Builder serializer = KryoNamespace.newBuilder() | ||
59 | + .register(KryoNamespaces.API) | ||
60 | + .register(MultiValuedTimestamp.class) | ||
61 | + .register(FlowClassifier.class); | ||
62 | + flowClassifierStore = storageService | ||
63 | + .<FlowClassifierId, FlowClassifier>eventuallyConsistentMapBuilder() | ||
64 | + .withName("flowclassifierstore").withSerializer(serializer) | ||
65 | + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); | ||
52 | log.info("Flow Classifier service activated"); | 66 | log.info("Flow Classifier service activated"); |
53 | } | 67 | } |
54 | 68 | ||
55 | @Deactivate | 69 | @Deactivate |
56 | private void deactivate() { | 70 | private void deactivate() { |
71 | + flowClassifierStore.destroy(); | ||
57 | log.info("Flow Classifier service deactivated"); | 72 | log.info("Flow Classifier service deactivated"); |
58 | } | 73 | } |
59 | 74 | ||
... | @@ -92,7 +107,8 @@ public class FlowClassifierManager implements FlowClassifierService { | ... | @@ -92,7 +107,8 @@ public class FlowClassifierManager implements FlowClassifierService { |
92 | public boolean updateFlowClassifier(FlowClassifier flowClassifier) { | 107 | public boolean updateFlowClassifier(FlowClassifier flowClassifier) { |
93 | checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL); | 108 | checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL); |
94 | FlowClassifierId id = flowClassifier.flowClassifierId(); | 109 | FlowClassifierId id = flowClassifier.flowClassifierId(); |
95 | - return flowClassifierStore.replace(id, flowClassifierStore.get(id), flowClassifier); | 110 | + flowClassifierStore.put(id, flowClassifier); |
111 | + return true; | ||
96 | } | 112 | } |
97 | 113 | ||
98 | @Override | 114 | @Override | ... | ... |
-
Please register or login to post a comment