- private void selectNewOwnerForEntitiesOwnedBy(String owner) {
- final BatchedModifications modifications = commitCoordinator.newBatchedModifications();
- searchForEntitiesOwnedBy(owner, new EntityWalker() {
- @Override
- public void onEntity(MapEntryNode entityTypeNode, MapEntryNode entityNode) {
-
- YangInstanceIdentifier entityPath = YangInstanceIdentifier.builder(ENTITY_TYPES_PATH).
- node(entityTypeNode.getIdentifier()).node(ENTITY_NODE_ID).node(entityNode.getIdentifier()).
- node(ENTITY_OWNER_NODE_ID).build();
-
- Object newOwner = newOwner(getCandidateNames(entityNode), getEntityOwnerElectionStrategy(entityPath));
-
- LOG.debug("{}: Found entity {}, writing new owner {}", persistenceId(), entityPath, newOwner);
-
- modifications.addModification(new WriteModification(entityPath,
- ImmutableNodes.leafNode(ENTITY_OWNER_NODE_ID, newOwner)));
- }
- });
-
- commitCoordinator.commitModifications(modifications, this);
+ // Notify the coordinator to check if pending modifications need to be sent. We do this here
+ // to handle the case where the leader's peer address isn't now yet when a prior state or
+ // leader change occurred.
+ commitCoordinator.onStateChanged(this, isLeader());