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
*/
Collection<Meter> getAllMeters();
/**
* Fetches the meters by the device id.
*
* @param deviceId a device id
* @return a collection of meters
*/
Collection<Meter> getMeters(DeviceId deviceId);
}
......
......@@ -23,6 +23,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.TriConsumer;
import org.onosproject.net.DeviceId;
import org.onosproject.net.meter.DefaultMeter;
import org.onosproject.net.meter.Meter;
import org.onosproject.net.meter.MeterEvent;
......@@ -40,7 +41,6 @@ import org.onosproject.net.meter.MeterState;
import org.onosproject.net.meter.MeterStore;
import org.onosproject.net.meter.MeterStoreDelegate;
import org.onosproject.net.meter.MeterStoreResult;
import org.onosproject.net.DeviceId;
import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.onosproject.store.service.AtomicCounter;
......@@ -160,6 +160,12 @@ public class MeterManager extends AbstractListenerProviderRegistry<MeterEvent, M
}
@Override
public Collection<Meter> getMeters(DeviceId deviceId) {
return store.getAllMeters().stream().filter(m ->
m.deviceId().equals(deviceId)).collect(Collectors.toList());
}
@Override
public Collection<Meter> getAllMeters() {
return store.getAllMeters();
}
......