+package org.opendaylight.controller.md.statistics.manager;
+
+import org.eclipse.xtext.xbase.lib.Exceptions;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
+import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.OpendaylightGroupStatisticsService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.OpendaylightMeterStatisticsService;
+import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.NotificationListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class StatisticsProvider implements AutoCloseable {
+
+ public final static Logger spLogger = LoggerFactory.getLogger(StatisticsProvider.class);
+
+ private DataProviderService dps;
+
+ private NotificationProviderService nps;
+
+ private OpendaylightGroupStatisticsService groupStatsService;
+
+ private OpendaylightMeterStatisticsService meterStatsService;
+
+ public DataProviderService getDataService() {
+ return this.dps;
+ }
+
+ public void setDataService(final DataProviderService dataService) {
+ this.dps = dataService;
+ }
+
+ public NotificationProviderService getNotificationService() {
+ return this.nps;
+ }
+
+ public void setNotificationService(final NotificationProviderService notificationService) {
+ this.nps = notificationService;
+ }
+
+ private final StatisticsUpdateCommiter updateCommiter = new StatisticsUpdateCommiter(StatisticsProvider.this);
+
+ private Registration<NotificationListener> listenerRegistration;
+
+ public void start() {
+
+ NotificationProviderService nps = this.getNotificationService();
+ Registration<NotificationListener> registerNotificationListener = nps.registerNotificationListener(this.updateCommiter);
+ this.listenerRegistration = registerNotificationListener;
+
+ // Get Group/Meter statistics service instance
+ groupStatsService = StatisticsManagerActivator.getProviderContext().getRpcService(OpendaylightGroupStatisticsService.class);
+
+ meterStatsService = StatisticsManagerActivator.getProviderContext().getRpcService(OpendaylightMeterStatisticsService.class);
+
+ spLogger.info("Statistics Provider started.");
+ }
+
+ protected DataModificationTransaction startChange() {
+
+ DataProviderService dps = this.getDataService();
+ return dps.beginTransaction();
+ }
+
+ @Override
+ public void close(){
+
+ try {
+ spLogger.info("Statistics Provider stopped.");
+ if (this.listenerRegistration != null) {
+
+ this.listenerRegistration.close();
+
+ }
+ } catch (Throwable e) {
+ throw Exceptions.sneakyThrow(e);
+ }
+
+ }
+
+}