X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fmd%2Fsal%2Fdom%2Fimpl%2FSchemaServiceImplSingletonModule.java;h=fd24944018c69b3b9480a7018e0fea1c23986719;hp=6b597dea9e5c1bc691acd78e2737db391c842f07;hb=4f84c7cdc09512490d743620eff479b9c69170f2;hpb=4bf903ba60c5bb2b5cdde1c7282e9a93e27e49c8 diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/SchemaServiceImplSingletonModule.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/SchemaServiceImplSingletonModule.java index 6b597dea9e..fd24944018 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/SchemaServiceImplSingletonModule.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/SchemaServiceImplSingletonModule.java @@ -1,36 +1,44 @@ -/** -* Generated file - -* Generated from: yang module name: opendaylight-sal-dom-broker-impl yang module local name: schema-service-singleton -* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator -* Generated at: Wed Nov 20 17:01:31 CET 2013 -* -* Do not modify this file unless it is present under src/main directory -*/ +/* + * Copyright (c) 2014 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.yang.md.sal.dom.impl; -import org.opendaylight.controller.sal.dom.broker.SchemaServiceImpl; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; +import org.opendaylight.controller.sal.core.api.model.SchemaService; +import org.opendaylight.controller.sal.dom.broker.GlobalBundleScanningSchemaServiceImpl; +import org.opendaylight.yangtools.concepts.Delegator; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener; import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -/** -* -*/ -public final class SchemaServiceImplSingletonModule extends org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractSchemaServiceImplSingletonModule -{ +public final class SchemaServiceImplSingletonModule extends +org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractSchemaServiceImplSingletonModule { + + private static final Logger LOG = LoggerFactory.getLogger(SchemaServiceImplSingletonModule.class); BundleContext bundleContext; - - public SchemaServiceImplSingletonModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { + + public SchemaServiceImplSingletonModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, + final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { super(identifier, dependencyResolver); } - public SchemaServiceImplSingletonModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, SchemaServiceImplSingletonModule oldModule, java.lang.AutoCloseable oldInstance) { + public SchemaServiceImplSingletonModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, + final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, + final SchemaServiceImplSingletonModule oldModule, final java.lang.AutoCloseable oldInstance) { super(identifier, dependencyResolver, oldModule, oldInstance); } - + @Override - public boolean canReuseInstance(AbstractSchemaServiceImplSingletonModule oldModule) { + public boolean canReuseInstance(final AbstractSchemaServiceImplSingletonModule oldModule) { return true; } @@ -38,21 +46,86 @@ public final class SchemaServiceImplSingletonModule extends org.opendaylight.con return bundleContext; } - public void setBundleContext(BundleContext bundleContext) { + public void setBundleContext(final BundleContext bundleContext) { this.bundleContext = bundleContext; } @Override - public void validate(){ + public void validate() { super.validate(); } @Override public java.lang.AutoCloseable createInstance() { - SchemaServiceImpl newInstance = new SchemaServiceImpl(); - newInstance.setContext(getBundleContext()); - newInstance.setParser(new YangParserImpl()); + ServiceReference ref = getBundleContext().getServiceReference(SchemaService.class); + if (ref != null) { + return new GlobalSchemaServiceProxy(getBundleContext(), ref); + } + + GlobalBundleScanningSchemaServiceImpl newInstance = new GlobalBundleScanningSchemaServiceImpl(getBundleContext()); newInstance.start(); return newInstance; } + + public class GlobalSchemaServiceProxy implements AutoCloseable, SchemaService, Delegator { + + private BundleContext bundleContext; + private ServiceReference reference; + private SchemaService delegate; + + public GlobalSchemaServiceProxy(final BundleContext bundleContext, final ServiceReference ref) { + this.bundleContext = bundleContext; + this.reference = ref; + this.delegate = bundleContext.getService(reference); + } + + @Override + public void close() throws Exception { + if (delegate != null) { + delegate = null; + + try { + bundleContext.ungetService(reference); + } catch (IllegalStateException e) { + // Indicates the service was already unregistered which can happen normally + // on shutdown. + LOG.debug( "Error unregistering service", e ); + } + + reference = null; + bundleContext = null; + } + } + + @Override + public void addModule(final Module arg0) { + delegate.addModule(arg0); + } + + @Override + public SchemaContext getGlobalContext() { + return delegate.getGlobalContext(); + } + + @Override + public SchemaContext getSessionContext() { + return delegate.getSessionContext(); + } + + @Override + public ListenerRegistration registerSchemaServiceListener(final SchemaServiceListener arg0) { + return delegate.registerSchemaServiceListener(arg0); + } + + @Override + public void removeModule(final Module arg0) { + delegate.removeModule(arg0); + } + + @Override + public SchemaService getDelegate() { + return delegate; + } + + } }