use of akka.actor.ActorSelection in project controller by opendaylight.
the class AbstractDataStoreClientBehaviorTest 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(SHARD)).thenReturn(promise.future());
return mock;
}
use of akka.actor.ActorSelection in project controller by opendaylight.
the class ActorContext method onPrimaryShardFound.
private PrimaryShardInfo onPrimaryShardFound(String shardName, String primaryActorPath, short primaryVersion, DataTree localShardDataTree) {
ActorSelection actorSelection = actorSystem.actorSelection(primaryActorPath);
PrimaryShardInfo info = localShardDataTree == null ? new PrimaryShardInfo(actorSelection, primaryVersion) : new PrimaryShardInfo(actorSelection, primaryVersion, localShardDataTree);
primaryShardInfoCache.putSuccessful(shardName, info);
return info;
}
use of akka.actor.ActorSelection in project controller by opendaylight.
the class EntityOwnershipShard method tryCommitModifications.
void tryCommitModifications(final BatchedModifications modifications) {
if (isLeader()) {
LOG.debug("{}: Committing BatchedModifications {} locally", persistenceId(), modifications.getTransactionId());
// Note that it's possible the commit won't get consensus and will timeout and not be applied
// to the state. However we don't need to retry it in that case b/c it will be committed to
// the journal first and, once a majority of followers come back on line and it is replicated,
// it will be applied at that point.
handleBatchedModificationsLocal(modifications, self());
} else {
final ActorSelection leader = getLeader();
if (leader != null) {
possiblyRemoveAllInitialCandidates(leader);
LOG.debug("{}: Sending BatchedModifications {} to leader {}", persistenceId(), modifications.getTransactionId(), leader);
Future<Object> future = Patterns.ask(leader, modifications, TimeUnit.SECONDS.toMillis(getDatastoreContext().getShardTransactionCommitTimeoutInSeconds()));
Patterns.pipe(future, getContext().dispatcher()).pipeTo(getSelf(), ActorRef.noSender());
}
}
}
use of akka.actor.ActorSelection in project controller by opendaylight.
the class ShardDataTreeListenerInfoMXBeanImpl method getListenerActorsInfo.
@SuppressWarnings("checkstyle:IllegalCatch")
private List<DataTreeListenerInfo> getListenerActorsInfo(Collection<ActorSelection> actors) {
final Timeout timeout = new Timeout(20, TimeUnit.SECONDS);
final List<Future<Object>> futureList = new ArrayList<>(actors.size());
for (ActorSelection actor : actors) {
futureList.add(Patterns.ask(actor, GetInfo.INSTANCE, timeout));
}
try {
final List<DataTreeListenerInfo> listenerInfoList = new ArrayList<>();
Await.result(Futures.sequence(futureList, ExecutionContext.Implicits$.MODULE$.global()), timeout.duration()).forEach(obj -> listenerInfoList.add((DataTreeListenerInfo) obj));
return listenerInfoList;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of akka.actor.ActorSelection in project controller by opendaylight.
the class RaftActorLeadershipTransferCohort method init.
void init() {
RaftActorContext context = raftActor.getRaftActorContext();
RaftActorBehavior currentBehavior = raftActor.getCurrentBehavior();
transferTimer.start();
Optional<ActorRef> roleChangeNotifier = raftActor.getRoleChangeNotifier();
if (roleChangeNotifier.isPresent()) {
roleChangeNotifier.get().tell(raftActor.newLeaderStateChanged(context.getId(), null, currentBehavior.getLeaderPayloadVersion()), raftActor.self());
}
for (String peerId : context.getPeerIds()) {
ActorSelection followerActor = context.getPeerActorSelection(peerId);
if (followerActor != null) {
followerActor.tell(new LeaderTransitioning(context.getId()), context.getActor());
}
}
raftActor.pauseLeader(new TimedRunnable(context.getConfigParams().getElectionTimeOutInterval(), raftActor) {
@Override
protected void doRun() {
LOG.debug("{}: pauseLeader successfully completed - doing transfer", raftActor.persistenceId());
doTransfer();
}
@Override
protected void doCancel() {
LOG.debug("{}: pauseLeader timed out - continuing with transfer", raftActor.persistenceId());
doTransfer();
}
});
}
Aggregations