Bug 1458 - Migrate to next MD-SAL dataStore API
[openflowplugin.git] / drop-test / src / main / java / org / opendaylight / openflowplugin / droptest / DropTestProvider.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowplugin.droptest;
9
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
12 import org.opendaylight.yangtools.concepts.Registration;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 @SuppressWarnings("all")
17 public class DropTestProvider implements AutoCloseable {
18     private final static Logger LOG = LoggerFactory.getLogger(DropTestProvider.class);
19
20     private DataBroker _dataService;
21     private NotificationProviderService _notificationService;
22     private Registration listenerRegistration;
23     private final DropTestCommiter commiter = new DropTestCommiter(this);
24
25     public DropTestStats getStats() {
26         return this.commiter.getStats();
27     }
28
29     public void clearStats() {
30         this.commiter.clearStats();
31     }
32
33     public DataBroker getDataService() {
34         return this._dataService;
35     }
36
37     public void setDataService(final DataBroker dataService) {
38         this._dataService = dataService;
39     }
40
41
42     public NotificationProviderService getNotificationService() {
43         return this._notificationService;
44     }
45
46     public void setNotificationService(final NotificationProviderService notificationService) {
47         this._notificationService = notificationService;
48     }
49
50     public void start() {
51         this.listenerRegistration = this.getNotificationService().registerNotificationListener(commiter);
52         LOG.debug("DropTestProvider Started.");
53     }
54
55     public void close() {
56         try {
57             LOG.debug("DropTestProvider stopped.");
58             if (this.listenerRegistration != null) {
59                 this.listenerRegistration.close();
60             }
61         } catch (Exception e) {
62             throw new Error(e);
63         }
64     }
65 }