Bump upstreams
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / DefaultDiagStatusProvider.java
1 /*
2  * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. 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.impl;
9
10 import javax.annotation.PreDestroy;
11 import javax.inject.Inject;
12 import javax.inject.Singleton;
13 import org.opendaylight.infrautils.diagstatus.DiagStatusService;
14 import org.opendaylight.infrautils.diagstatus.ServiceDescriptor;
15 import org.opendaylight.infrautils.diagstatus.ServiceRegistration;
16 import org.opendaylight.infrautils.diagstatus.ServiceState;
17 import org.osgi.service.component.annotations.Activate;
18 import org.osgi.service.component.annotations.Component;
19 import org.osgi.service.component.annotations.Deactivate;
20 import org.osgi.service.component.annotations.Reference;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23
24 @Singleton
25 @Component
26 public final class DefaultDiagStatusProvider implements DiagStatusProvider {
27     private static final Logger LOG = LoggerFactory.getLogger(DefaultDiagStatusProvider.class);
28     private static final String OPENFLOW_SERVICE_NAME = "OPENFLOW";
29
30     private ServiceRegistration reg;
31
32     @Inject
33     @Activate
34     public DefaultDiagStatusProvider(@Reference final DiagStatusService diagStatusService) {
35         reg = diagStatusService.register(OPENFLOW_SERVICE_NAME);
36     }
37
38     @PreDestroy
39     @Deactivate
40     public void close() {
41         if (reg != null) {
42             reg.close();
43             reg = null;
44         }
45     }
46
47     @Override
48     public void reportStatus(final ServiceState serviceState) {
49         LOG.debug("reporting status as {} for {}", serviceState, OPENFLOW_SERVICE_NAME);
50         reg.report(new ServiceDescriptor(OPENFLOW_SERVICE_NAME, serviceState));
51     }
52
53     @Override
54     public void reportStatus(final ServiceState serviceState, final Throwable throwable) {
55         LOG.debug("reporting status as {} for {}", serviceState, OPENFLOW_SERVICE_NAME);
56         reg.report(new ServiceDescriptor(OPENFLOW_SERVICE_NAME, throwable));
57     }
58
59     @Override
60     public void reportStatus(final ServiceState serviceState, final String description) {
61         LOG.debug("reporting status as {} for {}", serviceState, OPENFLOW_SERVICE_NAME);
62         reg.report(new ServiceDescriptor(OPENFLOW_SERVICE_NAME, serviceState, description));
63     }
64 }