[ONOS-3117] adding listener to Port-Pair-Group Manager
Change-Id: I33dcdc6172e4a5a596d0e376e224ee3eb42387cd
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupService.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupService.java
index 77f483f..efee0eb 100644
--- a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupService.java
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/PortPairGroupService.java
@@ -77,4 +77,18 @@
* @return true if the give port pair group is deleted successfully.
*/
boolean removePortPairGroup(PortPairGroupId portPairGroupId);
+
+ /**
+ * Adds the specified listener to Port-Pair-Group manager.
+ *
+ * @param listener Port-Pair-Group listener
+ */
+ void addListener(PortPairGroupListener listener);
+
+ /**
+ * Removes the specified listener to Port-Pair-Group manager.
+ *
+ * @param listener Port-Pair-Group listener
+ */
+ void removeListener(PortPairGroupListener listener);
}
diff --git a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/PortPairGroupManager.java b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/PortPairGroupManager.java
index 55fb4e4..5f80ef6 100644
--- a/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/PortPairGroupManager.java
+++ b/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/PortPairGroupManager.java
@@ -19,6 +19,7 @@
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Collections;
+import java.util.Set;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
@@ -34,9 +35,12 @@
import org.onosproject.store.service.WallClockTimestamp;
import org.onosproject.vtnrsc.PortPairGroup;
import org.onosproject.vtnrsc.PortPairGroupId;
+import org.onosproject.vtnrsc.portpairgroup.PortPairGroupListener;
import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
import org.slf4j.Logger;
+import com.google.common.collect.Sets;
+
/**
* Provides implementation of the portPairGroupService.
*/
@@ -44,11 +48,12 @@
@Service
public class PortPairGroupManager implements PortPairGroupService {
- private final Logger log = getLogger(getClass());
-
private static final String PORT_PAIR_GROUP_ID_NULL = "PortPairGroup ID cannot be null";
private static final String PORT_PAIR_GROUP_NULL = "PortPairGroup cannot be null";
+ private static final String LISTENER_NOT_NULL = "Listener cannot be null";
+ private final Logger log = getLogger(getClass());
+ private final Set<PortPairGroupListener> listeners = Sets.newCopyOnWriteArraySet();
private EventuallyConsistentMap<PortPairGroupId, PortPairGroup> portPairGroupStore;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -73,6 +78,7 @@
@Deactivate
public void deactivate() {
portPairGroupStore.destroy();
+ listeners.clear();
log.info("Stopped");
}
@@ -143,4 +149,16 @@
}
return true;
}
+
+ @Override
+ public void addListener(PortPairGroupListener listener) {
+ checkNotNull(listener, LISTENER_NOT_NULL);
+ listeners.add(listener);
+ }
+
+ @Override
+ public void removeListener(PortPairGroupListener listener) {
+ checkNotNull(listener, LISTENER_NOT_NULL);
+ listeners.remove(listener);
+ }
}