Mahesh Poojary S
Committed by Gerrit Code Review

[ONOS-3110] port-pair manager modification

Change-Id: I0ad39054182016e09b0c665270f70de29cccc56a
......@@ -15,13 +15,13 @@
*/
package org.onosproject.vtnrsc.portpair;
import org.onosproject.event.ListenerService;
import org.onosproject.vtnrsc.PortPair;
import org.onosproject.vtnrsc.PortPairId;
/**
* Service for interacting with the inventory of port pairs.
*/
public interface PortPairService {
public interface PortPairService extends ListenerService<PortPairEvent, PortPairListener> {
/**
* Returns if the port pair is existed.
......@@ -77,18 +77,4 @@ 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,7 +19,6 @@ 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;
......@@ -28,6 +27,7 @@ import org.apache.felix.scr.annotations.Reference;
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.StorageService;
import org.onosproject.store.service.WallClockTimestamp;
import org.onosproject.vtnrsc.PortPair;
import org.onosproject.vtnrsc.PortPairId;
import org.onosproject.vtnrsc.portpair.PortPairEvent;
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.
*/
@Component(immediate = true)
@Service
public class PortPairManager implements PortPairService {
public class PortPairManager extends AbstractListenerManager<PortPairEvent, PortPairListener> implements
PortPairService {
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)
......@@ -67,10 +67,11 @@ public class PortPairManager implements PortPairService {
.register(MultiValuedTimestamp.class)
.register(PortPair.class);
portPairStore = storageService
.<PortPairId, PortPair>eventuallyConsistentMapBuilder()
.withName("portpairstore").withSerializer(serializer)
.withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
portPairStore = storageService.<PortPairId, PortPair>eventuallyConsistentMapBuilder()
.withName("portpairstore")
.withSerializer(serializer)
.withTimestampProvider((k, v) -> new WallClockTimestamp())
.build();
log.info("Started");
}
......@@ -78,7 +79,6 @@ public class PortPairManager implements PortPairService {
@Deactivate
public void deactivate() {
portPairStore.destroy();
listeners.clear();
log.info("Stopped");
}
......@@ -110,8 +110,7 @@ public class PortPairManager implements PortPairService {
portPairStore.put(portPair.portPairId(), portPair);
if (!portPairStore.containsKey(portPair.portPairId())) {
log.debug("The portPair is created failed which identifier was {}", portPair.portPairId()
.toString());
log.debug("The portPair is created failed which identifier was {}", portPair.portPairId().toString());
return false;
}
return true;
......@@ -122,16 +121,14 @@ public class PortPairManager implements PortPairService {
checkNotNull(portPair, PORT_PAIR_NULL);
if (!portPairStore.containsKey(portPair.portPairId())) {
log.debug("The portPair is not exist whose identifier was {} ",
portPair.portPairId().toString());
log.debug("The portPair is not exist whose identifier was {} ", portPair.portPairId().toString());
return false;
}
portPairStore.put(portPair.portPairId(), portPair);
if (!portPair.equals(portPairStore.get(portPair.portPairId()))) {
log.debug("The portPair is updated failed whose identifier was {} ",
portPair.portPairId().toString());
log.debug("The portPair is updated failed whose identifier was {} ", portPair.portPairId().toString());
return false;
}
return true;
......@@ -143,22 +140,9 @@ public class PortPairManager implements PortPairService {
portPairStore.remove(portPairId);
if (portPairStore.containsKey(portPairId)) {
log.debug("The portPair is removed failed whose identifier was {}",
portPairId.toString());
log.debug("The portPair is removed failed whose identifier was {}", portPairId.toString());
return false;
}
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);
}
}
......