private static Stage<Object, ?> getCurrentStage(final PipelineContext context) { return context .getCurrentStage() .orElseThrow(() -> new IllegalStateException("There was not current stage even though the process has not finished.")); }
private static Object pollOutput(final PipelineContext context) { return context.pollOutput() .orElseThrow(() -> new IllegalStateException("The " + PipelineContext.class.getSimpleName() + " was polled with no previous output.")); }
private void continuePipeline(final PipelineContext context, final PipelineEventListener... eventListeners) { while (!context.isFinished()) { final Stage<Object, ?> stage = getCurrentStage(context); final Object newInput = pollOutput(context); propagateEvent(new BeforeStageExecutionEvent(context.getExecutionId(), context.getPipeline(), stage), eventListeners); ((ContextAware) output).setContext(Collections.unmodifiableMap(context.getValues())); final Object newOutput = interpolate(context.getValues(), output); if (executor == null) { throw new RuntimeException("Fail to resolve ConfigExecutor for: " + output.getClass()); context.getValues().put(executor.inputId(), newOutput); if (executor instanceof BiFunctionConfigExecutor) { final Optional result = (Optional) ((BiFunctionConfigExecutor) executor).apply(newInput, newOutput); context.pushOutput(executor.outputId(), result.get()); } else if (executor instanceof FunctionConfigExecutor) { final Optional result = (Optional) ((FunctionConfigExecutor) executor).apply(newOutput); context.pushOutput(executor.outputId(), result.get());
public <T> void execute(final Input input, final Pipeline pipeline, final Consumer<T> callback, final PipelineEventListener... eventListeners) { final PipelineContext context = new PipelineContext(pipeline); context.start(input); context.pushCallback(callback); propagateEvent(new BeforePipelineExecutionEvent(context.getExecutionId(), pipeline), eventListeners); continuePipeline(context, eventListeners); propagateEvent(new AfterPipelineExecutionEvent(context.getExecutionId(), pipeline), eventListeners); }
void start(final Object initialInput) { if (isStarted()) { throw new RuntimeException("Process has already been started."); } this.values.put("input", initialInput); if (initialInput instanceof Input) { executionId = ((Input) initialInput).computeIfAbsent(PIPELINE_EXECUTION_ID, generator -> ExecutionIdGenerator.generateExecutionId()); } else { executionId = ExecutionIdGenerator.generateExecutionId(); } if (iterator.hasNext()) { currentStage = Optional.of(iterator.next()); } else { currentStage = Optional.empty(); } lastOutput = Optional.of(initialInput); }
private void continuePipeline(final PipelineContext context, final PipelineEventListener... eventListeners) { while (!context.isFinished()) { final Stage<Object, ?> stage = getCurrentStage(context); final Object newInput = pollOutput(context); propagateEvent(new BeforeStageExecutionEvent(context.getExecutionId(), context.getPipeline(), stage), eventListeners); ((ContextAware) output).setContext(Collections.unmodifiableMap(context.getValues())); final Object newOutput = interpolate(context.getValues(), output); if (executor == null) { throw new RuntimeException("Fail to resolve ConfigExecutor for: " + output.getClass()); context.getValues().put(executor.inputId(), newOutput); if (executor instanceof BiFunctionConfigExecutor) { final Optional result = (Optional) ((BiFunctionConfigExecutor) executor).apply(newInput, newOutput); context.pushOutput(executor.outputId(), result.get()); } else if (executor instanceof FunctionConfigExecutor) { final Optional result = (Optional) ((FunctionConfigExecutor) executor).apply(newOutput); context.pushOutput(executor.outputId(), result.get());
public <T> void execute(final Input input, final Pipeline pipeline, final Consumer<T> callback, final PipelineEventListener... eventListeners) { final PipelineContext context = new PipelineContext(pipeline); context.start(input); context.pushCallback(callback); propagateEvent(new BeforePipelineExecutionEvent(context.getExecutionId(), pipeline), eventListeners); continuePipeline(context, eventListeners); propagateEvent(new AfterPipelineExecutionEvent(context.getExecutionId(), pipeline), eventListeners); }
void start(final Object initialInput) { if (isStarted()) { throw new RuntimeException("Process has already been started."); } this.values.put("input", initialInput); if (initialInput instanceof Input) { executionId = ((Input) initialInput).computeIfAbsent(PIPELINE_EXECUTION_ID, generator -> ExecutionIdGenerator.generateExecutionId()); } else { executionId = ExecutionIdGenerator.generateExecutionId(); } if (iterator.hasNext()) { currentStage = Optional.of(iterator.next()); } else { currentStage = Optional.empty(); } lastOutput = Optional.of(initialInput); }
private static Stage<Object, ?> getCurrentStage(final PipelineContext context) { return context .getCurrentStage() .orElseThrow(() -> new IllegalStateException("There was not current stage even though the process has not finished.")); }
private static Object pollOutput(final PipelineContext context) { return context.pollOutput() .orElseThrow(() -> new IllegalStateException("The " + PipelineContext.class.getSimpleName() + " was polled with no previous output.")); }