Deprecate md-sal config modules
[controller.git] / opendaylight / md-sal / sal-binding-config / src / main / java / org / opendaylight / controller / config / yang / md / sal / binding / impl / RuntimeMappingModule.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.binding.impl;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.base.Stopwatch;
12 import com.google.common.util.concurrent.Uninterruptibles;
13 import java.util.concurrent.TimeUnit;
14 import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec;
15 import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodecFactory;
16 import org.osgi.framework.BundleContext;
17
18 /**
19  * @deprecated Replaced by blueprint wiring
20  */
21 @Deprecated
22 public final class RuntimeMappingModule extends AbstractRuntimeMappingModule {
23     private static final long WAIT_IN_MINUTES = 5;
24
25     private BundleContext bundleContext;
26
27     public RuntimeMappingModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
28             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
29         super(identifier, dependencyResolver);
30     }
31
32     public RuntimeMappingModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
33             final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
34             final RuntimeMappingModule oldModule, final java.lang.AutoCloseable oldInstance) {
35         super(identifier, dependencyResolver, oldModule, oldInstance);
36     }
37
38     @Override
39     public void validate() {
40         super.validate();
41         Preconditions.checkNotNull(bundleContext);
42         // Add custom validation for module attributes here.
43     }
44
45     @Override
46     public boolean canReuseInstance(final AbstractRuntimeMappingModule oldModule) {
47         return true;
48     }
49
50     @Override
51     public java.lang.AutoCloseable createInstance() {
52         // This is kind of ugly - you might cringe (you've been warned). The BindingToNormalizedNodeCodec
53         // instance is advertised via blueprint so ideally we'd obtain it from the OSGi service registry.
54         // The config yang service identity declares the concrete BindingToNormalizedNodeCodec class
55         // and not an interface as the java-class so we must return a BindingToNormalizedNodeCodec instance.
56         // However we can't cast the instance obtained from the service registry to
57         // BindingToNormalizedNodeCodec b/c Aries may register a proxy if there are interceptors defined.
58         // By default karaf ships with the org.apache.aries.quiesce.api bundle which automatically adds
59         // an interceptor that adds stat tracking for service method calls. While this can be disabled, we
60         // shouldn't rely on it.
61         //
62         // Therefore we store a static instance in the BindingToNormalizedNodeCodecFactory which is created
63         // by blueprint via newInstance. We obtain the static instance here and busy wait if not yet available.
64
65         Stopwatch sw = Stopwatch.createStarted();
66         while(sw.elapsed(TimeUnit.MINUTES) <= WAIT_IN_MINUTES) {
67             BindingToNormalizedNodeCodec instance = BindingToNormalizedNodeCodecFactory.getInstance();
68             if(instance != null) {
69                 return instance;
70             }
71
72             Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
73         }
74
75         throw new IllegalStateException("Could not obtain the BindingToNormalizedNodeCodec instance after " +
76                 WAIT_IN_MINUTES + " minutes.");
77     }
78
79     public void setBundleContext(final BundleContext bundleContext) {
80         this.bundleContext = bundleContext;
81     }
82 }

©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.