64f29c8cd31bd1ded902d5dd29ffaf8248f552d4
[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.sal.binding.api.NotificationProviderService;
11 import org.opendaylight.controller.sal.binding.api.data.DataProviderService;
12 import org.opendaylight.yangtools.concepts.Registration;
13 import org.opendaylight.yangtools.yang.binding.NotificationListener;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 @SuppressWarnings("all")
18 public class DropTestProvider implements AutoCloseable {
19     private final static Logger LOG = LoggerFactory.getLogger(DropTestProvider.class);
20
21     private DataProviderService _dataService;
22     private NotificationProviderService _notificationService;
23     private Registration listenerRegistration;
24     private final DropTestCommiter commiter = new DropTestCommiter(this);
25
26     public DropTestStats getStats() {
27         return this.commiter.getStats();
28     }
29     
30     public void clearStats() {
31         this.commiter.clearStats();
32     }
33     
34     public DataProviderService getDataService() {
35         return this._dataService;
36     }
37
38     public void setDataService(final DataProviderService dataService) {
39         this._dataService = dataService;
40     }
41
42
43     public NotificationProviderService getNotificationService() {
44         return this._notificationService;
45     }
46
47     public void setNotificationService(final NotificationProviderService notificationService) {
48         this._notificationService = notificationService;
49     }
50
51     public void start() {
52         this.listenerRegistration = this.getNotificationService().registerNotificationListener(commiter);
53         LOG.debug("DropTestProvider Started.");
54     }
55
56     public void close() {
57         try {
58             LOG.debug("DropTestProvider stopped.");
59             if (this.listenerRegistration != null) {
60                 this.listenerRegistration.close();
61             }
62         } catch (Exception e) {
63             throw new Error(e);
64         }
65     }
66 }