X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Fentityownership%2FDistributedEntityOwnershipService.java;h=49dc21b81f77a6e902d1706b27f871208f3c6da3;hb=0ea559733fca586d0927e434a205c220c8566c8e;hp=48c68e7a6bbef170aef9c940b1f186127640f440;hpb=6b31b94c7c06711efd69f7fd456167026f34dc2e;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipService.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipService.java index 48c68e7a6b..49dc21b81f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipService.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/DistributedEntityOwnershipService.java @@ -10,15 +10,16 @@ package org.opendaylight.controller.cluster.datastore.entityownership; import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.CANDIDATE_NODE_ID; import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.ENTITY_OWNER_NODE_ID; import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.entityPath; + import akka.actor.ActorRef; import akka.dispatch.OnComplete; import akka.pattern.Patterns; import akka.util.Timeout; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import java.util.Collection; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; @@ -73,7 +74,7 @@ public class DistributedEntityOwnershipService implements DOMEntityOwnershipServ private volatile ActorRef localEntityOwnershipShard; private volatile DataTree localEntityOwnershipShardDataTree; - private DistributedEntityOwnershipService(final ActorContext context) { + DistributedEntityOwnershipService(final ActorContext context) { this.context = Preconditions.checkNotNull(context); } @@ -109,10 +110,10 @@ public class DistributedEntityOwnershipService implements DOMEntityOwnershipServ future.onComplete(new OnComplete() { @Override public void onComplete(final Throwable failure, final Object response) { - if(failure != null) { + if (failure != null) { LOG.debug("Error sending message {} to {}", message, shardActor, failure); } else { - LOG.debug("{} message to {} succeeded", message, shardActor, failure); + LOG.debug("{} message to {} succeeded", message, shardActor); } } }, context.getClientDispatcher()); @@ -120,12 +121,12 @@ public class DistributedEntityOwnershipService implements DOMEntityOwnershipServ @VisibleForTesting void executeLocalEntityOwnershipShardOperation(final Object message) { - if(localEntityOwnershipShard == null) { + if (localEntityOwnershipShard == null) { Future future = context.findLocalShardAsync(ENTITY_OWNERSHIP_SHARD_NAME); future.onComplete(new OnComplete() { @Override public void onComplete(final Throwable failure, final ActorRef shardActor) { - if(failure != null) { + if (failure != null) { LOG.error("Failed to find local {} shard", ENTITY_OWNERSHIP_SHARD_NAME, failure); } else { localEntityOwnershipShard = shardActor; @@ -144,7 +145,7 @@ public class DistributedEntityOwnershipService implements DOMEntityOwnershipServ throws CandidateAlreadyRegisteredException { Preconditions.checkNotNull(entity, "entity cannot be null"); - if(registeredEntities.putIfAbsent(entity, entity) != null) { + if (registeredEntities.putIfAbsent(entity, entity) != null) { throw new CandidateAlreadyRegisteredException(entity); } @@ -166,9 +167,6 @@ public class DistributedEntityOwnershipService implements DOMEntityOwnershipServ @Override public DOMEntityOwnershipListenerRegistration registerListener(final String entityType, final DOMEntityOwnershipListener listener) { - Preconditions.checkNotNull(entityType, "entityType cannot be null"); - Preconditions.checkNotNull(listener, "listener cannot be null"); - RegisterListenerLocal registerListener = new RegisterListenerLocal(listener, entityType); LOG.debug("Registering listener with message: {}", registerListener); @@ -183,21 +181,23 @@ public class DistributedEntityOwnershipService implements DOMEntityOwnershipServ DataTree dataTree = getLocalEntityOwnershipShardDataTree(); if (dataTree == null) { - return Optional.absent(); + return Optional.empty(); } Optional> entityNode = dataTree.takeSnapshot().readNode( entityPath(forEntity.getType(), forEntity.getIdentifier())); if (!entityNode.isPresent()) { - return Optional.absent(); + return Optional.empty(); } // Check if there are any candidates, if there are none we do not really have ownership state final MapEntryNode entity = (MapEntryNode) entityNode.get(); - final Optional> optionalCandidates = entity.getChild(CANDIDATE_NODE_ID); - final boolean hasCandidates = optionalCandidates.isPresent() && ((MapNode) optionalCandidates.get()).getValue().size() > 0; - if(!hasCandidates){ - return Optional.absent(); + final Optional> optionalCandidates = + entity.getChild(CANDIDATE_NODE_ID); + final boolean hasCandidates = optionalCandidates.isPresent() + && ((MapNode) optionalCandidates.get()).getValue().size() > 0; + if (!hasCandidates) { + return Optional.empty(); } MemberName localMemberName = context.getCurrentMemberName(); @@ -215,10 +215,11 @@ public class DistributedEntityOwnershipService implements DOMEntityOwnershipServ } @VisibleForTesting + @SuppressWarnings("checkstyle:IllegalCatch") DataTree getLocalEntityOwnershipShardDataTree() { if (localEntityOwnershipShardDataTree == null) { try { - if(localEntityOwnershipShard == null) { + if (localEntityOwnershipShard == null) { localEntityOwnershipShard = Await.result(context.findLocalShardAsync( ENTITY_OWNERSHIP_SHARD_NAME), Duration.Inf()); }