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;
private volatile ActorRef localEntityOwnershipShard;
private volatile DataTree localEntityOwnershipShardDataTree;
- private DistributedEntityOwnershipService(final ActorContext context) {
+ DistributedEntityOwnershipService(final ActorContext context) {
this.context = Preconditions.checkNotNull(context);
}
future.onComplete(new OnComplete<Object>() {
@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());
@VisibleForTesting
void executeLocalEntityOwnershipShardOperation(final Object message) {
- if(localEntityOwnershipShard == null) {
+ if (localEntityOwnershipShard == null) {
Future<ActorRef> future = context.findLocalShardAsync(ENTITY_OWNERSHIP_SHARD_NAME);
future.onComplete(new OnComplete<ActorRef>() {
@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;
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);
}
return Optional.absent();
}
- Optional<NormalizedNode<?, ?>> entityNode = dataTree.takeSnapshot().readNode(
+ java.util.Optional<NormalizedNode<?, ?>> entityNode = dataTree.takeSnapshot().readNode(
entityPath(forEntity.getType(), forEntity.getIdentifier()));
if (!entityNode.isPresent()) {
return Optional.absent();
// 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<DataContainerChild<? extends PathArgument, ?>> optionalCandidates = entity.getChild(CANDIDATE_NODE_ID);
- final boolean hasCandidates = optionalCandidates.isPresent() && ((MapNode) optionalCandidates.get()).getValue().size() > 0;
- if(!hasCandidates){
+ final java.util.Optional<DataContainerChild<? extends PathArgument, ?>> optionalCandidates =
+ entity.getChild(CANDIDATE_NODE_ID);
+ final boolean hasCandidates = optionalCandidates.isPresent()
+ && ((MapNode) optionalCandidates.get()).getValue().size() > 0;
+ if (!hasCandidates) {
return Optional.absent();
}
MemberName localMemberName = context.getCurrentMemberName();
- Optional<DataContainerChild<? extends PathArgument, ?>> ownerLeaf = entity.getChild(ENTITY_OWNER_NODE_ID);
+ java.util.Optional<DataContainerChild<? extends PathArgument, ?>> ownerLeaf = entity.getChild(
+ ENTITY_OWNER_NODE_ID);
String owner = ownerLeaf.isPresent() ? ownerLeaf.get().getValue().toString() : null;
boolean hasOwner = !Strings.isNullOrEmpty(owner);
boolean isOwner = hasOwner && localMemberName.getName().equals(owner);
}
@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());
}