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;
22 public final class SchemaServiceImplSingletonModule extends
23 org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractSchemaServiceImplSingletonModule {
25 private static final Logger LOG = LoggerFactory.getLogger(SchemaServiceImplSingletonModule.class);
27 BundleContext bundleContext;
29 public SchemaServiceImplSingletonModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
30 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
31 super(identifier, dependencyResolver);
34 public SchemaServiceImplSingletonModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
35 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
36 final SchemaServiceImplSingletonModule oldModule, final java.lang.AutoCloseable oldInstance) {
37 super(identifier, dependencyResolver, oldModule, oldInstance);
41 public boolean canReuseInstance(final AbstractSchemaServiceImplSingletonModule oldModule) {
45 public BundleContext getBundleContext() {
49 public void setBundleContext(final BundleContext bundleContext) {
50 this.bundleContext = bundleContext;
54 public void validate() {
59 public java.lang.AutoCloseable createInstance() {
60 ServiceReference<SchemaService> ref = getBundleContext().getServiceReference(SchemaService.class);
62 return new GlobalSchemaServiceProxy(getBundleContext(), ref);
65 GlobalBundleScanningSchemaServiceImpl newInstance = new GlobalBundleScanningSchemaServiceImpl(getBundleContext());
70 public class GlobalSchemaServiceProxy implements AutoCloseable, SchemaService, Delegator<SchemaService> {
72 private BundleContext bundleContext;
73 private ServiceReference<SchemaService> reference;
74 private SchemaService delegate;
76 public GlobalSchemaServiceProxy(final BundleContext bundleContext, final ServiceReference<SchemaService> ref) {
77 this.bundleContext = bundleContext;
79 this.delegate = bundleContext.getService(reference);
83 public void close() throws Exception {
84 if (delegate != null) {
88 bundleContext.ungetService(reference);
89 } catch (IllegalStateException e) {
90 // Indicates the service was already unregistered which can happen normally
92 LOG.debug( "Error unregistering service", e );
101 public void addModule(final Module arg0) {
102 delegate.addModule(arg0);
106 public SchemaContext getGlobalContext() {
107 return delegate.getGlobalContext();
111 public SchemaContext getSessionContext() {
112 return delegate.getSessionContext();
116 public ListenerRegistration<SchemaServiceListener> registerSchemaServiceListener(final SchemaServiceListener arg0) {
117 return delegate.registerSchemaServiceListener(arg0);
121 public void removeModule(final Module arg0) {
122 delegate.removeModule(arg0);
126 public SchemaService getDelegate() {