ad74e8b7944f7806b7c3d4e0bca757e9c6b2eac6
[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.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.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      * @return 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     /**
41      * @param dataService value for setter
42      */
43     public void setDataService(final DataBroker dataService) {
44         this.dataService = dataService;
45     }
46
47
48     /**
49      * @param notificationService value for setter
50      */
51     public void setNotificationService(final NotificationService notificationService) {
52         this.notificationService = notificationService;
53     }
54
55     /**
56      * activates the drop responder
57      */
58     public void start() {
59         commiter.setDataService(dataService);
60         commiter.setNotificationService(notificationService);
61         commiter.start();
62         active = true;
63         LOG.debug("DropTestProvider Started.");
64     }
65
66     @Override
67     public void close() {
68         LOG.debug("DropTestProvider stopped.");
69         if (commiter != null) {
70             commiter.close();
71             active = false;
72         }
73     }
74
75     /**
76      * @return the active
77      */
78     public boolean isActive() {
79         return active;
80     }
81 }