use of akka.actor.ActorRef in project controller by opendaylight.
the class RaftActor method onShutDown.
private void onShutDown() {
LOG.debug("{}: onShutDown", persistenceId());
if (shuttingDown) {
return;
}
shuttingDown = true;
final RaftActorBehavior currentBehavior = context.getCurrentBehavior();
switch(currentBehavior.state()) {
case Leader:
case PreLeader:
// Fall-through to more work
break;
default:
// For non-leaders shutdown is a no-op
self().tell(PoisonPill.getInstance(), self());
return;
}
if (context.hasFollowers()) {
initiateLeadershipTransfer(new RaftActorLeadershipTransferCohort.OnComplete() {
@Override
public void onSuccess(final ActorRef raftActorRef) {
LOG.debug("{}: leader transfer succeeded - sending PoisonPill", persistenceId());
raftActorRef.tell(PoisonPill.getInstance(), raftActorRef);
}
@Override
public void onFailure(final ActorRef raftActorRef) {
LOG.debug("{}: leader transfer failed - sending PoisonPill", persistenceId());
raftActorRef.tell(PoisonPill.getInstance(), raftActorRef);
}
}, null, TimeUnit.MILLISECONDS.convert(2, TimeUnit.SECONDS));
} else {
pauseLeader(new TimedRunnable(context.getConfigParams().getElectionTimeOutInterval(), this) {
@Override
protected void doRun() {
self().tell(PoisonPill.getInstance(), self());
}
@Override
protected void doCancel() {
self().tell(PoisonPill.getInstance(), self());
}
});
}
}
use of akka.actor.ActorRef in project controller by opendaylight.
the class RaftActor method onRequestLeadership.
private void onRequestLeadership(final RequestLeadership message) {
LOG.debug("{}: onRequestLeadership {}", persistenceId(), message);
if (!isLeader()) {
// non-leader cannot satisfy leadership request
LOG.warn("{}: onRequestLeadership {} was sent to non-leader." + " Current behavior: {}. Sending failure response", persistenceId(), getCurrentBehavior().state());
message.getReplyTo().tell(new LeadershipTransferFailedException("Cannot transfer leader to " + message.getRequestedFollowerId() + ". RequestLeadership message was sent to non-leader " + persistenceId()), getSelf());
return;
}
final String requestedFollowerId = message.getRequestedFollowerId();
final ActorRef replyTo = message.getReplyTo();
initiateLeadershipTransfer(new RaftActorLeadershipTransferCohort.OnComplete() {
@Override
public void onSuccess(final ActorRef raftActorRef) {
// sanity check
if (!requestedFollowerId.equals(getLeaderId())) {
onFailure(raftActorRef);
}
LOG.debug("{}: Leadership transferred successfully to {}", persistenceId(), requestedFollowerId);
replyTo.tell(new Status.Success(null), getSelf());
}
@Override
public void onFailure(final ActorRef raftActorRef) {
LOG.debug("{}: LeadershipTransfer request from {} failed", persistenceId(), requestedFollowerId);
replyTo.tell(new Status.Failure(new LeadershipTransferFailedException("Failed to transfer leadership to " + requestedFollowerId + ". Follower is not ready to become leader")), getSelf());
}
}, message.getRequestedFollowerId(), RaftActorLeadershipTransferCohort.USE_DEFAULT_LEADER_TIMEOUT);
}
use of akka.actor.ActorRef in project controller by opendaylight.
the class ExampleRoleChangeListener method sendRegistrationRequests.
@SuppressWarnings("checkstyle:IllegalCatch")
private void sendRegistrationRequests() {
for (Map.Entry<String, Boolean> entry : notifierRegistrationStatus.entrySet()) {
if (!entry.getValue()) {
try {
LOG.debug("{} registering with {}", getSelf().path().toString(), entry.getKey());
ActorRef notifier = Await.result(getContext().actorSelection(entry.getKey()).resolveOne(DURATION), DURATION);
notifier.tell(new RegisterRoleChangeListener(), getSelf());
} catch (Exception e) {
LOG.error("ERROR!! Unable to send registration request to notifier {}", entry.getKey());
}
}
}
}
use of akka.actor.ActorRef in project controller by opendaylight.
the class RaftActorSnapshotMessageSupport method onGetSnapshot.
private void onGetSnapshot(ActorRef sender) {
log.debug("{}: onGetSnapshot", context.getId());
if (context.getPersistenceProvider().isRecoveryApplicable()) {
CaptureSnapshot captureSnapshot = context.getSnapshotManager().newCaptureSnapshot(context.getReplicatedLog().last(), -1);
ActorRef snapshotReplyActor = context.actorOf(GetSnapshotReplyActor.props(captureSnapshot, ImmutableElectionTerm.copyOf(context.getTermInformation()), sender, snapshotReplyActorTimeout, context.getId(), context.getPeerServerInfo(true)));
cohort.createSnapshot(snapshotReplyActor, Optional.empty());
} else {
Snapshot snapshot = Snapshot.create(EmptyState.INSTANCE, Collections.<ReplicatedLogEntry>emptyList(), -1, -1, -1, -1, context.getTermInformation().getCurrentTerm(), context.getTermInformation().getVotedFor(), context.getPeerServerInfo(true));
sender.tell(new GetSnapshotReply(context.getId(), snapshot), context.getActor());
}
}
use of akka.actor.ActorRef in project controller by opendaylight.
the class TestDriver method addClients.
// add num clients to all nodes in the system
public void addClients(int num) {
for (Map.Entry<String, ActorRef> actorRefEntry : actorRefs.entrySet()) {
for (int i = 0; i < num; i++) {
String clientName = "client-" + i + "-" + actorRefEntry.getKey();
ActorRef clientActor = actorSystem.actorOf(ClientActor.props(actorRefEntry.getValue()), clientName);
clientActorRefs.put(clientName, clientActor);
System.out.println("Created client-node:" + clientName);
}
}
}
Aggregations