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;
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.osgi.BeanToOsgiServiceManager.OsgiRegistration;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
17 * Transfer object representing already committed module that needs to be
18 * destroyed. Implements comparable in order to preserve order in which modules
19 * were created. Module instances should be closed in order defined by the
22 public class DestroyedModule implements AutoCloseable,
23 Comparable<DestroyedModule> {
24 private static final Logger logger = LoggerFactory
25 .getLogger(DestroyedModule.class);
27 private final ModuleIdentifier name;
28 private final AutoCloseable instance;
29 private final ModuleJMXRegistrator oldJMXRegistrator;
30 private final OsgiRegistration osgiRegistration;
31 private final int orderingIdx;
33 DestroyedModule(ModuleIdentifier name, AutoCloseable instance,
34 ModuleJMXRegistrator oldJMXRegistrator,
35 OsgiRegistration osgiRegistration, int orderingIdx) {
37 this.instance = instance;
38 this.oldJMXRegistrator = oldJMXRegistrator;
39 this.osgiRegistration = osgiRegistration;
40 this.orderingIdx = orderingIdx;
43 public ModuleIdentifier getName() {
49 logger.info("Destroying {}", name);
52 } catch (Exception e) {
53 logger.error("Error while closing instance of {}", name, e);
56 oldJMXRegistrator.close();
57 } catch (Exception e) {
58 logger.error("Error while closing jmx registrator of {}", name, e);
61 osgiRegistration.close();
62 } catch (Exception e) {
63 logger.error("Error while closing osgi registration of {}", name, e);
68 public int compareTo(DestroyedModule o) {
69 return Integer.compare(orderingIdx, o.orderingIdx);