use of org.apache.flink.runtime.messages.JobClientMessages.JobManagerActorRef in project flink by apache.
the class JobClientActor method handleMessage.
@Override
protected void handleMessage(Object message) {
if (message instanceof ExecutionGraphMessages.ExecutionStateChanged) {
logAndPrintMessage((ExecutionGraphMessages.ExecutionStateChanged) message);
} else if (message instanceof ExecutionGraphMessages.JobStatusChanged) {
logAndPrintMessage((ExecutionGraphMessages.JobStatusChanged) message);
} else if (message instanceof JobManagerLeaderAddress) {
JobManagerLeaderAddress msg = (JobManagerLeaderAddress) message;
if (jobManager != null) {
// only print this message when we had been connected to a JobManager before
logAndPrintMessage("New JobManager elected. Connecting to " + msg.address());
}
disconnectFromJobManager();
this.leaderSessionID = msg.leaderSessionID();
if (msg.address() != null) {
// Resolve the job manager leader address to obtain an ActorRef
AkkaUtils.getActorRefFuture(msg.address(), getContext().system(), timeout).onSuccess(new OnSuccess<ActorRef>() {
@Override
public void onSuccess(ActorRef result) throws Throwable {
getSelf().tell(decorateMessage(new JobManagerActorRef(result)), ActorRef.noSender());
}
}, getContext().dispatcher());
}
} else if (message instanceof JobManagerActorRef) {
// Resolved JobManager ActorRef
JobManagerActorRef msg = (JobManagerActorRef) message;
connectToJobManager(msg.jobManager());
logAndPrintMessage("Connected to JobManager at " + msg.jobManager());
connectedToJobManager();
} else // client is only interested in the final job result
if (message instanceof JobManagerMessages.JobResultMessage) {
if (LOG.isDebugEnabled()) {
LOG.debug("Received {} message from JobManager", message.getClass().getSimpleName());
}
// forward the success to the original client
if (isClientConnected()) {
this.client.tell(decorateMessage(message), getSelf());
}
terminate();
} else if (message instanceof Terminated) {
ActorRef target = ((Terminated) message).getActor();
if (jobManager.equals(target)) {
LOG.info("Lost connection to JobManager {}. Triggering connection timeout.", jobManager.path());
disconnectFromJobManager();
// ConnectionTimeout extends RequiresLeaderSessionID
if (isClientConnected()) {
getContext().system().scheduler().scheduleOnce(timeout, getSelf(), decorateMessage(JobClientMessages.getConnectionTimeout()), getContext().dispatcher(), ActorRef.noSender());
}
} else {
LOG.warn("Received 'Terminated' for unknown actor " + target);
}
} else if (JobClientMessages.getConnectionTimeout().equals(message)) {
// check if we haven't found a job manager yet
if (!isJobManagerConnected()) {
final JobClientActorConnectionTimeoutException errorMessage = new JobClientActorConnectionTimeoutException("Lost connection to the JobManager.");
final Object replyMessage = decorateMessage(new Status.Failure(errorMessage));
if (isClientConnected()) {
client.tell(replyMessage, getSelf());
}
// Connection timeout reached, let's terminate
terminate();
}
} else if (!isJobManagerConnected() && getClientMessageClass().equals(message.getClass())) {
LOG.info("Received {} but there is no connection to a JobManager yet.", message);
// We want to submit/attach to a job, but we haven't found a job manager yet.
// Let's give him another chance to find a job manager within the given timeout.
getContext().system().scheduler().scheduleOnce(timeout, getSelf(), decorateMessage(JobClientMessages.getConnectionTimeout()), getContext().dispatcher(), ActorRef.noSender());
handleCustomMessage(message);
} else {
if (!toBeTerminated) {
handleCustomMessage(message);
} else {
// we're about to receive a PoisonPill because toBeTerminated == true
String msg = getClass().getName() + " is about to be terminated. Therefore, the " + "job submission cannot be executed.";
LOG.error(msg);
getSender().tell(decorateMessage(new Status.Failure(new Exception(msg))), ActorRef.noSender());
}
}
}
Aggregations