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.binding.impl;
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;
19 * @deprecated Replaced by blueprint wiring
22 public final class RuntimeMappingModule extends AbstractRuntimeMappingModule {
23 private static final long WAIT_IN_MINUTES = 5;
25 private BundleContext bundleContext;
27 public RuntimeMappingModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
28 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
29 super(identifier, dependencyResolver);
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);
39 public void validate() {
41 Preconditions.checkNotNull(bundleContext);
42 // Add custom validation for module attributes here.
46 public boolean canReuseInstance(final AbstractRuntimeMappingModule oldModule) {
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.
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.
65 Stopwatch sw = Stopwatch.createStarted();
66 while(sw.elapsed(TimeUnit.MINUTES) <= WAIT_IN_MINUTES) {
67 BindingToNormalizedNodeCodec instance = BindingToNormalizedNodeCodecFactory.getInstance();
68 if(instance != null) {
72 Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
75 throw new IllegalStateException("Could not obtain the BindingToNormalizedNodeCodec instance after " +
76 WAIT_IN_MINUTES + " minutes.");
79 public void setBundleContext(final BundleContext bundleContext) {
80 this.bundleContext = bundleContext;