[ONOS-3111] port-pair-group manager modification

Change-Id: I37df58e8589147624393a84efdf28e0bb8dfa29c
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 efee0eb..daacfa9 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
@@ -15,13 +15,14 @@
  */
 package org.onosproject.vtnrsc.portpairgroup;
 
+import org.onosproject.event.ListenerService;
 import org.onosproject.vtnrsc.PortPairGroup;
 import org.onosproject.vtnrsc.PortPairGroupId;
 
 /**
  * Service for interacting with the inventory of port pair groups.
  */
-public interface PortPairGroupService {
+public interface PortPairGroupService extends ListenerService<PortPairGroupEvent, PortPairGroupListener> {
 
     /**
      * Returns if the port pair group is existed.
@@ -77,18 +78,4 @@
      * @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 5f80ef6..fd38cd9 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,7 +19,6 @@
 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;
@@ -28,6 +27,7 @@
 import org.apache.felix.scr.annotations.ReferenceCardinality;
 import org.apache.felix.scr.annotations.Service;
 import org.onlab.util.KryoNamespace;
+import org.onosproject.event.AbstractListenerManager;
 import org.onosproject.store.serializers.KryoNamespaces;
 import org.onosproject.store.service.EventuallyConsistentMap;
 import org.onosproject.store.service.MultiValuedTimestamp;
@@ -35,25 +35,25 @@
 import org.onosproject.store.service.WallClockTimestamp;
 import org.onosproject.vtnrsc.PortPairGroup;
 import org.onosproject.vtnrsc.PortPairGroupId;
+import org.onosproject.vtnrsc.portpairgroup.PortPairGroupEvent;
 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.
  */
 @Component(immediate = true)
 @Service
-public class PortPairGroupManager implements PortPairGroupService {
+public class PortPairGroupManager extends AbstractListenerManager<PortPairGroupEvent, PortPairGroupListener> implements
+        PortPairGroupService {
 
     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)
@@ -78,7 +78,6 @@
     @Deactivate
     public void deactivate() {
         portPairGroupStore.destroy();
-        listeners.clear();
         log.info("Stopped");
     }
 
@@ -111,7 +110,7 @@
         portPairGroupStore.put(portPairGroup.portPairGroupId(), portPairGroup);
         if (!portPairGroupStore.containsKey(portPairGroup.portPairGroupId())) {
             log.debug("The portPairGroup is created failed which identifier was {}", portPairGroup.portPairGroupId()
-                      .toString());
+                    .toString());
             return false;
         }
         return true;
@@ -149,16 +148,4 @@
         }
         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);
-    }
 }