/** * Resets the state of this Unit of Work, by setting its phase to {@code NOT_STARTED}, replacing the message * of this Unit of Work with given {@code message}, and clearing its collection of registered handlers. * * @param message the new Message that is about to be processed. */ public void reset(T message) { if (processingContext == null) { processingContext = new MessageProcessingContext<>(message); } else { processingContext.reset(message); } setPhase(Phase.NOT_STARTED); resources().clear(); correlationDataProviders().clear(); }
@Override protected void addHandler(Phase phase, Consumer<UnitOfWork<T>> handler) { processingContext.addHandler(phase, handler); }
@Override public ExecutionResult getExecutionResult() { return processingContext.getExecutionResult(); } }
@Override public T getMessage() { return processingContext.getMessage(); }
@Override protected void setExecutionResult(ExecutionResult executionResult) { processingContext.setExecutionResult(executionResult); } }
@Override public UnitOfWork<T> transformMessage(Function<T, ? extends Message<?>> transformOperator) { processingContext.transformMessage(transformOperator); return this; }
@Override protected void notifyHandlers(Phase phase) { processingContext.notifyHandlers(this, phase); }
/** * Initializes a Unit of Work (without starting it). * * @param message the message that will be processed in the context of the unit of work */ public DefaultUnitOfWork(T message) { processingContext = new MessageProcessingContext<>(message); }
@Override public T getMessage() { return processingContext.getMessage(); }
@Override protected void setExecutionResult(ExecutionResult executionResult) { processingContext.setExecutionResult(executionResult); }
@Override public UnitOfWork<T> transformMessage(Function<T, ? extends Message<?>> transformOperator) { processingContext.transformMessage(transformOperator); return this; }
@Override protected void notifyHandlers(Phase phase) { processingContext.notifyHandlers(this, phase); }
/** * Initializes a Unit of Work (without starting it). * * @param message the message that will be processed in the context of the unit of work */ public DefaultUnitOfWork(T message) { processingContext = new MessageProcessingContext<>(message); }
@Override public T getMessage() { return processingContext.getMessage(); }
@Override protected void setExecutionResult(ExecutionResult executionResult) { processingContext.setExecutionResult(executionResult); }
@Override public ExecutionResult getExecutionResult() { return processingContext.getExecutionResult(); }
@Override public UnitOfWork<T> transformMessage(Function<T, ? extends Message<?>> transformOperator) { processingContext.transformMessage(transformOperator); return this; }
@Override protected void notifyHandlers(Phase phase) { Iterator<MessageProcessingContext<T>> iterator = phase.isReverseCallbackOrder() ? new LinkedList<>(processingContexts).descendingIterator() : processingContexts.iterator(); iterator.forEachRemaining(context -> (processingContext = context).notifyHandlers(this, phase)); }
@Override protected void addHandler(Phase phase, Consumer<UnitOfWork<T>> handler) { processingContext.addHandler(phase, handler); }
/** * Resets the state of this Unit of Work, by setting its phase to {@code NOT_STARTED}, replacing the message * of this Unit of Work with given {@code message}, and clearing its collection of registered handlers. * * @param message the new Message that is about to be processed. */ public void reset(T message) { if (processingContext == null) { processingContext = new MessageProcessingContext<>(message); } else { processingContext.reset(message); } setPhase(Phase.NOT_STARTED); resources().clear(); correlationDataProviders().clear(); }