X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fdependencyresolver%2FDestroyedModule.java;fp=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fdependencyresolver%2FDestroyedModule.java;h=2aa74758d47c6fd2c7cc6b1fa095695ea8e91ded;hb=4f27eb271720e9d7eaa2f720672a2e76de82c40e;hp=0000000000000000000000000000000000000000;hpb=808313e2a87d8dd037a0566574d0acc34687149c;p=controller.git diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DestroyedModule.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DestroyedModule.java new file mode 100644 index 0000000000..2aa74758d4 --- /dev/null +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/dependencyresolver/DestroyedModule.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.config.manager.impl.dependencyresolver; + +import org.opendaylight.controller.config.api.ModuleIdentifier; +import org.opendaylight.controller.config.manager.impl.jmx.ModuleJMXRegistrator; +import org.opendaylight.controller.config.manager.impl.osgi.BeanToOsgiServiceManager.OsgiRegistration; +import org.opendaylight.yangtools.concepts.Identifiable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Transfer object representing already committed module that needs to be + * destroyed. Implements comparable in order to preserve order in which modules + * were created. Module instances should be closed in order defined by the + * compareTo method. + */ +public class DestroyedModule implements AutoCloseable, + Comparable, Identifiable { + private static final Logger logger = LoggerFactory + .getLogger(DestroyedModule.class); + + private final ModuleIdentifier identifier; + private final AutoCloseable instance; + private final ModuleJMXRegistrator oldJMXRegistrator; + private final OsgiRegistration osgiRegistration; + private final int orderingIdx; + + public DestroyedModule(ModuleIdentifier identifier, AutoCloseable instance, + ModuleJMXRegistrator oldJMXRegistrator, + OsgiRegistration osgiRegistration, int orderingIdx) { + this.identifier = identifier; + this.instance = instance; + this.oldJMXRegistrator = oldJMXRegistrator; + this.osgiRegistration = osgiRegistration; + this.orderingIdx = orderingIdx; + } + + @Override + public void close() { + logger.trace("Destroying {}", identifier); + try { + instance.close(); + } catch (Exception e) { + logger.error("Error while closing instance of {}", identifier, e); + } + try { + oldJMXRegistrator.close(); + } catch (Exception e) { + logger.error("Error while closing jmx registrator of {}", identifier, e); + } + try { + osgiRegistration.close(); + } catch (Exception e) { + logger.error("Error while closing osgi registration of {}", identifier, e); + } + } + + @Override + public int compareTo(DestroyedModule o) { + return Integer.compare(orderingIdx, o.orderingIdx); + } + + @Override + public ModuleIdentifier getIdentifier() { + return identifier; + } +}