use of akka.actor.ActorSelection in project controller by opendaylight.
the class Leader method tryToCompleteLeadershipTransfer.
private void tryToCompleteLeadershipTransfer(String followerId) {
if (leadershipTransferContext == null) {
return;
}
final Optional<String> requestedFollowerIdOptional = leadershipTransferContext.transferCohort.getRequestedFollowerId();
if (requestedFollowerIdOptional.isPresent() && !requestedFollowerIdOptional.get().equals(followerId)) {
// we want to transfer leadership to specific follower
return;
}
FollowerLogInformation followerInfo = getFollower(followerId);
if (followerInfo == null) {
return;
}
long lastIndex = context.getReplicatedLog().lastIndex();
boolean isVoting = context.getPeerInfo(followerId).isVoting();
log.debug("{}: tryToCompleteLeadershipTransfer: followerId: {}, matchIndex: {}, lastIndex: {}, isVoting: {}", logName(), followerId, followerInfo.getMatchIndex(), lastIndex, isVoting);
if (isVoting && followerInfo.getMatchIndex() == lastIndex) {
log.debug("{}: Follower's log matches - sending ElectionTimeout", logName());
// We can't be sure if the follower has applied all its log entries to its state so send an
// additional AppendEntries with the latest commit index.
sendAppendEntries(0, false);
// Now send a TimeoutNow message to the matching follower to immediately start an election.
ActorSelection followerActor = context.getPeerActorSelection(followerId);
followerActor.tell(TimeoutNow.INSTANCE, context.getActor());
log.debug("{}: Leader transfer complete", logName());
leadershipTransferContext.transferCohort.transferComplete();
leadershipTransferContext = null;
}
}
use of akka.actor.ActorSelection in project controller by opendaylight.
the class RaftActorServerConfigurationSupport method onNewOperation.
private void onNewOperation(final ServerOperationContext<?> operationContext) {
if (raftActor.isLeader()) {
currentOperationState.onNewOperation(operationContext);
} else {
ActorSelection leader = raftActor.getLeader();
if (leader != null) {
LOG.debug("{}: Not leader - forwarding to leader {}", raftContext.getId(), leader);
leader.tell(operationContext.getOperation(), operationContext.getClientRequestor());
} else {
LOG.debug("{}: No leader - returning NO_LEADER reply", raftContext.getId());
operationContext.getClientRequestor().tell(operationContext.newReply(ServerChangeStatus.NO_LEADER, null), raftActor.self());
}
}
}
use of akka.actor.ActorSelection in project controller by opendaylight.
the class AbstractClientHandleTest method createActorContextMock.
private static ActorContext createActorContextMock(final ActorSystem system, final ActorRef actor) {
final ActorContext mock = mock(ActorContext.class);
final Promise<PrimaryShardInfo> promise = new scala.concurrent.impl.Promise.DefaultPromise<>();
final ActorSelection selection = system.actorSelection(actor.path());
final PrimaryShardInfo shardInfo = new PrimaryShardInfo(selection, (short) 0);
promise.success(shardInfo);
when(mock.findPrimaryShardAsync(any())).thenReturn(promise.future());
return mock;
}
use of akka.actor.ActorSelection in project controller by opendaylight.
the class ShardedDataTreeActor method onProducerRemoved.
private void onProducerRemoved(final ProducerRemoved message) {
LOG.debug("Received ProducerRemoved: {}", message);
final List<CompletableFuture<Object>> futures = new ArrayList<>();
for (final String address : resolver.getShardingServicePeerActorAddresses()) {
final ActorSelection selection = actorSystem.actorSelection(address);
futures.add(FutureConverters.toJava(actorContext.executeOperationAsync(selection, new NotifyProducerRemoved(message.getSubtrees()))).toCompletableFuture());
}
final CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()]));
final ActorRef respondTo = getSender();
combinedFuture.thenRun(() -> respondTo.tell(new Status.Success(null), self())).exceptionally(e -> {
respondTo.tell(new Status.Failure(null), self());
return null;
});
}
use of akka.actor.ActorSelection in project controller by opendaylight.
the class ShardedDataTreeActor method onProducerCreated.
private void onProducerCreated(final ProducerCreated message) {
LOG.debug("Received ProducerCreated: {}", message);
// fastpath if we have no peers
if (resolver.getShardingServicePeerActorAddresses().isEmpty()) {
getSender().tell(new Status.Success(null), noSender());
}
final ActorRef sender = getSender();
final Collection<DOMDataTreeIdentifier> subtrees = message.getSubtrees();
final List<CompletableFuture<Object>> futures = new ArrayList<>();
for (final String address : resolver.getShardingServicePeerActorAddresses()) {
final ActorSelection actorSelection = actorSystem.actorSelection(address);
futures.add(FutureConverters.toJava(actorContext.executeOperationAsync(actorSelection, new NotifyProducerCreated(subtrees), DEFAULT_ASK_TIMEOUT)).toCompletableFuture());
}
final CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()]));
combinedFuture.thenRun(() -> sender.tell(new Success(null), noSender())).exceptionally(throwable -> {
sender.tell(new Status.Failure(throwable), self());
return null;
});
}
Aggregations