use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.
the class AsyncTransformUsingServiceOrderedP method tryFlushQueue.
/**
* Drains items from the queue until either:
* <ul><li>
* encountering a non-completed item
* </li><li>
* the outbox gets full
* </li></ul>
*
* @return true if there are no more in-flight items and everything was emitted
* to the outbox
*/
boolean tryFlushQueue() {
// queue. It also doesn't shuffle the stream items.
for (; ; ) {
if (!emitFromTraverser(currentTraverser)) {
return false;
}
Object o = queue.peek();
if (o == null) {
return true;
}
if (o instanceof Watermark) {
watermarkTraverser.accept((Watermark) o);
currentTraverser = watermarkTraverser;
queuedWmCount--;
} else {
@SuppressWarnings("unchecked") Tuple2<T, CompletableFuture<IR>> cast = (Tuple2<T, CompletableFuture<IR>>) o;
T item = cast.f0();
CompletableFuture<IR> future = cast.f1();
assert future != null;
if (!future.isDone()) {
return false;
}
try {
currentTraverser = mapResultFn.apply(item, future.get());
if (currentTraverser == null) {
currentTraverser = Traversers.empty();
}
} catch (Throwable e) {
throw new JetException("Async operation completed exceptionally: " + e, e);
}
}
queue.remove();
}
}
use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.
the class SessionWindowP method restoreFromSnapshot.
@Override
@SuppressWarnings("unchecked")
protected void restoreFromSnapshot(@Nonnull Object key, @Nonnull Object value) {
if (key instanceof BroadcastKey) {
BroadcastKey bcastKey = (BroadcastKey) key;
if (!Keys.CURRENT_WATERMARK.equals(bcastKey.key())) {
throw new JetException("Unexpected broadcast key: " + bcastKey.key());
}
long newCurrentWatermark = (long) value;
assert processingGuarantee != EXACTLY_ONCE || minRestoredCurrentWatermark == Long.MAX_VALUE || minRestoredCurrentWatermark == newCurrentWatermark : "different values for currentWatermark restored, before=" + minRestoredCurrentWatermark + ", new=" + newCurrentWatermark;
minRestoredCurrentWatermark = Math.min(newCurrentWatermark, minRestoredCurrentWatermark);
return;
}
if (keyToWindows.put((K) key, (Windows) value) != null) {
throw new JetException("Duplicate key in snapshot: " + key);
}
}
use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.
the class FileSourceBuilder method buildMetaSupplier.
/**
* Builds a {@link ProcessorMetaSupplier} based on the current state of the
* builder. Use for integration with the Core API.
* <p>
* This method is a part of Core API and has lower backward-compatibility
* guarantees (we can change it in minor version).
*/
@Nonnull
public ProcessorMetaSupplier buildMetaSupplier() {
if (path == null) {
throw new IllegalStateException("Parameter 'path' is required");
}
if (format == null) {
throw new IllegalStateException("Parameter 'format' is required");
}
FileSourceConfiguration<T> fsc = new FileSourceConfiguration<>(path, glob, format, sharedFileSystem, ignoreFileNotFound, options);
if (shouldUseHadoop()) {
ServiceLoader<FileSourceFactory> loader = ServiceLoader.load(FileSourceFactory.class);
// Only one implementation is expected to be present on classpath
Iterator<FileSourceFactory> iterator = loader.iterator();
if (!iterator.hasNext()) {
throw new JetException("No suitable FileSourceFactory found. " + "Do you have Jet's Hadoop module on classpath?");
}
FileSourceFactory fileSourceFactory = iterator.next();
if (iterator.hasNext()) {
throw new JetException("Multiple FileSourceFactory implementations found");
}
return fileSourceFactory.create(fsc);
}
return new LocalFileSourceFactory().create(fsc);
}
use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.
the class JobResult method getFailureAsThrowable.
/**
* Returns a mock throwable created for the failureText. It's either {@link
* CancellationException} or {@link JetException} with the failureText
* text.
*/
@Nullable
public Throwable getFailureAsThrowable() {
if (failureText == null) {
return null;
}
Throwable throwable;
if (failureText.startsWith(CancellationException.class.getName())) {
int prefixLength = (CancellationException.class.getName() + ": ").length();
String message = failureText.length() >= prefixLength ? failureText.substring(prefixLength) : null;
throwable = new CancellationException(message);
} else {
throwable = new JetException(failureText);
}
return throwable;
}
use of com.hazelcast.jet.JetException in project hazelcast by hazelcast.
the class ProcessorTasklet method stateMachineStep.
@SuppressWarnings("checkstyle:returncount")
private void stateMachineStep() {
switch(state) {
case PROCESS_WATERMARK:
if (pendingWatermark == null) {
long wm = watermarkCoalescer.checkWmHistory();
if (wm == NO_NEW_WM) {
state = NULLARY_PROCESS;
// recursion
stateMachineStep();
break;
}
pendingWatermark = new Watermark(wm);
}
if (pendingWatermark.equals(IDLE_MESSAGE) ? outbox.offer(IDLE_MESSAGE) : doWithClassLoader(context.classLoader(), () -> processor.tryProcessWatermark(pendingWatermark))) {
state = NULLARY_PROCESS;
pendingWatermark = null;
}
break;
case NULLARY_PROCESS:
// if currInstream is null, maybe fillInbox wasn't called yet. Avoid calling tryProcess in that case.
if (currInstream == null || isSnapshotInbox() || doWithClassLoader(context.classLoader(), () -> processor.tryProcess())) {
state = PROCESS_INBOX;
outbox.reset();
// recursion
stateMachineStep();
}
break;
case PROCESS_INBOX:
processInbox();
return;
case COMPLETE_EDGE:
if (isSnapshotInbox() ? doWithClassLoader(context.classLoader(), () -> processor.finishSnapshotRestore()) : doWithClassLoader(context.classLoader(), () -> processor.completeEdge(currInstream.ordinal()))) {
assert !outbox.hasUnfinishedItem() || !isSnapshotInbox() : "outbox has an unfinished item after successful finishSnapshotRestore()";
progTracker.madeProgress();
state = processingState();
}
return;
case SAVE_SNAPSHOT:
if (doWithClassLoader(context.classLoader(), () -> processor.saveToSnapshot())) {
progTracker.madeProgress();
state = ssContext.isExportOnly() ? EMIT_BARRIER : SNAPSHOT_COMMIT_PREPARE;
// recursion
stateMachineStep();
}
return;
case SNAPSHOT_COMMIT_PREPARE:
if (doWithClassLoader(context.classLoader(), () -> processor.snapshotCommitPrepare())) {
progTracker.madeProgress();
state = EMIT_BARRIER;
// recursion
stateMachineStep();
}
return;
case EMIT_BARRIER:
assert currentBarrier != null : "currentBarrier == null";
if (outbox.offerToEdgesAndSnapshot(currentBarrier)) {
progTracker.madeProgress();
if (currentBarrier.isTerminal()) {
state = WAITING_FOR_SNAPSHOT_COMPLETED;
} else {
currentBarrier = null;
receivedBarriers.clear();
pendingSnapshotId1++;
state = processingState();
}
}
return;
case SNAPSHOT_COMMIT_FINISH__PROCESS:
case SNAPSHOT_COMMIT_FINISH__COMPLETE:
case SNAPSHOT_COMMIT_FINISH__FINAL:
if (ssContext.isExportOnly() || doWithClassLoader(context.classLoader(), () -> processor.snapshotCommitFinish(ssContext.isLastPhase1Successful()))) {
pendingSnapshotId2++;
ssContext.phase2DoneForTasklet();
progTracker.madeProgress();
switch(state) {
case SNAPSHOT_COMMIT_FINISH__PROCESS:
state = PROCESS_INBOX;
break;
case SNAPSHOT_COMMIT_FINISH__COMPLETE:
state = COMPLETE;
break;
case SNAPSHOT_COMMIT_FINISH__FINAL:
state = PRE_EMIT_DONE_ITEM;
break;
default:
throw new RuntimeException("unexpected state: " + state);
}
}
return;
case WAITING_FOR_SNAPSHOT_COMPLETED:
long currSnapshotId2 = ssContext.activeSnapshotIdPhase2();
if (currSnapshotId2 >= pendingSnapshotId2) {
state = SNAPSHOT_COMMIT_FINISH__FINAL;
// recursion
stateMachineStep();
}
return;
case COMPLETE:
complete();
return;
case PRE_EMIT_DONE_ITEM:
ssContext.processorTaskletDone(pendingSnapshotId2 - 1);
state = EMIT_DONE_ITEM;
stateMachineStep();
return;
case EMIT_DONE_ITEM:
if (outbox.offerToEdgesAndSnapshot(DONE_ITEM)) {
progTracker.madeProgress();
state = CLOSE;
stateMachineStep();
}
return;
case CLOSE:
if (isCooperative() && !processor.closeIsCooperative()) {
if (closeFuture == null) {
ClassLoader contextCl = Thread.currentThread().getContextClassLoader();
closeFuture = executionService.submit(() -> doWithClassLoader(contextCl, this::closeProcessor));
progTracker.madeProgress();
}
if (!closeFuture.isDone()) {
return;
}
progTracker.madeProgress();
} else {
closeProcessor();
}
state = END;
progTracker.done();
return;
default:
// note ProcessorState.END goes here
throw new JetException("Unexpected state: " + state);
}
}
Aggregations