Mahesh Poojary Huawei
Committed by Thomas Vachuska

[ONOS-3117] adding listener to Port-Pair-Group Manager

Change-Id: I33dcdc6172e4a5a596d0e376e224ee3eb42387cd
...@@ -77,4 +77,18 @@ public interface PortPairGroupService { ...@@ -77,4 +77,18 @@ public interface PortPairGroupService {
77 * @return true if the give port pair group is deleted successfully. 77 * @return true if the give port pair group is deleted successfully.
78 */ 78 */
79 boolean removePortPairGroup(PortPairGroupId portPairGroupId); 79 boolean removePortPairGroup(PortPairGroupId portPairGroupId);
80 +
81 + /**
82 + * Adds the specified listener to Port-Pair-Group manager.
83 + *
84 + * @param listener Port-Pair-Group listener
85 + */
86 + void addListener(PortPairGroupListener listener);
87 +
88 + /**
89 + * Removes the specified listener to Port-Pair-Group manager.
90 + *
91 + * @param listener Port-Pair-Group listener
92 + */
93 + void removeListener(PortPairGroupListener 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.PortPairGroup; 36 import org.onosproject.vtnrsc.PortPairGroup;
36 import org.onosproject.vtnrsc.PortPairGroupId; 37 import org.onosproject.vtnrsc.PortPairGroupId;
38 +import org.onosproject.vtnrsc.portpairgroup.PortPairGroupListener;
37 import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; 39 import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
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 portPairGroupService. 45 * Provides implementation of the portPairGroupService.
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 PortPairGroupManager implements PortPairGroupService { 49 public class PortPairGroupManager implements PortPairGroupService {
46 50
47 - private final Logger log = getLogger(getClass());
48 -
49 private static final String PORT_PAIR_GROUP_ID_NULL = "PortPairGroup ID cannot be null"; 51 private static final String PORT_PAIR_GROUP_ID_NULL = "PortPairGroup ID cannot be null";
50 private static final String PORT_PAIR_GROUP_NULL = "PortPairGroup cannot be null"; 52 private static final String PORT_PAIR_GROUP_NULL = "PortPairGroup 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<PortPairGroupListener> listeners = Sets.newCopyOnWriteArraySet();
52 private EventuallyConsistentMap<PortPairGroupId, PortPairGroup> portPairGroupStore; 57 private EventuallyConsistentMap<PortPairGroupId, PortPairGroup> portPairGroupStore;
53 58
54 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 59 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -73,6 +78,7 @@ public class PortPairGroupManager implements PortPairGroupService { ...@@ -73,6 +78,7 @@ public class PortPairGroupManager implements PortPairGroupService {
73 @Deactivate 78 @Deactivate
74 public void deactivate() { 79 public void deactivate() {
75 portPairGroupStore.destroy(); 80 portPairGroupStore.destroy();
81 + listeners.clear();
76 log.info("Stopped"); 82 log.info("Stopped");
77 } 83 }
78 84
...@@ -143,4 +149,16 @@ public class PortPairGroupManager implements PortPairGroupService { ...@@ -143,4 +149,16 @@ public class PortPairGroupManager implements PortPairGroupService {
143 } 149 }
144 return true; 150 return true;
145 } 151 }
152 +
153 + @Override
154 + public void addListener(PortPairGroupListener listener) {
155 + checkNotNull(listener, LISTENER_NOT_NULL);
156 + listeners.add(listener);
157 + }
158 +
159 + @Override
160 + public void removeListener(PortPairGroupListener listener) {
161 + checkNotNull(listener, LISTENER_NOT_NULL);
162 + listeners.remove(listener);
163 + }
146 } 164 }
......