Mahesh Poojary S
Committed by Gerrit Code Review

[ONOS-3110] port-pair manager modification

Change-Id: I0ad39054182016e09b0c665270f70de29cccc56a
...@@ -15,13 +15,13 @@ ...@@ -15,13 +15,13 @@
15 */ 15 */
16 package org.onosproject.vtnrsc.portpair; 16 package org.onosproject.vtnrsc.portpair;
17 17
18 +import org.onosproject.event.ListenerService;
18 import org.onosproject.vtnrsc.PortPair; 19 import org.onosproject.vtnrsc.PortPair;
19 import org.onosproject.vtnrsc.PortPairId; 20 import org.onosproject.vtnrsc.PortPairId;
20 -
21 /** 21 /**
22 * Service for interacting with the inventory of port pairs. 22 * Service for interacting with the inventory of port pairs.
23 */ 23 */
24 -public interface PortPairService { 24 +public interface PortPairService extends ListenerService<PortPairEvent, PortPairListener> {
25 25
26 /** 26 /**
27 * Returns if the port pair is existed. 27 * Returns if the port pair is existed.
...@@ -77,18 +77,4 @@ public interface PortPairService { ...@@ -77,18 +77,4 @@ public interface PortPairService {
77 * @return true if the give port pair is deleted successfully. 77 * @return true if the give port pair is deleted successfully.
78 */ 78 */
79 boolean removePortPair(PortPairId portPairId); 79 boolean removePortPair(PortPairId portPairId);
80 -
81 - /**
82 - * Adds the specified listener to Port-Pair manager.
83 - *
84 - * @param listener Port-Pair listener
85 - */
86 - void addListener(PortPairListener listener);
87 -
88 - /**
89 - * Removes the specified listener to Port-Pair manager.
90 - *
91 - * @param listener Port-Pair listener
92 - */
93 - void removeListener(PortPairListener listener);
94 } 80 }
......
...@@ -19,7 +19,6 @@ import static com.google.common.base.Preconditions.checkNotNull; ...@@ -19,7 +19,6 @@ 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;
23 22
24 import org.apache.felix.scr.annotations.Activate; 23 import org.apache.felix.scr.annotations.Activate;
25 import org.apache.felix.scr.annotations.Component; 24 import org.apache.felix.scr.annotations.Component;
...@@ -28,6 +27,7 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -28,6 +27,7 @@ import org.apache.felix.scr.annotations.Reference;
28 import org.apache.felix.scr.annotations.ReferenceCardinality; 27 import org.apache.felix.scr.annotations.ReferenceCardinality;
29 import org.apache.felix.scr.annotations.Service; 28 import org.apache.felix.scr.annotations.Service;
30 import org.onlab.util.KryoNamespace; 29 import org.onlab.util.KryoNamespace;
30 +import org.onosproject.event.AbstractListenerManager;
31 import org.onosproject.store.serializers.KryoNamespaces; 31 import org.onosproject.store.serializers.KryoNamespaces;
32 import org.onosproject.store.service.EventuallyConsistentMap; 32 import org.onosproject.store.service.EventuallyConsistentMap;
33 import org.onosproject.store.service.MultiValuedTimestamp; 33 import org.onosproject.store.service.MultiValuedTimestamp;
...@@ -35,25 +35,25 @@ import org.onosproject.store.service.StorageService; ...@@ -35,25 +35,25 @@ import org.onosproject.store.service.StorageService;
35 import org.onosproject.store.service.WallClockTimestamp; 35 import org.onosproject.store.service.WallClockTimestamp;
36 import org.onosproject.vtnrsc.PortPair; 36 import org.onosproject.vtnrsc.PortPair;
37 import org.onosproject.vtnrsc.PortPairId; 37 import org.onosproject.vtnrsc.PortPairId;
38 +import org.onosproject.vtnrsc.portpair.PortPairEvent;
38 import org.onosproject.vtnrsc.portpair.PortPairListener; 39 import org.onosproject.vtnrsc.portpair.PortPairListener;
39 import org.onosproject.vtnrsc.portpair.PortPairService; 40 import org.onosproject.vtnrsc.portpair.PortPairService;
40 import org.slf4j.Logger; 41 import org.slf4j.Logger;
41 42
42 -import com.google.common.collect.Sets;
43 -
44 /** 43 /**
45 * Provides implementation of the portPairService. 44 * Provides implementation of the portPairService.
46 */ 45 */
47 @Component(immediate = true) 46 @Component(immediate = true)
48 @Service 47 @Service
49 -public class PortPairManager implements PortPairService { 48 +public class PortPairManager extends AbstractListenerManager<PortPairEvent, PortPairListener> implements
49 + PortPairService {
50 50
51 private static final String PORT_PAIR_ID_NULL = "PortPair ID cannot be null"; 51 private static final String PORT_PAIR_ID_NULL = "PortPair ID cannot be null";
52 private static final String PORT_PAIR_NULL = "PortPair cannot be null"; 52 private static final String PORT_PAIR_NULL = "PortPair cannot be null";
53 private static final String LISTENER_NOT_NULL = "Listener cannot be null"; 53 private static final String LISTENER_NOT_NULL = "Listener cannot be null";
54 54
55 private final Logger log = getLogger(getClass()); 55 private final Logger log = getLogger(getClass());
56 - private final Set<PortPairListener> listeners = Sets.newCopyOnWriteArraySet(); 56 +
57 private EventuallyConsistentMap<PortPairId, PortPair> portPairStore; 57 private EventuallyConsistentMap<PortPairId, PortPair> portPairStore;
58 58
59 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 59 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -67,10 +67,11 @@ public class PortPairManager implements PortPairService { ...@@ -67,10 +67,11 @@ public class PortPairManager implements PortPairService {
67 .register(MultiValuedTimestamp.class) 67 .register(MultiValuedTimestamp.class)
68 .register(PortPair.class); 68 .register(PortPair.class);
69 69
70 - portPairStore = storageService 70 + portPairStore = storageService.<PortPairId, PortPair>eventuallyConsistentMapBuilder()
71 - .<PortPairId, PortPair>eventuallyConsistentMapBuilder() 71 + .withName("portpairstore")
72 - .withName("portpairstore").withSerializer(serializer) 72 + .withSerializer(serializer)
73 - .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); 73 + .withTimestampProvider((k, v) -> new WallClockTimestamp())
74 + .build();
74 75
75 log.info("Started"); 76 log.info("Started");
76 } 77 }
...@@ -78,7 +79,6 @@ public class PortPairManager implements PortPairService { ...@@ -78,7 +79,6 @@ public class PortPairManager implements PortPairService {
78 @Deactivate 79 @Deactivate
79 public void deactivate() { 80 public void deactivate() {
80 portPairStore.destroy(); 81 portPairStore.destroy();
81 - listeners.clear();
82 log.info("Stopped"); 82 log.info("Stopped");
83 } 83 }
84 84
...@@ -110,8 +110,7 @@ public class PortPairManager implements PortPairService { ...@@ -110,8 +110,7 @@ public class PortPairManager implements PortPairService {
110 110
111 portPairStore.put(portPair.portPairId(), portPair); 111 portPairStore.put(portPair.portPairId(), portPair);
112 if (!portPairStore.containsKey(portPair.portPairId())) { 112 if (!portPairStore.containsKey(portPair.portPairId())) {
113 - log.debug("The portPair is created failed which identifier was {}", portPair.portPairId() 113 + log.debug("The portPair is created failed which identifier was {}", portPair.portPairId().toString());
114 - .toString());
115 return false; 114 return false;
116 } 115 }
117 return true; 116 return true;
...@@ -122,16 +121,14 @@ public class PortPairManager implements PortPairService { ...@@ -122,16 +121,14 @@ public class PortPairManager implements PortPairService {
122 checkNotNull(portPair, PORT_PAIR_NULL); 121 checkNotNull(portPair, PORT_PAIR_NULL);
123 122
124 if (!portPairStore.containsKey(portPair.portPairId())) { 123 if (!portPairStore.containsKey(portPair.portPairId())) {
125 - log.debug("The portPair is not exist whose identifier was {} ", 124 + log.debug("The portPair is not exist whose identifier was {} ", portPair.portPairId().toString());
126 - portPair.portPairId().toString());
127 return false; 125 return false;
128 } 126 }
129 127
130 portPairStore.put(portPair.portPairId(), portPair); 128 portPairStore.put(portPair.portPairId(), portPair);
131 129
132 if (!portPair.equals(portPairStore.get(portPair.portPairId()))) { 130 if (!portPair.equals(portPairStore.get(portPair.portPairId()))) {
133 - log.debug("The portPair is updated failed whose identifier was {} ", 131 + log.debug("The portPair is updated failed whose identifier was {} ", portPair.portPairId().toString());
134 - portPair.portPairId().toString());
135 return false; 132 return false;
136 } 133 }
137 return true; 134 return true;
...@@ -143,22 +140,9 @@ public class PortPairManager implements PortPairService { ...@@ -143,22 +140,9 @@ public class PortPairManager implements PortPairService {
143 140
144 portPairStore.remove(portPairId); 141 portPairStore.remove(portPairId);
145 if (portPairStore.containsKey(portPairId)) { 142 if (portPairStore.containsKey(portPairId)) {
146 - log.debug("The portPair is removed failed whose identifier was {}", 143 + log.debug("The portPair is removed failed whose identifier was {}", portPairId.toString());
147 - portPairId.toString());
148 return false; 144 return false;
149 } 145 }
150 return true; 146 return true;
151 } 147 }
152 -
153 - @Override
154 - public void addListener(PortPairListener listener) {
155 - checkNotNull(listener, LISTENER_NOT_NULL);
156 - listeners.add(listener);
157 - }
158 -
159 - @Override
160 - public void removeListener(PortPairListener listener) {
161 - checkNotNull(listener, LISTENER_NOT_NULL);
162 - listeners.remove(listener);
163 - }
164 } 148 }
......