private void onSelectOwner(SelectOwner selectOwner) {
String currentOwner = getCurrentOwner(selectOwner.getEntityPath());
if(Strings.isNullOrEmpty(currentOwner)) {
+ String entityType = EntityOwnersModel.entityTypeFromEntityPath(selectOwner.getEntityPath());
writeNewOwner(selectOwner.getEntityPath(), newOwner(selectOwner.getAllCandidates(),
+ entityOwnershipStatistics.byEntityType(entityType),
selectOwner.getOwnerSelectionStrategy()));
Cancellable cancellable = entityToScheduledOwnershipTask.get(selectOwner.getEntityPath());
if(isLeader()) {
String currentOwner = getCurrentOwner(message.getEntityPath());
if(message.getRemovedCandidate().equals(currentOwner)){
+ String entityType = EntityOwnersModel.entityTypeFromEntityPath(message.getEntityPath());
writeNewOwner(message.getEntityPath(),
- newOwner(message.getRemainingCandidates(), getEntityOwnerElectionStrategy(message.getEntityPath())));
+ newOwner(message.getRemainingCandidates(), entityOwnershipStatistics.byEntityType(entityType),
+ getEntityOwnerElectionStrategy(message.getEntityPath())));
}
} else {
// We're not the leader. If the removed candidate is our local member then check if we actually
EntityOwnerSelectionStrategy strategy = getEntityOwnerElectionStrategy(message.getEntityPath());
if(Strings.isNullOrEmpty(currentOwner)){
if(strategy.getSelectionDelayInMillis() == 0L) {
- writeNewOwner(message.getEntityPath(), newOwner(message.getAllCandidates(), strategy));
+ String entityType = EntityOwnersModel.entityTypeFromEntityPath(message.getEntityPath());
+ writeNewOwner(message.getEntityPath(), newOwner(message.getAllCandidates(),
+ entityOwnershipStatistics.byEntityType(entityType), strategy));
} else {
scheduleOwnerSelection(message.getEntityPath(), message.getAllCandidates(), strategy);
}
node(entityTypeNode.getIdentifier()).node(ENTITY_NODE_ID).node(entityNode.getIdentifier()).
node(ENTITY_OWNER_NODE_ID).build();
- Object newOwner = newOwner(getCandidateNames(entityNode), getEntityOwnerElectionStrategy(entityPath));
+ String entityType = EntityOwnersModel.entityTypeFromEntityPath(entityPath);
+
+ Object newOwner = newOwner(getCandidateNames(entityNode),
+ entityOwnershipStatistics.byEntityType(entityType),
+ getEntityOwnerElectionStrategy(entityPath));
LOG.debug("{}: Found entity {}, writing new owner {}", persistenceId(), entityPath, newOwner);
entityToScheduledOwnershipTask.put(entityPath, lastScheduledTask);
}
- private String newOwner(Collection<String> candidates, EntityOwnerSelectionStrategy ownerSelectionStrategy) {
+ private String newOwner(Collection<String> candidates, Map<String, Long> statistics, EntityOwnerSelectionStrategy ownerSelectionStrategy) {
Collection<String> viableCandidates = getViableCandidates(candidates);
if(viableCandidates.size() == 0){
return "";
}
- return ownerSelectionStrategy.newOwner(viableCandidates);
+ return ownerSelectionStrategy.newOwner(viableCandidates, statistics);
}
private Collection<String> getViableCandidates(Collection<String> candidates) {