[ONOS-3117] store listener in Flow-Classifier Manager
Change-Id: I40fd21050d9728d432b037528435ee8e7ec31ea2
Showing
2 changed files
with
37 additions
and
4 deletions
... | @@ -79,4 +79,18 @@ public interface FlowClassifierService { | ... | @@ -79,4 +79,18 @@ public interface FlowClassifierService { |
79 | * false | 79 | * false |
80 | */ | 80 | */ |
81 | boolean removeFlowClassifier(FlowClassifierId id); | 81 | boolean removeFlowClassifier(FlowClassifierId id); |
82 | + | ||
83 | + /** | ||
84 | + * Adds the specified listener to Flow-Classifier manager. | ||
85 | + * | ||
86 | + * @param listener Flow-Classifier listener | ||
87 | + */ | ||
88 | + void addListener(FlowClassifierListener listener); | ||
89 | + | ||
90 | + /** | ||
91 | + * Removes the specified listener to Flow-Classifier manager. | ||
92 | + * | ||
93 | + * @param listener Flow-Classifier listener | ||
94 | + */ | ||
95 | + void removeListener(FlowClassifierListener listener); | ||
82 | } | 96 | } | ... | ... |
... | @@ -15,6 +15,9 @@ | ... | @@ -15,6 +15,9 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.vtnrsc.flowclassifier.impl; | 16 | package org.onosproject.vtnrsc.flowclassifier.impl; |
17 | 17 | ||
18 | +import static org.slf4j.LoggerFactory.getLogger; | ||
19 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
20 | + | ||
18 | import org.apache.felix.scr.annotations.Activate; | 21 | import org.apache.felix.scr.annotations.Activate; |
19 | import org.apache.felix.scr.annotations.Component; | 22 | import org.apache.felix.scr.annotations.Component; |
20 | import org.apache.felix.scr.annotations.Deactivate; | 23 | import org.apache.felix.scr.annotations.Deactivate; |
... | @@ -29,13 +32,14 @@ import org.onosproject.store.service.StorageService; | ... | @@ -29,13 +32,14 @@ import org.onosproject.store.service.StorageService; |
29 | import org.onosproject.store.service.WallClockTimestamp; | 32 | import org.onosproject.store.service.WallClockTimestamp; |
30 | import org.onosproject.vtnrsc.FlowClassifierId; | 33 | import org.onosproject.vtnrsc.FlowClassifierId; |
31 | import org.onosproject.vtnrsc.FlowClassifier; | 34 | import org.onosproject.vtnrsc.FlowClassifier; |
35 | +import org.onosproject.vtnrsc.flowclassifier.FlowClassifierListener; | ||
32 | import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; | 36 | import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; |
33 | import org.slf4j.Logger; | 37 | import org.slf4j.Logger; |
34 | 38 | ||
35 | -import static org.slf4j.LoggerFactory.getLogger; | 39 | +import java.util.Set; |
36 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
37 | 40 | ||
38 | import com.google.common.collect.ImmutableList; | 41 | import com.google.common.collect.ImmutableList; |
42 | +import com.google.common.collect.Sets; | ||
39 | 43 | ||
40 | /** | 44 | /** |
41 | * Provides implementation of the Flow Classifier Service. | 45 | * Provides implementation of the Flow Classifier Service. |
... | @@ -44,12 +48,14 @@ import com.google.common.collect.ImmutableList; | ... | @@ -44,12 +48,14 @@ import com.google.common.collect.ImmutableList; |
44 | @Service | 48 | @Service |
45 | public class FlowClassifierManager implements FlowClassifierService { | 49 | public class FlowClassifierManager implements FlowClassifierService { |
46 | 50 | ||
47 | - private final Logger log = getLogger(FlowClassifierManager.class); | ||
48 | - | ||
49 | private static final String FLOW_CLASSIFIER_NOT_NULL = "Flow Classifier cannot be null"; | 51 | private static final String FLOW_CLASSIFIER_NOT_NULL = "Flow Classifier cannot be null"; |
50 | private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "Flow Classifier Id cannot be null"; | 52 | private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "Flow Classifier Id cannot be null"; |
53 | + private static final String LISTENER_NOT_NULL = "Listener cannot be null"; | ||
51 | 54 | ||
55 | + private final Logger log = getLogger(FlowClassifierManager.class); | ||
56 | + private final Set<FlowClassifierListener> listeners = Sets.newCopyOnWriteArraySet(); | ||
52 | private EventuallyConsistentMap<FlowClassifierId, FlowClassifier> flowClassifierStore; | 57 | private EventuallyConsistentMap<FlowClassifierId, FlowClassifier> flowClassifierStore; |
58 | + | ||
53 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 59 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
54 | protected StorageService storageService; | 60 | protected StorageService storageService; |
55 | 61 | ||
... | @@ -69,6 +75,7 @@ public class FlowClassifierManager implements FlowClassifierService { | ... | @@ -69,6 +75,7 @@ public class FlowClassifierManager implements FlowClassifierService { |
69 | @Deactivate | 75 | @Deactivate |
70 | protected void deactivate() { | 76 | protected void deactivate() { |
71 | flowClassifierStore.destroy(); | 77 | flowClassifierStore.destroy(); |
78 | + listeners.clear(); | ||
72 | log.info("Flow Classifier service deactivated"); | 79 | log.info("Flow Classifier service deactivated"); |
73 | } | 80 | } |
74 | 81 | ||
... | @@ -138,4 +145,16 @@ public class FlowClassifierManager implements FlowClassifierService { | ... | @@ -138,4 +145,16 @@ public class FlowClassifierManager implements FlowClassifierService { |
138 | } | 145 | } |
139 | return true; | 146 | return true; |
140 | } | 147 | } |
148 | + | ||
149 | + @Override | ||
150 | + public void addListener(FlowClassifierListener listener) { | ||
151 | + checkNotNull(listener, LISTENER_NOT_NULL); | ||
152 | + listeners.add(listener); | ||
153 | + } | ||
154 | + | ||
155 | + @Override | ||
156 | + public void removeListener(FlowClassifierListener listener) { | ||
157 | + checkNotNull(listener, LISTENER_NOT_NULL); | ||
158 | + listeners.remove(listener); | ||
159 | + } | ||
141 | } | 160 | } | ... | ... |
-
Please register or login to post a comment