// submit job
final JobGraph jobGraph = getJobGraph(plan);
final long startingTime = System.currentTimeMillis();
long cancelTime = -1L;
final JobClient client = this.executor.getJobClient(jobGraph);
final JobSubmissionResult submissionResult = client.submitJob();
if (submissionResult.getReturnCode() != AbstractJobResult.ReturnCode.SUCCESS) {
throw new IllegalStateException(submissionResult.getDescription());
}
final int interval = client.getRecommendedPollingInterval();
final long sleep = interval * 1000L;
Thread.sleep(sleep / 2);
long lastProcessedEventSequenceNumber = -1L;
while (true) {
if (Thread.interrupted()) {
throw new IllegalStateException("Job client has been interrupted");
}
final long now = System.currentTimeMillis();
if (cancelTime < 0L) {
// Cancel job
if (startingTime + msecsTillCanceling < now) {
LOG.info("Issuing cancel request");
final JobCancelResult jcr = client.cancelJob();
if (jcr == null) {
throw new IllegalStateException("Return value of cancelJob is null!");
}
if (jcr.getReturnCode() != AbstractJobResult.ReturnCode.SUCCESS) {
throw new IllegalStateException(jcr.getDescription());
}
// Save when the cancel request has been issued
cancelTime = now;
}
} else {
// Job has already been canceled
if (cancelTime + maxTimeTillCanceled < now) {
throw new IllegalStateException("Cancelling of job took " + (now - cancelTime)
+ " milliseconds, only " + maxTimeTillCanceled + " milliseconds are allowed");
}
}
final JobProgressResult jobProgressResult = client.getJobProgress();
if (jobProgressResult == null) {
throw new IllegalStateException("Returned job progress is unexpectedly null!");
}