2 * Copyright (c) 2013 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 RootRuntimeBeanRegistratorImpl runtimeBeanRegistrator;
36 public DestroyedModule(ModuleIdentifier identifier, AutoCloseable instance,
37 ModuleJMXRegistrator oldJMXRegistrator,
38 OsgiRegistration osgiRegistration, 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;
50 LOG.trace("Destroying {}", identifier);
53 } catch (Exception e) {
54 LOG.error("Error while closing instance of {}", identifier, e);
57 oldJMXRegistrator.close();
58 } catch (Exception e) {
59 LOG.error("Error while closing jmx registrator of {}", identifier, e);
62 if (runtimeBeanRegistrator != null) {
63 runtimeBeanRegistrator.close();
65 } catch (Exception e) {
66 LOG.error("Error while closing runtime bean jmx registrator of {}", identifier, e);
69 osgiRegistration.close();
70 } catch (Exception e) {
71 LOG.error("Error while closing osgi registration of {}", identifier, e);
76 public int compareTo(DestroyedModule o) {
77 return Integer.compare(orderingIdx, o.orderingIdx);
81 public ModuleIdentifier getIdentifier() {