Merge "BUG-2661: Sonar issue"
[openflowplugin.git] / test-common / src / main / java / org / opendaylight / openflowplugin / testcommon / DropTestRpcProvider.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.sal.binding.api.NotificationProviderService;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
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 DropTestRpcProvider implements AutoCloseable {
19     private static final Logger LOG = LoggerFactory.getLogger(DropTestDsProvider.class);
20
21     private SalFlowService flowService;
22     private NotificationProviderService notificationService;
23     private DropTestRpcSender commiter = new DropTestRpcSender();
24     private boolean active = false;
25
26     /**
27      * @param flowService value for setter
28      */
29     public void setFlowService(final SalFlowService flowService) {
30         this.flowService = flowService;
31     }
32
33     /**
34      * @param notificationService value for setter
35      */
36     public void setNotificationService(final NotificationProviderService notificationService) {
37         this.notificationService = notificationService;
38     }
39
40     /**
41      * activates drop responder
42      */
43     public void start() {
44         commiter.setFlowService(flowService);
45         commiter.setNotificationService(notificationService);
46         commiter.start();
47         active = true;
48         LOG.debug("DropTestProvider Started.");
49     }
50
51     /**
52      * @return message counts
53      */
54     public DropTestStats getStats() {
55         if (this.commiter != null) {
56             return commiter.getStats();
57         } else {
58             return new DropTestStats("Not initialized yet.");
59         }
60     }
61
62     /**
63      * reset message counts
64      */
65     public void clearStats() {
66         if (commiter != null) {
67             commiter.clearStats();
68         }
69     }
70
71     @Override
72     public void close() {
73         LOG.debug("DropTestProvider stopped.");
74         if (commiter != null) {
75             commiter.close();
76             active = false;
77         }
78     }
79
80     /**
81      * @return the active
82      */
83     public boolean isActive() {
84         return active;
85     }
86 }