Jian Li
Committed by Gerrit Code Review

Add getMeters method for obtaining meter collection by device id

Change-Id: Ie5137ef8acce7643a58c2faa00b7027e3b9f38fa
...@@ -60,4 +60,11 @@ public interface MeterService ...@@ -60,4 +60,11 @@ public interface MeterService
60 */ 60 */
61 Collection<Meter> getAllMeters(); 61 Collection<Meter> getAllMeters();
62 62
63 + /**
64 + * Fetches the meters by the device id.
65 + *
66 + * @param deviceId a device id
67 + * @return a collection of meters
68 + */
69 + Collection<Meter> getMeters(DeviceId deviceId);
63 } 70 }
......
...@@ -23,6 +23,7 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -23,6 +23,7 @@ import org.apache.felix.scr.annotations.Reference;
23 import org.apache.felix.scr.annotations.ReferenceCardinality; 23 import org.apache.felix.scr.annotations.ReferenceCardinality;
24 import org.apache.felix.scr.annotations.Service; 24 import org.apache.felix.scr.annotations.Service;
25 import org.onlab.util.TriConsumer; 25 import org.onlab.util.TriConsumer;
26 +import org.onosproject.net.DeviceId;
26 import org.onosproject.net.meter.DefaultMeter; 27 import org.onosproject.net.meter.DefaultMeter;
27 import org.onosproject.net.meter.Meter; 28 import org.onosproject.net.meter.Meter;
28 import org.onosproject.net.meter.MeterEvent; 29 import org.onosproject.net.meter.MeterEvent;
...@@ -40,7 +41,6 @@ import org.onosproject.net.meter.MeterState; ...@@ -40,7 +41,6 @@ import org.onosproject.net.meter.MeterState;
40 import org.onosproject.net.meter.MeterStore; 41 import org.onosproject.net.meter.MeterStore;
41 import org.onosproject.net.meter.MeterStoreDelegate; 42 import org.onosproject.net.meter.MeterStoreDelegate;
42 import org.onosproject.net.meter.MeterStoreResult; 43 import org.onosproject.net.meter.MeterStoreResult;
43 -import org.onosproject.net.DeviceId;
44 import org.onosproject.net.provider.AbstractListenerProviderRegistry; 44 import org.onosproject.net.provider.AbstractListenerProviderRegistry;
45 import org.onosproject.net.provider.AbstractProviderService; 45 import org.onosproject.net.provider.AbstractProviderService;
46 import org.onosproject.store.service.AtomicCounter; 46 import org.onosproject.store.service.AtomicCounter;
...@@ -160,6 +160,12 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M ...@@ -160,6 +160,12 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M
160 } 160 }
161 161
162 @Override 162 @Override
163 + public Collection<Meter> getMeters(DeviceId deviceId) {
164 + return store.getAllMeters().stream().filter(m ->
165 + m.deviceId().equals(deviceId)).collect(Collectors.toList());
166 + }
167 +
168 + @Override
163 public Collection<Meter> getAllMeters() { 169 public Collection<Meter> getAllMeters() {
164 return store.getAllMeters(); 170 return store.getAllMeters();
165 } 171 }
......