Move GlobalBundleScanningSchemaServiceImpl to its own bundle
[controller.git] / opendaylight / md-sal / sal-dom-broker-config / src / main / java / org / opendaylight / controller / config / yang / md / sal / dom / impl / SchemaServiceImplSingletonModule.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.config.yang.md.sal.dom.impl;
9
10 import com.google.common.util.concurrent.CheckedFuture;
11 import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
12 import org.opendaylight.controller.sal.core.api.model.SchemaService;
13 import org.opendaylight.controller.sal.core.api.model.YangTextSourceProvider;
14 import org.opendaylight.yangtools.concepts.ListenerRegistration;
15 import org.opendaylight.yangtools.yang.model.api.Module;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
18 import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
19 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
20 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
21 import org.osgi.framework.BundleContext;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25 /**
26  * @deprecated Replaced by blueprint wiring
27  */
28 @Deprecated
29 public final class SchemaServiceImplSingletonModule extends
30 org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractSchemaServiceImplSingletonModule {
31
32     private static final Logger LOG = LoggerFactory.getLogger(SchemaServiceImplSingletonModule.class);
33
34     BundleContext bundleContext;
35
36     public SchemaServiceImplSingletonModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
37             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
38         super(identifier, dependencyResolver);
39     }
40
41     public SchemaServiceImplSingletonModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
42             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
43             final SchemaServiceImplSingletonModule oldModule, final java.lang.AutoCloseable oldInstance) {
44         super(identifier, dependencyResolver, oldModule, oldInstance);
45     }
46
47     @Override
48     public boolean canReuseInstance(final AbstractSchemaServiceImplSingletonModule oldModule) {
49         return true;
50     }
51
52     public BundleContext getBundleContext() {
53         return bundleContext;
54     }
55
56     public void setBundleContext(final BundleContext bundleContext) {
57         this.bundleContext = bundleContext;
58     }
59
60     @Override
61     public void validate() {
62         super.validate();
63     }
64
65     @Override
66     public AutoCloseable createInstance() {
67         final WaitingServiceTracker<SchemaService> schemaServiceTracker =
68                 WaitingServiceTracker.create(SchemaService.class, bundleContext);
69         final SchemaService schemaService = schemaServiceTracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
70
71         final WaitingServiceTracker<YangTextSourceProvider> sourceProviderTracker =
72                 WaitingServiceTracker.create(YangTextSourceProvider.class, bundleContext);
73         final YangTextSourceProvider sourceProvider = sourceProviderTracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
74
75         class GlobalSchemaServiceProxy implements AutoCloseable, SchemaService, YangTextSourceProvider {
76             @Override
77             public void close() {
78                 schemaServiceTracker.close();
79                 sourceProviderTracker.close();
80             }
81
82             @Override
83             public void addModule(final Module arg0) {
84                 schemaService.addModule(arg0);
85             }
86
87             @Override
88             public SchemaContext getGlobalContext() {
89                 return schemaService.getGlobalContext();
90             }
91
92             @Override
93             public SchemaContext getSessionContext() {
94                 return schemaService.getSessionContext();
95             }
96
97             @Override
98             public ListenerRegistration<SchemaContextListener> registerSchemaContextListener(final SchemaContextListener arg0) {
99                 return schemaService.registerSchemaContextListener(arg0);
100             }
101
102             @Override
103             public void removeModule(final Module arg0) {
104                 schemaService.removeModule(arg0);
105             }
106
107             @Override
108             public CheckedFuture<? extends YangTextSchemaSource, SchemaSourceException> getSource(
109                     SourceIdentifier sourceIdentifier) {
110                 return sourceProvider.getSource(sourceIdentifier);
111             }
112         }
113
114         return new GlobalSchemaServiceProxy();
115     }
116 }