Change transformation from DOMRpcResult to RpcResult
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / FutureSchema.java
index fb70811840e4cbaa935e1523db64e54ea71036ff..5ee1f47a287220e797f8f13c134dbb257d898ba5 100644 (file)
@@ -11,22 +11,22 @@ 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 java.net.URI;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Date;
 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.yangtools.sal.binding.generator.util.BindingRuntimeContext;
+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")
+    @GuardedBy(value = "postponedOperations")
     private final Set<FutureSchemaPredicate> postponedOperations = new LinkedHashSet<>();
     private final long duration;
     private final TimeUnit unit;
@@ -40,39 +40,39 @@ class FutureSchema implements AutoCloseable {
     }
 
     BindingRuntimeContext runtimeContext() {
-        BindingRuntimeContext localRuntimeContext = runtimeContext;
-        if(localRuntimeContext != null) {
+        final BindingRuntimeContext localRuntimeContext = this.runtimeContext;
+        if (localRuntimeContext != null) {
             return localRuntimeContext;
         }
 
-        if(waitForSchema(Collections.emptyList())) {
-            return runtimeContext;
+        if (waitForSchema(Collections.emptyList())) {
+            return this.runtimeContext;
         }
 
         throw new IllegalStateException("No SchemaContext is available");
     }
 
     void onRuntimeContextUpdated(final BindingRuntimeContext context) {
-        synchronized(postponedOperations) {
-            runtimeContext = context;
-            for (final FutureSchemaPredicate op : postponedOperations) {
+        synchronized (this.postponedOperations) {
+            this.runtimeContext = context;
+            for (final FutureSchemaPredicate op : this.postponedOperations) {
                 op.unlockIfPossible(context);
             }
         }
     }
 
     long getDuration() {
-        return duration;
+        return this.duration;
     }
 
     TimeUnit getUnit() {
-        return unit;
+        return this.unit;
     }
 
     @Override
     public void close() {
-        synchronized(postponedOperations) {
-            for (final FutureSchemaPredicate op : postponedOperations) {
+        synchronized (this.postponedOperations) {
+            for (final FutureSchemaPredicate op : this.postponedOperations) {
                 op.cancel();
             }
         }
@@ -88,11 +88,11 @@ class FutureSchema implements AutoCloseable {
         return schema != null;
     }
 
-    boolean waitForSchema(final URI namespace, final Date revision) {
+    boolean waitForSchema(final QNameModule module) {
         return addPostponedOpAndWait(new FutureSchemaPredicate() {
             @Override
-            public boolean apply(final BindingRuntimeContext input) {
-                return input.getSchemaContext().findModuleByNamespaceAndRevision(namespace, revision) != null;
+            public boolean apply(@Nonnull final BindingRuntimeContext input) {
+                return input.getSchemaContext().findModule(module).isPresent();
             }
         });
     }
@@ -111,18 +111,18 @@ class FutureSchema implements AutoCloseable {
         });
     }
 
-    private boolean addPostponedOpAndWait(FutureSchemaPredicate postponedOp) {
-        if(!waitEnabled) {
+    private boolean addPostponedOpAndWait(final FutureSchemaPredicate postponedOp) {
+        if (!this.waitEnabled) {
             return false;
         }
 
-        BindingRuntimeContext localRuntimeContext = runtimeContext;
-        synchronized(postponedOperations) {
-            postponedOperations.add(postponedOp);
+        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 != runtimeContext) {
-                postponedOp.unlockIfPossible(runtimeContext);
+            if (localRuntimeContext != this.runtimeContext) {
+                postponedOp.unlockIfPossible(this.runtimeContext);
             }
         }
 
@@ -133,30 +133,29 @@ class FutureSchema implements AutoCloseable {
 
         final boolean waitForSchema() {
             try {
-                schemaPromise.get(duration, unit);
+                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(postponedOperations) {
-                    postponedOperations.remove(this);
+                synchronized (FutureSchema.this.postponedOperations) {
+                    FutureSchema.this.postponedOperations.remove(this);
                 }
             }
         }
 
         final void unlockIfPossible(final BindingRuntimeContext context) {
-            if (!schemaPromise.isDone() && apply(context)) {
-                schemaPromise.set(null);
+            if (!this.schemaPromise.isDone() && apply(context)) {
+                this.schemaPromise.set(null);
             }
         }
 
         final void cancel() {
-            schemaPromise.cancel(true);
+            this.schemaPromise.cancel(true);
         }
 
         private final SettableFuture<?> schemaPromise = SettableFuture.create();
     }
-
 }