Switch to MD-SAL APIs
[openflowplugin.git] / test-common / src / main / java / org / opendaylight / openflowplugin / testcommon / DropTestDsProvider.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.testcommon;
9
10 import org.opendaylight.mdsal.binding.api.DataBroker;
11 import org.opendaylight.mdsal.binding.api.NotificationService;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14
15 /**
16  * Provides activation and deactivation of drop responder service - responds on packetIn.
17  */
18 public class DropTestDsProvider implements AutoCloseable {
19     private static final Logger LOG = LoggerFactory.getLogger(DropTestDsProvider.class);
20
21     private DataBroker dataService;
22     private NotificationService notificationService;
23     private final DropTestCommiter commiter = new DropTestCommiter();
24     private boolean active = false;
25
26     /**
27      * Returns the message counts.
28      */
29     public DropTestStats getStats() {
30         return commiter.getStats();
31     }
32
33     /**
34      * Reset message counts.
35      */
36     public void clearStats() {
37         commiter.clearStats();
38     }
39
40     public void setDataService(final DataBroker dataService) {
41         this.dataService = dataService;
42     }
43
44     public void setNotificationService(final NotificationService notificationService) {
45         this.notificationService = notificationService;
46     }
47
48     /**
49      * Activates the drop responder.
50      */
51     public void start() {
52         commiter.setDataService(dataService);
53         commiter.setNotificationService(notificationService);
54         commiter.start();
55         active = true;
56         LOG.debug("DropTestProvider Started.");
57     }
58
59     @Override
60     public void close() {
61         LOG.debug("DropTestProvider stopped.");
62         if (commiter != null) {
63             commiter.close();
64             active = false;
65         }
66     }
67
68     /**
69      * Returns the active state.
70      */
71     public boolean isActive() {
72         return active;
73     }
74 }