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.yangtools.concepts.Identifiable;
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 AutoCloseable,
24 Comparable<DestroyedModule>, Identifiable<ModuleIdentifier> {
25 private static final Logger logger = LoggerFactory
26 .getLogger(DestroyedModule.class);
28 private final ModuleIdentifier identifier;
29 private final AutoCloseable instance;
30 private final ModuleJMXRegistrator oldJMXRegistrator;
31 private final OsgiRegistration osgiRegistration;
32 private final int orderingIdx;
34 DestroyedModule(ModuleIdentifier identifier, AutoCloseable instance,
35 ModuleJMXRegistrator oldJMXRegistrator,
36 OsgiRegistration osgiRegistration, int orderingIdx) {
37 this.identifier = identifier;
38 this.instance = instance;
39 this.oldJMXRegistrator = oldJMXRegistrator;
40 this.osgiRegistration = osgiRegistration;
41 this.orderingIdx = orderingIdx;
46 logger.info("Destroying {}", identifier);
49 } catch (Exception e) {
50 logger.error("Error while closing instance of {}", identifier, e);
53 oldJMXRegistrator.close();
54 } catch (Exception e) {
55 logger.error("Error while closing jmx registrator of {}", identifier, e);
58 osgiRegistration.close();
59 } catch (Exception e) {
60 logger.error("Error while closing osgi registration of {}", identifier, e);
65 public int compareTo(DestroyedModule o) {
66 return Integer.compare(orderingIdx, o.orderingIdx);
70 public ModuleIdentifier getIdentifier() {