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=f51f57944321ce14887518097de7d3f4d8f2d907;hb=a507f19b518f36065c74f4f88c9327ede28ff640;hp=90720eead6f180b4037356e2723a4f58910723a5;hpb=9883165b61255af5bfcb060b76b16f69a56b1f82;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 90720eead6..f51f579443 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,11 +10,13 @@ package org.opendaylight.controller.cluster.datastore.entityownership; import akka.actor.ActorRef; import akka.dispatch.OnComplete; import akka.util.Timeout; +import com.google.common.annotations.VisibleForTesting; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; import org.opendaylight.controller.cluster.datastore.DistributedDataStore; import org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterCandidateLocal; +import org.opendaylight.controller.cluster.datastore.entityownership.messages.UnregisterCandidateLocal; import org.opendaylight.controller.cluster.datastore.messages.CreateShard; import org.opendaylight.controller.md.sal.common.api.clustering.CandidateAlreadyRegisteredException; import org.opendaylight.controller.md.sal.common.api.clustering.Entity; @@ -106,17 +108,24 @@ public class DistributedEntityOwnershipService implements EntityOwnershipService public EntityOwnershipCandidateRegistration registerCandidate(Entity entity, EntityOwnershipCandidate candidate) throws CandidateAlreadyRegisteredException { - EntityOwnershipCandidate currentCandidate = registeredEntities.putIfAbsent(entity,candidate); + EntityOwnershipCandidate currentCandidate = registeredEntities.putIfAbsent(entity, candidate); if(currentCandidate != null) { throw new CandidateAlreadyRegisteredException(entity, currentCandidate); } RegisterCandidateLocal registerCandidate = new RegisterCandidateLocal(candidate, entity); - LOG.debug("Registering candidate with message: " + registerCandidate); + LOG.debug("Registering candidate with message: {}", registerCandidate); executeLocalEntityOwnershipShardOperation(registerCandidate); - return new DistributedEntityOwnershipCandidateRegistration(candidate, entity); + return new DistributedEntityOwnershipCandidateRegistration(candidate, entity, this); + } + + void unregisterCandidate(Entity entity) { + LOG.debug("Unregistering candidate for {}", entity); + + executeLocalEntityOwnershipShardOperation(new UnregisterCandidateLocal(entity)); + registeredEntities.remove(entity); } @Override @@ -130,6 +139,11 @@ public class DistributedEntityOwnershipService implements EntityOwnershipService } protected EntityOwnershipShardPropsCreator newShardPropsCreator() { - return new EntityOwnershipShardPropsCreator(); + return new EntityOwnershipShardPropsCreator(datastore.getActorContext().getCurrentMemberName()); + } + + @VisibleForTesting + ActorRef getLocalEntityOwnershipShard() { + return localEntityOwnershipShard; } }