2 * Copyright (c) 2014 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.yang.md.sal.dom.impl;
10 import org.opendaylight.controller.sal.core.api.model.SchemaService;
11 import org.opendaylight.controller.sal.dom.broker.GlobalBundleScanningSchemaServiceImpl;
12 import org.opendaylight.yangtools.concepts.Delegator;
13 import org.opendaylight.yangtools.concepts.ListenerRegistration;
14 import org.opendaylight.yangtools.yang.model.api.Module;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
16 import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener;
17 import org.osgi.framework.BundleContext;
18 import org.osgi.framework.ServiceReference;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
25 public final class SchemaServiceImplSingletonModule extends
26 org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractSchemaServiceImplSingletonModule {
28 private static final Logger LOG = LoggerFactory.getLogger(SchemaServiceImplSingletonModule.class);
30 BundleContext bundleContext;
32 public SchemaServiceImplSingletonModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
33 org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
34 super(identifier, dependencyResolver);
37 public SchemaServiceImplSingletonModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
38 org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
39 SchemaServiceImplSingletonModule oldModule, java.lang.AutoCloseable oldInstance) {
40 super(identifier, dependencyResolver, oldModule, oldInstance);
44 public boolean canReuseInstance(AbstractSchemaServiceImplSingletonModule oldModule) {
48 public BundleContext getBundleContext() {
52 public void setBundleContext(BundleContext bundleContext) {
53 this.bundleContext = bundleContext;
57 public void validate() {
62 public java.lang.AutoCloseable createInstance() {
63 ServiceReference<SchemaService> ref = getBundleContext().getServiceReference(SchemaService.class);
65 return new GlobalSchemaServiceProxy(getBundleContext(), ref);
68 GlobalBundleScanningSchemaServiceImpl newInstance = new GlobalBundleScanningSchemaServiceImpl();
69 newInstance.setContext(getBundleContext());
74 public class GlobalSchemaServiceProxy implements AutoCloseable, SchemaService, Delegator<SchemaService> {
76 private BundleContext bundleContext;
77 private ServiceReference<SchemaService> reference;
78 private SchemaService delegate;
80 public GlobalSchemaServiceProxy(BundleContext bundleContext, ServiceReference<SchemaService> ref) {
81 this.bundleContext = bundleContext;
83 this.delegate = bundleContext.getService(reference);
87 public void close() throws Exception {
88 if (delegate != null) {
92 bundleContext.ungetService(reference);
93 } catch (IllegalStateException e) {
94 // Indicates the service was already unregistered which can happen normally
96 LOG.debug( "Error unregistering service", e );
100 bundleContext = null;
105 public void addModule(Module arg0) {
106 delegate.addModule(arg0);
110 public SchemaContext getGlobalContext() {
111 return delegate.getGlobalContext();
115 public SchemaContext getSessionContext() {
116 return delegate.getSessionContext();
120 public ListenerRegistration<SchemaServiceListener> registerSchemaServiceListener(SchemaServiceListener arg0) {
121 return delegate.registerSchemaServiceListener(arg0);
125 public void removeModule(Module arg0) {
126 delegate.removeModule(arg0);
130 public SchemaService getDelegate() {