2 * Copyright (c) 2018 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 package org.opendaylight.genius.interfacemanager.recovery.impl;
10 import javax.inject.Inject;
11 import javax.inject.Singleton;
12 import org.apache.aries.blueprint.annotation.service.Reference;
13 import org.opendaylight.serviceutils.srm.RecoverableListener;
14 import org.opendaylight.serviceutils.srm.ServiceRecoveryInterface;
15 import org.opendaylight.serviceutils.srm.ServiceRecoveryRegistry;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.types.rev180626.GeniusIfm;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
21 public class InterfaceServiceRecoveryHandler implements ServiceRecoveryInterface {
23 private static final Logger LOG = LoggerFactory.getLogger(InterfaceServiceRecoveryHandler.class);
24 private final ServiceRecoveryRegistry serviceRecoveryRegistry;
27 public InterfaceServiceRecoveryHandler(@Reference final ServiceRecoveryRegistry serviceRecoveryRegistry) {
28 LOG.info("registering IFM service recovery handlers");
29 this.serviceRecoveryRegistry = serviceRecoveryRegistry;
30 serviceRecoveryRegistry.registerServiceRecoveryRegistry(buildServiceRegistryKey(), this);
33 private void deregisterListeners() {
34 serviceRecoveryRegistry.getRecoverableListeners(buildServiceRegistryKey())
35 .forEach((RecoverableListener::deregisterListener));
38 private void registerListeners() {
39 serviceRecoveryRegistry.getRecoverableListeners(buildServiceRegistryKey())
40 .forEach((RecoverableListener::registerListener));
44 public void recoverService(final String entityId) {
45 LOG.info("recover IFM service by deregistering and registering all relevant listeners");
46 deregisterListeners();
50 public String buildServiceRegistryKey() {
51 return GeniusIfm.class.toString();