X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Fimpl%2FFutureSchema.java;h=0993a9fda90956ddc3e3582c91df369e0154206d;hb=refs%2Fchanges%2F76%2F69876%2F11;hp=0c316e809d5e9165b536d51f10046b2d853cee52;hpb=20a32e6459fd1e27e7669bf1ebc7742b96787b94;p=controller.git 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 index 0c316e809d..0993a9fda9 100644 --- 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 @@ -11,6 +11,7 @@ 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; @@ -18,6 +19,7 @@ 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; @@ -25,7 +27,7 @@ import org.opendaylight.yangtools.yang.common.QNameModule; class FutureSchema implements AutoCloseable { - @GuardedBy(value="postponedOperations") + @GuardedBy(value = "postponedOperations") private final Set postponedOperations = new LinkedHashSet<>(); private final long duration; private final TimeUnit unit; @@ -40,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; } @@ -52,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); @@ -70,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(); } @@ -90,7 +92,7 @@ class FutureSchema implements AutoCloseable { boolean waitForSchema(final QNameModule module) { return addPostponedOpAndWait(new FutureSchemaPredicate() { @Override - public boolean apply(final BindingRuntimeContext input) { + public boolean apply(@Nonnull final BindingRuntimeContext input) { return input.getSchemaContext().findModule(module).isPresent(); } }); @@ -111,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); } } @@ -139,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); @@ -157,5 +160,4 @@ class FutureSchema implements AutoCloseable { private final SettableFuture schemaPromise = SettableFuture.create(); } - }