2 * Copyright (c) 2013, 2017 Cisco Systems, Inc. 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.controller.config.manager.impl.dependencyresolver;
10 import org.opendaylight.controller.config.api.ModuleIdentifier;
11 import org.opendaylight.controller.config.manager.impl.jmx.ModuleJMXRegistrator;
12 import org.opendaylight.controller.config.manager.impl.jmx.RootRuntimeBeanRegistratorImpl;
13 import org.opendaylight.controller.config.manager.impl.osgi.BeanToOsgiServiceManager.OsgiRegistration;
14 import org.opendaylight.yangtools.concepts.Identifiable;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * Transfer object representing already committed module that needs to be
20 * destroyed. Implements comparable in order to preserve order in which modules
21 * were created. Module instances should be closed in order defined by the
24 public class DestroyedModule implements AutoCloseable,
25 Comparable<DestroyedModule>, Identifiable<ModuleIdentifier> {
26 private static final Logger LOG = LoggerFactory
27 .getLogger(DestroyedModule.class);
29 private final ModuleIdentifier identifier;
30 private final AutoCloseable instance;
31 private final ModuleJMXRegistrator oldJMXRegistrator;
32 private final OsgiRegistration osgiRegistration;
33 private final int orderingIdx;
34 private final RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator;
36 public DestroyedModule(final ModuleIdentifier identifier, final AutoCloseable instance,
37 final ModuleJMXRegistrator oldJMXRegistrator,
38 final OsgiRegistration osgiRegistration, final int orderingIdx,
39 final RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator) {
40 this.identifier = identifier;
41 this.instance = instance;
42 this.oldJMXRegistrator = oldJMXRegistrator;
43 this.osgiRegistration = osgiRegistration;
44 this.orderingIdx = orderingIdx;
45 this.runtimeBeanRegistrator = runtimeBeanRegistrator;
49 @SuppressWarnings("IllegalCatch")
51 LOG.trace("Destroying {}", identifier);
54 } catch (final Exception e) {
55 LOG.error("Error while closing instance of {}", identifier, e);
58 oldJMXRegistrator.close();
59 } catch (final Exception e) {
60 LOG.error("Error while closing jmx registrator of {}", identifier, e);
63 if (runtimeBeanRegistrator != null) {
64 runtimeBeanRegistrator.close();
66 } catch (final Exception e) {
67 LOG.error("Error while closing runtime bean jmx registrator of {}", identifier, e);
70 osgiRegistration.close();
71 } catch (final Exception e) {
72 LOG.error("Error while closing osgi registration of {}", identifier, e);
77 public int compareTo(final DestroyedModule destroyedModule) {
78 return Integer.compare(orderingIdx, destroyedModule.orderingIdx);
82 public ModuleIdentifier getIdentifier() {