+ final String currentOwner = getCurrentOwner(message.getEntityPath());
+ final EntityOwnerSelectionStrategy strategy = getEntityOwnerElectionStrategy(message.getEntityPath());
+ final String entityType = EntityOwnersModel.entityTypeFromEntityPath(message.getEntityPath());
+
+ // Available members is all the known peers - the number of peers that are down + self
+ // So if there are 2 peers and 1 is down then availableMembers will be 2
+ final int availableMembers = (peerIdToMemberNames.size() - downPeerMemberNames.size()) + 1;
+
+ LOG.debug("{}: Using strategy {} to select owner, currentOwner = {}", persistenceId(), strategy, currentOwner);
+
+ if(!message.getAllCandidates().contains(currentOwner)){
+ if(strategy.getSelectionDelayInMillis() == 0L) {
+ writeNewOwner(message.getEntityPath(), newOwner(currentOwner, message.getAllCandidates(),
+ entityOwnershipStatistics.byEntityType(entityType), strategy));
+ } else if(message.getAllCandidates().size() == availableMembers) {
+ LOG.debug("{}: Received the maximum candidates requests : {} writing new owner",
+ persistenceId(), availableMembers);
+ cancelOwnerSelectionTask(message.getEntityPath());
+ writeNewOwner(message.getEntityPath(), newOwner(currentOwner, message.getAllCandidates(),
+ entityOwnershipStatistics.byEntityType(entityType), strategy));
+ } else {
+ scheduleOwnerSelection(message.getEntityPath(), message.getAllCandidates(), strategy);
+ }