/* * Copyright (c) 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.openflowplugin.impl; import javax.annotation.PreDestroy; import javax.inject.Inject; import javax.inject.Singleton; import org.opendaylight.infrautils.diagstatus.DiagStatusService; import org.opendaylight.infrautils.diagstatus.ServiceDescriptor; import org.opendaylight.infrautils.diagstatus.ServiceRegistration; import org.opendaylight.infrautils.diagstatus.ServiceState; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; import org.osgi.service.component.annotations.Reference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Singleton @Component public final class DefaultDiagStatusProvider implements DiagStatusProvider { private static final Logger LOG = LoggerFactory.getLogger(DefaultDiagStatusProvider.class); private static final String OPENFLOW_SERVICE_NAME = "OPENFLOW"; private ServiceRegistration reg; @Inject @Activate public DefaultDiagStatusProvider(@Reference final DiagStatusService diagStatusService) { reg = diagStatusService.register(OPENFLOW_SERVICE_NAME); } @PreDestroy @Deactivate public void close() { if (reg != null) { reg.close(); reg = null; } } @Override public void reportStatus(final ServiceState serviceState) { LOG.debug("reporting status as {} for {}", serviceState, OPENFLOW_SERVICE_NAME); reg.report(new ServiceDescriptor(OPENFLOW_SERVICE_NAME, serviceState)); } @Override public void reportStatus(final ServiceState serviceState, final Throwable throwable) { LOG.debug("reporting status as {} for {}", serviceState, OPENFLOW_SERVICE_NAME); reg.report(new ServiceDescriptor(OPENFLOW_SERVICE_NAME, throwable)); } @Override public void reportStatus(final ServiceState serviceState, final String description) { LOG.debug("reporting status as {} for {}", serviceState, OPENFLOW_SERVICE_NAME); reg.report(new ServiceDescriptor(OPENFLOW_SERVICE_NAME, serviceState, description)); } }