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.opendaylight.protocol.concepts.NamedObject;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
18 * Transfer object representing already committed module that needs to be
19 * destroyed. Implements comparable in order to preserve order in which modules
20 * were created. Module instances should be closed in order defined by the
23 public class DestroyedModule implements NamedObject<ModuleIdentifier>,
24 AutoCloseable, Comparable<DestroyedModule> {
25 private static final Logger logger = LoggerFactory
26 .getLogger(DestroyedModule.class);
28 private final ModuleIdentifier name;
29 private final AutoCloseable instance;
30 private final ModuleJMXRegistrator oldJMXRegistrator;
31 private final OsgiRegistration osgiRegistration;
32 private final int orderingIdx;
34 DestroyedModule(ModuleIdentifier name, AutoCloseable instance,
35 ModuleJMXRegistrator oldJMXRegistrator,
36 OsgiRegistration osgiRegistration, int orderingIdx) {
38 this.instance = instance;
39 this.oldJMXRegistrator = oldJMXRegistrator;
40 this.osgiRegistration = osgiRegistration;
41 this.orderingIdx = orderingIdx;
45 public ModuleIdentifier getName() {
51 logger.info("Destroying {}", name);
54 } catch (Exception e) {
55 logger.error("Error while closing instance of {}", name, e);
58 oldJMXRegistrator.close();
59 } catch (Exception e) {
60 logger.error("Error while closing jmx registrator of {}", name, e);
63 osgiRegistration.close();
64 } catch (Exception e) {
65 logger.error("Error while closing osgi registration of {}", name, e);
70 public int compareTo(DestroyedModule o) {
71 return Integer.compare(orderingIdx, o.orderingIdx);