Use MD-SAL BindingToNormalizedNodeCodec for most operations 80/72880/6
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 12 Jun 2018 14:47:57 +0000 (16:47 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Thu, 14 Jun 2018 14:48:28 +0000 (10:48 -0400)
This subclasses BindingToNormalizedNodeCodec from MD-SAL, overriding
the operations we need to have overridden. Overall this class is to
be treated as deprecated.

Change-Id: I96f5085ee0e16191855cdc4ca1ed04de6d76f6fb
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/mdsal-trace/binding-impl/src/main/resources/org/opendaylight/blueprint/impl-blueprint.xml
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/BindingToNormalizedNodeCodec.java
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/FutureSchema.java [deleted file]

index 447ea6a..50e0cd0 100644 (file)
@@ -18,7 +18,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
 
   <reference id="classLoadingStrategy" interface="org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy"/>
 
-  <reference id="mappingCodec" interface="org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec" ext:proxy-method="classes" />
+  <odl:static-reference id="mappingCodec" interface="org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec"/>
 
   <bean id="tracingBindingDataBroker" class="org.opendaylight.controller.md.sal.binding.impl.BindingDOMDataBrokerAdapter">
     <argument ref="tracingDefaultDOMBroker"/>
index f179aa6..aa39016 100644 (file)
  */
 package org.opendaylight.controller.md.sal.binding.impl;
 
-import com.google.common.base.Function;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
 import com.google.common.collect.ImmutableBiMap;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.lang.reflect.Method;
-import java.util.AbstractMap.SimpleEntry;
-import java.util.Collection;
-import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
 import javax.annotation.Nonnull;
 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationException;
 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizationOperation;
 import org.opendaylight.controller.md.sal.common.impl.util.compat.DataNormalizer;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeFactory;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode;
-import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
 import org.opendaylight.mdsal.binding.dom.codec.impl.BindingNormalizedNodeCodecRegistry;
-import org.opendaylight.mdsal.binding.dom.codec.impl.MissingSchemaException;
 import org.opendaylight.mdsal.binding.generator.api.ClassLoadingStrategy;
-import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext;
-import org.opendaylight.yangtools.yang.binding.BindingMapping;
-import org.opendaylight.yangtools.yang.binding.DataContainer;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.Notification;
 import org.opendaylight.yangtools.yang.binding.RpcService;
-import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
-import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.codec.DeserializationException;
-import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
+@SuppressFBWarnings(value = "NM_SAME_SIMPLE_NAME_AS_SUPERCLASS", justification = "Migration path")
 public class BindingToNormalizedNodeCodec
-        implements BindingCodecTreeFactory, BindingNormalizedNodeSerializer, SchemaContextListener, AutoCloseable {
+        extends org.opendaylight.mdsal.binding.dom.adapter.BindingToNormalizedNodeCodec {
 
-    private static final long WAIT_DURATION_SEC = 5;
-    private static final Logger LOG = LoggerFactory.getLogger(BindingToNormalizedNodeCodec.class);
-
-    private final BindingNormalizedNodeCodecRegistry codecRegistry;
-
-    private final ClassLoadingStrategy classLoadingStrategy;
-    private final FutureSchema futureSchema;
-    private final LoadingCache<InstanceIdentifier<?>, YangInstanceIdentifier> iiCache = CacheBuilder.newBuilder()
-            .softValues().build(new CacheLoader<InstanceIdentifier<?>, YangInstanceIdentifier>() {
-
-                @Override
-                public YangInstanceIdentifier load(final InstanceIdentifier<?> key) throws Exception {
-                    return toYangInstanceIdentifierBlocking(key);
-                }
-
-            });
-
-    private DataNormalizer legacyToNormalized;
+    private DataNormalizer legacyToNormalized = null;
 
     public BindingToNormalizedNodeCodec(final ClassLoadingStrategy classLoadingStrategy,
             final BindingNormalizedNodeCodecRegistry codecRegistry) {
-        this(classLoadingStrategy, codecRegistry, false);
-
+        super(classLoadingStrategy, codecRegistry);
     }
 
     public BindingToNormalizedNodeCodec(final ClassLoadingStrategy classLoadingStrategy,
             final BindingNormalizedNodeCodecRegistry codecRegistry, final boolean waitForSchema) {
-        this.classLoadingStrategy = Preconditions.checkNotNull(classLoadingStrategy, "classLoadingStrategy");
-        this.codecRegistry = Preconditions.checkNotNull(codecRegistry, "codecRegistry");
-        this.futureSchema = new FutureSchema(WAIT_DURATION_SEC, TimeUnit.SECONDS, waitForSchema);
-    }
-
-    public YangInstanceIdentifier
-            toYangInstanceIdentifierBlocking(final InstanceIdentifier<? extends DataObject> binding) {
-        try {
-            return this.codecRegistry.toYangInstanceIdentifier(binding);
-        } catch (final MissingSchemaException e) {
-            waitForSchema(decompose(binding), e);
-            return this.codecRegistry.toYangInstanceIdentifier(binding);
-        }
-    }
-
-    /**
-     * Translates supplied Binding Instance Identifier into NormalizedNode
-     * instance identifier.
-     *
-     * @param binding
-     *            Binding Instance Identifier
-     * @return DOM Instance Identifier
-     * @throws IllegalArgumentException
-     *             If supplied Instance Identifier is not valid.
-     */
-    public YangInstanceIdentifier toNormalized(final InstanceIdentifier<? extends DataObject> binding) {
-        return this.codecRegistry.toYangInstanceIdentifier(binding);
-    }
-
-    @Override
-    public YangInstanceIdentifier toYangInstanceIdentifier(final InstanceIdentifier<?> binding) {
-        return this.codecRegistry.toYangInstanceIdentifier(binding);
-    }
-
-    public YangInstanceIdentifier toYangInstanceIdentifierCached(final InstanceIdentifier<?> binding) {
-        return this.iiCache.getUnchecked(binding);
-    }
-
-    @Override
-    public <T extends DataObject> Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> toNormalizedNode(
-            final InstanceIdentifier<T> path, final T data) {
-        return this.codecRegistry.toNormalizedNode(path, data);
+        super(classLoadingStrategy, codecRegistry, waitForSchema);
     }
 
-    /**
-     * Converts Binding Map.Entry to DOM Map.Entry
-     *
-     * <p>
-     * Same as {@link #toNormalizedNode(InstanceIdentifier, DataObject)}.
-     *
-     * @param binding Map Entry with InstanceIdentifier as key and DataObject as value.
-     * @return DOM Map Entry with {@link YangInstanceIdentifier} as key and {@link NormalizedNode}
-     *         as value.
-     */
-    @SuppressWarnings({ "unchecked", "rawtypes" })
-    public Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> toNormalizedNode(
-            final Entry<InstanceIdentifier<? extends DataObject>, DataObject> binding) {
-        return toNormalizedNode((InstanceIdentifier) binding.getKey(), binding.getValue());
-    }
-
-    @Override
-    public Entry<InstanceIdentifier<?>, DataObject> fromNormalizedNode(final YangInstanceIdentifier path,
-            final NormalizedNode<?, ?> data) {
-        return this.codecRegistry.fromNormalizedNode(path, data);
-    }
-
-    @Override
-    public Notification fromNormalizedNodeNotification(final SchemaPath path, final ContainerNode data) {
-        return this.codecRegistry.fromNormalizedNodeNotification(path, data);
-    }
-
-    @Override
-    public DataObject fromNormalizedNodeRpcData(final SchemaPath path, final ContainerNode data) {
-        return this.codecRegistry.fromNormalizedNodeRpcData(path, data);
-    }
-
-    @Override
-    public InstanceIdentifier<?> fromYangInstanceIdentifier(final YangInstanceIdentifier dom) {
-        return this.codecRegistry.fromYangInstanceIdentifier(dom);
+    DataNormalizer getDataNormalizer() {
+        return this.legacyToNormalized;
     }
 
     @Override
-    public ContainerNode toNormalizedNodeNotification(final Notification data) {
-        return this.codecRegistry.toNormalizedNodeNotification(data);
+    public YangInstanceIdentifier toYangInstanceIdentifierBlocking(
+            final InstanceIdentifier<? extends DataObject> binding) {
+        return super.toYangInstanceIdentifierBlocking(binding);
     }
 
     @Override
-    public ContainerNode toNormalizedNodeRpcData(final DataContainer data) {
-        return this.codecRegistry.toNormalizedNodeRpcData(data);
-    }
-
-    public DataNormalizer getDataNormalizer() {
-        return this.legacyToNormalized;
-    }
-
-    /**
-     * Returns a Binding-Aware instance identifier from normalized
-     * instance-identifier if it is possible to create representation.
-     *
-     * <p>
-     * Returns Optional.absent for cases where target is mixin node except
-     * augmentation.
-     *
-     */
-    public Optional<InstanceIdentifier<? extends DataObject>> toBinding(final YangInstanceIdentifier normalized)
-            throws DeserializationException {
-        try {
-            return Optional.<InstanceIdentifier<? extends DataObject>>fromNullable(
-                    this.codecRegistry.fromYangInstanceIdentifier(normalized));
-        } catch (final IllegalArgumentException e) {
-            return Optional.absent();
-        }
-    }
-
-    public Optional<Entry<InstanceIdentifier<? extends DataObject>, DataObject>> toBinding(
-            @Nonnull final Entry<YangInstanceIdentifier, ? extends NormalizedNode<?, ?>> normalized)
-            throws DeserializationException {
-        try {
-            /*
-             * This cast is required, due to generics behaviour in openjdk / oracle javac
-             *
-             * InstanceIdentifier has definition InstanceIdentifier<T extends DataObject>,
-             * this means '?' is always  <? extends DataObject>. Eclipse compiler
-             * is able to determine this relationship and treats
-             * Entry<InstanceIdentifier<?>,DataObject> and Entry<InstanceIdentifier<? extends DataObject,DataObject>
-             * as assignable. However openjdk / oracle javac treats this two types
-             * as incompatible and issues a compile error.
-             *
-             * It is safe to  loose generic information and cast it to other generic signature.
-             *
-             */
-            @SuppressWarnings("unchecked")
-            final Entry<InstanceIdentifier<? extends DataObject>, DataObject> binding =
-                    Entry.class.cast(this.codecRegistry.fromNormalizedNode(normalized.getKey(), normalized.getValue()));
-            return Optional.fromNullable(binding);
-        } catch (final IllegalArgumentException e) {
-            return Optional.absent();
-        }
+    public YangInstanceIdentifier toYangInstanceIdentifierCached(final InstanceIdentifier<?> binding) {
+        return super.toYangInstanceIdentifierCached(binding);
     }
 
     @Override
     public void onGlobalContextUpdated(final SchemaContext schemaContext) {
         this.legacyToNormalized = new DataNormalizer(schemaContext);
-        final BindingRuntimeContext runtimeContext =
-                BindingRuntimeContext.create(this.classLoadingStrategy, schemaContext);
-        this.codecRegistry.onBindingRuntimeContextUpdated(runtimeContext);
-        this.futureSchema.onRuntimeContextUpdated(runtimeContext);
-    }
-
-    public <T extends DataObject> Function<Optional<NormalizedNode<?, ?>>, Optional<T>>
-            deserializeFunction(final InstanceIdentifier<T> path) {
-        return this.codecRegistry.deserializeFunction(path);
+        super.onGlobalContextUpdated(schemaContext);
     }
 
     /**
@@ -247,6 +71,7 @@ public class BindingToNormalizedNodeCodec
      * @param path DOM Path
      * @return Node with defaults set on.
      */
+    @Override
     public NormalizedNode<?, ?> getDefaultNodeFor(final YangInstanceIdentifier path) {
         final Iterator<PathArgument> iterator = path.getPathArguments().iterator();
         DataNormalizationOperation<?> currentOp = this.legacyToNormalized.getRootOperation();
@@ -261,129 +86,15 @@ public class BindingToNormalizedNodeCodec
         return currentOp.createDefault(path.getLastPathArgument());
     }
 
-    public BindingNormalizedNodeCodecRegistry getCodecRegistry() {
-        return this.codecRegistry;
-    }
-
     @Override
-    public void close() {
-        // NOOP Intentionally
-    }
-
-    public BindingNormalizedNodeCodecRegistry getCodecFactory() {
-        return this.codecRegistry;
-    }
-
-    // FIXME: This should be probably part of Binding Runtime context
-    public ImmutableBiMap<Method, SchemaPath> getRpcMethodToSchemaPath(final Class<? extends RpcService> key) {
-        final Module module = getModuleBlocking(key);
-        final ImmutableBiMap.Builder<Method, SchemaPath> ret = ImmutableBiMap.<Method, SchemaPath>builder();
-        try {
-            for (final RpcDefinition rpcDef : module.getRpcs()) {
-                final Method method = findRpcMethod(key, rpcDef);
-                ret.put(method, rpcDef.getPath());
-            }
-        } catch (final NoSuchMethodException e) {
-            throw new IllegalStateException("Rpc defined in model does not have representation in generated class.", e);
-        }
-        return ret.build();
-    }
-
     public ImmutableBiMap<Method, RpcDefinition> getRpcMethodToSchema(final Class<? extends RpcService> key) {
-        final Module module = getModuleBlocking(key);
-        final ImmutableBiMap.Builder<Method, RpcDefinition> ret = ImmutableBiMap.builder();
-        try {
-            for (final RpcDefinition rpcDef : module.getRpcs()) {
-                final Method method = findRpcMethod(key, rpcDef);
-                ret.put(method, rpcDef);
-            }
-        } catch (final NoSuchMethodException e) {
-            throw new IllegalStateException("Rpc defined in model does not have representation in generated class.", e);
-        }
-        return ret.build();
-    }
-
-    private Module getModuleBlocking(final Class<?> modeledClass) {
-        final QNameModule moduleName = BindingReflections.getQNameModule(modeledClass);
-        Module module = runtimeContext().getSchemaContext().findModule(moduleName).orElse(null);
-        if (module == null && this.futureSchema.waitForSchema(moduleName)) {
-            module = runtimeContext().getSchemaContext().findModule(moduleName).orElse(null);
-        }
-        Preconditions.checkState(module != null, "Schema for %s is not available.", modeledClass);
-        return module;
-    }
-
-    private void waitForSchema(final Collection<Class<?>> binding, final MissingSchemaException ex) {
-        LOG.warn("Blocking thread to wait for schema convergence updates for {} {}", this.futureSchema.getDuration(),
-                this.futureSchema.getUnit());
-        if (this.futureSchema.waitForSchema(binding)) {
-            return;
-        }
-
-        throw ex;
-    }
-
-    private Method findRpcMethod(final Class<? extends RpcService> key, final RpcDefinition rpcDef)
-            throws NoSuchMethodException {
-        final String methodName = BindingMapping.getMethodName(rpcDef.getQName());
-        if (rpcDef.getInput() != null) {
-            final Class<?> inputClz = runtimeContext().getClassForSchema(rpcDef.getInput());
-            return key.getMethod(methodName, inputClz);
-        }
-        return key.getMethod(methodName);
-    }
-
-    private BindingRuntimeContext runtimeContext() {
-        return this.futureSchema.runtimeContext();
+        return super.getRpcMethodToSchema(key);
     }
 
     @Override
-    public BindingCodecTree create(final BindingRuntimeContext context) {
-        return this.codecRegistry.create(context);
-    }
-
-    @Override
-    public BindingCodecTree create(final SchemaContext context, final Class<?>... bindingClasses) {
-        return this.codecRegistry.create(context, bindingClasses);
-    }
-
     @Nonnull
-    public Map.Entry<InstanceIdentifier<?>, BindingCodecTreeNode<?>>
-            getSubtreeCodec(final YangInstanceIdentifier domIdentifier) {
-
-        final BindingCodecTree currentCodecTree = this.codecRegistry.getCodecContext();
-        final InstanceIdentifier<?> bindingPath = this.codecRegistry.fromYangInstanceIdentifier(domIdentifier);
-        Preconditions.checkArgument(bindingPath != null);
-        /**
-         * If we are able to deserialize YANG instance identifier, getSubtreeCodec must
-         * return non-null value.
-         */
-        final BindingCodecTreeNode<?> codecContext = currentCodecTree.getSubtreeCodec(bindingPath);
-        return new SimpleEntry<>(bindingPath, codecContext);
-    }
-
-    @SuppressWarnings("unchecked")
-    public Set<Class<? extends Notification>> getNotificationClasses(final Set<SchemaPath> interested) {
-        final Set<Class<? extends Notification>> result = new HashSet<>();
-        final Set<NotificationDefinition> knownNotifications = runtimeContext().getSchemaContext().getNotifications();
-        for (final NotificationDefinition notification : knownNotifications) {
-            if (interested.contains(notification.getPath())) {
-                try {
-                    result.add((Class<? extends Notification>) runtimeContext().getClassForSchema(notification));
-                } catch (final IllegalStateException e) {
-                    // Ignore
-                    LOG.warn("Class for {} is currently not known.", notification.getPath(), e);
-                }
-            }
-        }
-        return result;
-    }
-
-    private static Collection<Class<?>> decompose(final InstanceIdentifier<?> path) {
-        final Set<Class<?>> clazzes = new HashSet<>();
-        for (final InstanceIdentifier.PathArgument arg : path.getPathArguments()) {
-            clazzes.add(arg.getType());
-        }
-        return clazzes;
+    public Map.Entry<InstanceIdentifier<?>, BindingCodecTreeNode<?>> getSubtreeCodec(
+            final YangInstanceIdentifier domIdentifier) {
+        return super.getSubtreeCodec(domIdentifier);
     }
 }
diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/FutureSchema.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/FutureSchema.java
deleted file mode 100644 (file)
index 0993a9f..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.controller.md.sal.binding.impl;
-
-import com.google.common.base.Predicate;
-import com.google.common.base.Throwables;
-import com.google.common.util.concurrent.SettableFuture;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedHashSet;
-import java.util.Set;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import javax.annotation.Nonnull;
-import javax.annotation.concurrent.GuardedBy;
-import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext;
-import org.opendaylight.yangtools.yang.binding.Augmentation;
-import org.opendaylight.yangtools.yang.common.QNameModule;
-
-class FutureSchema implements AutoCloseable {
-
-    @GuardedBy(value = "postponedOperations")
-    private final Set<FutureSchemaPredicate> postponedOperations = new LinkedHashSet<>();
-    private final long duration;
-    private final TimeUnit unit;
-    private final boolean waitEnabled;
-    private volatile BindingRuntimeContext runtimeContext;
-
-    protected FutureSchema(final long time, final TimeUnit unit, final boolean waitEnabled) {
-        this.duration = time;
-        this.unit = unit;
-        this.waitEnabled = waitEnabled;
-    }
-
-    BindingRuntimeContext runtimeContext() {
-        final BindingRuntimeContext localRuntimeContext = this.runtimeContext;
-        if (localRuntimeContext != null) {
-            return localRuntimeContext;
-        }
-
-        if (waitForSchema(Collections.emptyList())) {
-            return this.runtimeContext;
-        }
-
-        throw new IllegalStateException("No SchemaContext is available");
-    }
-
-    void onRuntimeContextUpdated(final BindingRuntimeContext context) {
-        synchronized (this.postponedOperations) {
-            this.runtimeContext = context;
-            for (final FutureSchemaPredicate op : this.postponedOperations) {
-                op.unlockIfPossible(context);
-            }
-        }
-    }
-
-    long getDuration() {
-        return this.duration;
-    }
-
-    TimeUnit getUnit() {
-        return this.unit;
-    }
-
-    @Override
-    public void close() {
-        synchronized (this.postponedOperations) {
-            for (final FutureSchemaPredicate op : this.postponedOperations) {
-                op.cancel();
-            }
-        }
-    }
-
-    private static boolean isSchemaAvailable(final Class<?> clz, final BindingRuntimeContext context) {
-        final Object schema;
-        if (Augmentation.class.isAssignableFrom(clz)) {
-            schema = context.getAugmentationDefinition(clz);
-        } else {
-            schema = context.getSchemaDefinition(clz);
-        }
-        return schema != null;
-    }
-
-    boolean waitForSchema(final QNameModule module) {
-        return addPostponedOpAndWait(new FutureSchemaPredicate() {
-            @Override
-            public boolean apply(@Nonnull final BindingRuntimeContext input) {
-                return input.getSchemaContext().findModule(module).isPresent();
-            }
-        });
-    }
-
-    boolean waitForSchema(final Collection<Class<?>> bindingClasses) {
-        return addPostponedOpAndWait(new FutureSchemaPredicate() {
-            @Override
-            public boolean apply(final BindingRuntimeContext context) {
-                for (final Class<?> clz : bindingClasses) {
-                    if (!isSchemaAvailable(clz, context)) {
-                        return false;
-                    }
-                }
-                return true;
-            }
-        });
-    }
-
-    private boolean addPostponedOpAndWait(final FutureSchemaPredicate postponedOp) {
-        if (!this.waitEnabled) {
-            return false;
-        }
-
-        final BindingRuntimeContext localRuntimeContext = this.runtimeContext;
-        synchronized (this.postponedOperations) {
-            this.postponedOperations.add(postponedOp);
-
-            // If the runtimeContext changed, this op may now be satisfied so check it.
-            if (localRuntimeContext != this.runtimeContext) {
-                postponedOp.unlockIfPossible(this.runtimeContext);
-            }
-        }
-
-        return postponedOp.waitForSchema();
-    }
-
-    private abstract class FutureSchemaPredicate implements Predicate<BindingRuntimeContext> {
-
-        final boolean waitForSchema() {
-            try {
-                this.schemaPromise.get(FutureSchema.this.duration, FutureSchema.this.unit);
-                return true;
-            } catch (final InterruptedException | ExecutionException e) {
-                throw Throwables.propagate(e);
-            } catch (final TimeoutException e) {
-                return false;
-            } finally {
-                synchronized (FutureSchema.this.postponedOperations) {
-                    FutureSchema.this.postponedOperations.remove(this);
-                }
-            }
-        }
-
-        @SuppressFBWarnings(value = "NP_NONNULL_PARAM_VIOLATION", justification = "Void is the only allowed value")
-        final void unlockIfPossible(final BindingRuntimeContext context) {
-            if (!this.schemaPromise.isDone() && apply(context)) {
-                this.schemaPromise.set(null);
-            }
-        }
-
-        final void cancel() {
-            this.schemaPromise.cancel(true);
-        }
-
-        private final SettableFuture<?> schemaPromise = SettableFuture.create();
-    }
-}

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