Mahesh Poojary Huawei

[ONOS-3117] add listener to PortPairManager

Change-Id: I261527308da725996dbae34bddb855c0cacc6367
...@@ -77,4 +77,18 @@ public interface PortPairService { ...@@ -77,4 +77,18 @@ public interface PortPairService {
77 * @return true if the give port pair is deleted successfully. 77 * @return true if the give port pair is deleted successfully.
78 */ 78 */
79 boolean removePortPair(PortPairId portPairId); 79 boolean removePortPair(PortPairId portPairId);
80 +
81 + /**
82 + * Adds the specified listener to Port-Pair manager.
83 + *
84 + * @param listener Port-Pair listener
85 + */
86 + void addListener(PortPairListener listener);
87 +
88 + /**
89 + * Removes the specified listener to Port-Pair manager.
90 + *
91 + * @param listener Port-Pair listener
92 + */
93 + void removeListener(PortPairListener listener);
80 } 94 }
......
...@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
19 import static org.slf4j.LoggerFactory.getLogger; 19 import static org.slf4j.LoggerFactory.getLogger;
20 20
21 import java.util.Collections; 21 import java.util.Collections;
22 +import java.util.Set;
22 23
23 import org.apache.felix.scr.annotations.Activate; 24 import org.apache.felix.scr.annotations.Activate;
24 import org.apache.felix.scr.annotations.Component; 25 import org.apache.felix.scr.annotations.Component;
...@@ -34,9 +35,12 @@ import org.onosproject.store.service.StorageService; ...@@ -34,9 +35,12 @@ import org.onosproject.store.service.StorageService;
34 import org.onosproject.store.service.WallClockTimestamp; 35 import org.onosproject.store.service.WallClockTimestamp;
35 import org.onosproject.vtnrsc.PortPair; 36 import org.onosproject.vtnrsc.PortPair;
36 import org.onosproject.vtnrsc.PortPairId; 37 import org.onosproject.vtnrsc.PortPairId;
38 +import org.onosproject.vtnrsc.portpair.PortPairListener;
37 import org.onosproject.vtnrsc.portpair.PortPairService; 39 import org.onosproject.vtnrsc.portpair.PortPairService;
38 import org.slf4j.Logger; 40 import org.slf4j.Logger;
39 41
42 +import com.google.common.collect.Sets;
43 +
40 /** 44 /**
41 * Provides implementation of the portPairService. 45 * Provides implementation of the portPairService.
42 */ 46 */
...@@ -44,11 +48,12 @@ import org.slf4j.Logger; ...@@ -44,11 +48,12 @@ import org.slf4j.Logger;
44 @Service 48 @Service
45 public class PortPairManager implements PortPairService { 49 public class PortPairManager implements PortPairService {
46 50
47 - private final Logger log = getLogger(getClass());
48 -
49 private static final String PORT_PAIR_ID_NULL = "PortPair ID cannot be null"; 51 private static final String PORT_PAIR_ID_NULL = "PortPair ID cannot be null";
50 private static final String PORT_PAIR_NULL = "PortPair cannot be null"; 52 private static final String PORT_PAIR_NULL = "PortPair cannot be null";
53 + private static final String LISTENER_NOT_NULL = "Listener cannot be null";
51 54
55 + private final Logger log = getLogger(getClass());
56 + private final Set<PortPairListener> listeners = Sets.newCopyOnWriteArraySet();
52 private EventuallyConsistentMap<PortPairId, PortPair> portPairStore; 57 private EventuallyConsistentMap<PortPairId, PortPair> portPairStore;
53 58
54 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 59 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -73,6 +78,7 @@ public class PortPairManager implements PortPairService { ...@@ -73,6 +78,7 @@ public class PortPairManager implements PortPairService {
73 @Deactivate 78 @Deactivate
74 public void deactivate() { 79 public void deactivate() {
75 portPairStore.destroy(); 80 portPairStore.destroy();
81 + listeners.clear();
76 log.info("Stopped"); 82 log.info("Stopped");
77 } 83 }
78 84
...@@ -143,4 +149,16 @@ public class PortPairManager implements PortPairService { ...@@ -143,4 +149,16 @@ public class PortPairManager implements PortPairService {
143 } 149 }
144 return true; 150 return true;
145 } 151 }
152 +
153 + @Override
154 + public void addListener(PortPairListener listener) {
155 + checkNotNull(listener, LISTENER_NOT_NULL);
156 + listeners.add(listener);
157 + }
158 +
159 + @Override
160 + public void removeListener(PortPairListener listener) {
161 + checkNotNull(listener, LISTENER_NOT_NULL);
162 + listeners.remove(listener);
163 + }
146 } 164 }
......