Mahesh Poojary Huawei

[ONOS-3117] add listener to PortPairManager

Change-Id: I261527308da725996dbae34bddb855c0cacc6367
......@@ -77,4 +77,18 @@ public interface PortPairService {
* @return true if the give port pair is deleted successfully.
*/
boolean removePortPair(PortPairId portPairId);
/**
* Adds the specified listener to Port-Pair manager.
*
* @param listener Port-Pair listener
*/
void addListener(PortPairListener listener);
/**
* Removes the specified listener to Port-Pair manager.
*
* @param listener Port-Pair listener
*/
void removeListener(PortPairListener listener);
}
......
......@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
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.StorageService;
import org.onosproject.store.service.WallClockTimestamp;
import org.onosproject.vtnrsc.PortPair;
import org.onosproject.vtnrsc.PortPairId;
import org.onosproject.vtnrsc.portpair.PortPairListener;
import org.onosproject.vtnrsc.portpair.PortPairService;
import org.slf4j.Logger;
import com.google.common.collect.Sets;
/**
* Provides implementation of the portPairService.
*/
......@@ -44,11 +48,12 @@ import org.slf4j.Logger;
@Service
public class PortPairManager implements PortPairService {
private final Logger log = getLogger(getClass());
private static final String PORT_PAIR_ID_NULL = "PortPair ID cannot be null";
private static final String PORT_PAIR_NULL = "PortPair cannot be null";
private static final String LISTENER_NOT_NULL = "Listener cannot be null";
private final Logger log = getLogger(getClass());
private final Set<PortPairListener> listeners = Sets.newCopyOnWriteArraySet();
private EventuallyConsistentMap<PortPairId, PortPair> portPairStore;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......@@ -73,6 +78,7 @@ public class PortPairManager implements PortPairService {
@Deactivate
public void deactivate() {
portPairStore.destroy();
listeners.clear();
log.info("Stopped");
}
......@@ -143,4 +149,16 @@ public class PortPairManager implements PortPairService {
}
return true;
}
@Override
public void addListener(PortPairListener listener) {
checkNotNull(listener, LISTENER_NOT_NULL);
listeners.add(listener);
}
@Override
public void removeListener(PortPairListener listener) {
checkNotNull(listener, LISTENER_NOT_NULL);
listeners.remove(listener);
}
}
......