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

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.