Rework BindingRuntimeTypes
[mdsal.git] / singleton-service / mdsal-singleton-dom-impl / src / main / java / org / opendaylight / mdsal / singleton / dom / impl / ClusterSingletonServiceGroupImpl.java
index b91bb0d9b627c3e12852395ac499acc1f4e04d26..2fae806534da672d4c6ec555ddf6353175c8c835 100644 (file)
@@ -22,6 +22,7 @@ import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 import com.google.common.util.concurrent.SettableFuture;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -31,8 +32,8 @@ import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
 import java.util.concurrent.atomic.AtomicReference;
-import javax.annotation.concurrent.GuardedBy;
-import javax.annotation.concurrent.ThreadSafe;
+import org.checkerframework.checker.lock.qual.GuardedBy;
+import org.checkerframework.checker.lock.qual.Holding;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.eos.common.api.CandidateAlreadyRegisteredException;
 import org.opendaylight.mdsal.eos.common.api.EntityOwnershipChangeState;
@@ -43,7 +44,7 @@ import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipListener;
 import org.opendaylight.mdsal.eos.common.api.GenericEntityOwnershipService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonService;
 import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceRegistration;
-import org.opendaylight.yangtools.concepts.Path;
+import org.opendaylight.yangtools.concepts.HierarchicalIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -69,8 +70,7 @@ import org.slf4j.LoggerFactory;
  * @param <G> the GenericEntityOwnershipListener type
  * @param <S> the GenericEntityOwnershipService type
  */
-@ThreadSafe
-final class ClusterSingletonServiceGroupImpl<P extends Path<P>, E extends GenericEntity<P>,
+final class ClusterSingletonServiceGroupImpl<P extends HierarchicalIdentifier<P>, E extends GenericEntity<P>,
         C extends GenericEntityOwnershipChange<P, E>,  G extends GenericEntityOwnershipListener<P, C>,
         S extends GenericEntityOwnershipService<P, E, G>> extends ClusterSingletonServiceGroup<P, E, C> {
 
@@ -260,8 +260,7 @@ final class ClusterSingletonServiceGroupImpl<P extends Path<P>, E extends Generi
 
     @Override
     void registerService(final ClusterSingletonServiceRegistration reg) {
-        final ClusterSingletonService service = reg.getInstance();
-        verify(identifier.equals(service.getIdentifier().getValue()));
+        final ClusterSingletonService service = verifyRegistration(reg);
         checkNotClosed();
 
         checkState(initialized, "Service group %s is not initialized yet", identifier);
@@ -281,8 +280,7 @@ final class ClusterSingletonServiceGroupImpl<P extends Path<P>, E extends Generi
 
     @Override
     ListenableFuture<?> unregisterService(final ClusterSingletonServiceRegistration reg) {
-        final ClusterSingletonService service = reg.getInstance();
-        verify(identifier.equals(service.getIdentifier().getValue()));
+        verifyRegistration(reg);
         checkNotClosed();
 
         verify(members.remove(reg));
@@ -303,6 +301,12 @@ final class ClusterSingletonServiceGroupImpl<P extends Path<P>, E extends Generi
         return null;
     }
 
+    private ClusterSingletonService verifyRegistration(final ClusterSingletonServiceRegistration reg) {
+        final ClusterSingletonService service = reg.getInstance();
+        verify(identifier.equals(service.getIdentifier().getName()));
+        return service;
+    }
+
     private synchronized @NonNull ListenableFuture<?> destroyGroup() {
         final SettableFuture<Void> future = SettableFuture.create();
         if (!closeFuture.compareAndSet(null, future)) {
@@ -330,7 +334,7 @@ final class ClusterSingletonServiceGroupImpl<P extends Path<P>, E extends Generi
 
         if (isDirty()) {
             if (!tryLock()) {
-                LOG.debug("Service group {} postponing ownership change sync");
+                LOG.debug("Service group {} postponing ownership change sync", identifier);
                 return;
             }
 
@@ -344,7 +348,7 @@ final class ClusterSingletonServiceGroupImpl<P extends Path<P>, E extends Generi
      *
      * @param ownershipChange reported change
      */
-    @GuardedBy("this")
+    @Holding("this")
     private void lockedOwnershipChanged(final C ownershipChange) {
         final E entity = ownershipChange.getEntity();
         if (serviceEntity.equals(entity)) {
@@ -358,7 +362,7 @@ final class ClusterSingletonServiceGroupImpl<P extends Path<P>, E extends Generi
         }
     }
 
-    @GuardedBy("this")
+    @Holding("this")
     private void cleanupCandidateOwnershipChanged(final EntityOwnershipChangeState state, final boolean jeopardy) {
         if (jeopardy) {
             switch (state) {
@@ -403,7 +407,7 @@ final class ClusterSingletonServiceGroupImpl<P extends Path<P>, E extends Generi
         }
     }
 
-    @GuardedBy("this")
+    @Holding("this")
     private void serviceOwnershipChanged(final EntityOwnershipChangeState state, final boolean jeopardy) {
         if (jeopardy) {
             LOG.info("Service group {} service entity ownership uncertain", identifier);
@@ -487,6 +491,8 @@ final class ClusterSingletonServiceGroupImpl<P extends Path<P>, E extends Generi
         }
     }
 
+    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private void serviceTransitionCompleted() {
         markDirty();
         if (tryLock()) {