Bump to odlparent 3.1.0 and yangtools 2.0.3
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / main / java / org / opendaylight / controller / md / sal / binding / impl / FutureSchema.java
index e2fa7d1daf8319d9b3df9c18c174b7dac752d035..0993a9fda90956ddc3e3582c91df369e0154206d 100644 (file)
@@ -11,22 +11,23 @@ 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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 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.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;
@@ -41,11 +42,11 @@ class FutureSchema implements AutoCloseable {
 
     BindingRuntimeContext runtimeContext() {
         final BindingRuntimeContext localRuntimeContext = this.runtimeContext;
-        if(localRuntimeContext != null) {
+        if (localRuntimeContext != null) {
             return localRuntimeContext;
         }
 
-        if(waitForSchema(Collections.emptyList())) {
+        if (waitForSchema(Collections.emptyList())) {
             return this.runtimeContext;
         }
 
@@ -53,7 +54,7 @@ class FutureSchema implements AutoCloseable {
     }
 
     void onRuntimeContextUpdated(final BindingRuntimeContext context) {
-        synchronized(this.postponedOperations) {
+        synchronized (this.postponedOperations) {
             this.runtimeContext = context;
             for (final FutureSchemaPredicate op : this.postponedOperations) {
                 op.unlockIfPossible(context);
@@ -71,7 +72,7 @@ class FutureSchema implements AutoCloseable {
 
     @Override
     public void close() {
-        synchronized(this.postponedOperations) {
+        synchronized (this.postponedOperations) {
             for (final FutureSchemaPredicate op : this.postponedOperations) {
                 op.cancel();
             }
@@ -88,11 +89,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();
             }
         });
     }
@@ -112,16 +113,16 @@ class FutureSchema implements AutoCloseable {
     }
 
     private boolean addPostponedOpAndWait(final FutureSchemaPredicate postponedOp) {
-        if(!this.waitEnabled) {
+        if (!this.waitEnabled) {
             return false;
         }
 
         final BindingRuntimeContext localRuntimeContext = this.runtimeContext;
-        synchronized(this.postponedOperations) {
+        synchronized (this.postponedOperations) {
             this.postponedOperations.add(postponedOp);
 
             // If the runtimeContext changed, this op may now be satisfied so check it.
-            if(localRuntimeContext != this.runtimeContext) {
+            if (localRuntimeContext != this.runtimeContext) {
                 postponedOp.unlockIfPossible(this.runtimeContext);
             }
         }
@@ -140,12 +141,13 @@ class FutureSchema implements AutoCloseable {
             } catch (final TimeoutException e) {
                 return false;
             } finally {
-                synchronized(FutureSchema.this.postponedOperations) {
+                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);
@@ -158,5 +160,4 @@ class FutureSchema implements AutoCloseable {
 
         private final SettableFuture<?> schemaPromise = SettableFuture.create();
     }
-
 }