/** * Get the execution result in case the result is an exception. If the execution yielded no exception this method * returns {@code null}. * * @return The exception raised during execution of the task if any, {@code null} otherwise. */ public Throwable getExceptionResult() { return isExceptionResult() ? result.exceptionResult() : null; }
/** * Set the execution result of processing the current {@link #getMessage() Message}. In case this context has a * previously set ExecutionResult, setting a new result is only allowed if the new result is an exception result. * <p/> * In case the previously set result is also an exception result, the exception in the new execution result is * added to the original exception as a suppressed exception. * * @param executionResult the ExecutionResult of the currently handled Message */ @SuppressWarnings("ThrowableResultOfMethodCallIgnored") public void setExecutionResult(ExecutionResult executionResult) { Assert.state(this.executionResult == null || executionResult.isExceptionResult(), () -> String.format("Cannot change execution result [%s] to [%s] for message [%s].", message, this.executionResult, executionResult)); if (this.executionResult != null && this.executionResult.isExceptionResult()) { this.executionResult.getExceptionResult().addSuppressed(executionResult.getExceptionResult()); } else { this.executionResult = executionResult; } }
@Override public BiFunction<Integer, EventMessage<?>, EventMessage<?>> handle(List<? extends EventMessage<?>> messages) { StringBuilder sb = new StringBuilder(String.format("Events published: [%s]", messages.stream().map(m -> m.getPayloadType().getSimpleName()).collect(Collectors.joining(", ")))); CurrentUnitOfWork.ifStarted(unitOfWork -> { Message<?> message = unitOfWork.getMessage(); if (message == null) { sb.append(" while processing an operation not tied to an incoming message"); } else { sb.append(String.format(" while processing a [%s]", message.getPayloadType().getSimpleName())); } ExecutionResult executionResult = unitOfWork.getExecutionResult(); if (executionResult != null) { if (executionResult.isExceptionResult()) { @SuppressWarnings("ThrowableResultOfMethodCallIgnored") Throwable exception = executionResult.getExceptionResult(); exception = exception instanceof ExecutionException ? exception.getCause() : exception; sb.append(String.format(" which failed with a [%s]", exception.getClass().getSimpleName())); } else if (executionResult.getResult() != null) { sb.append(String.format(" which yielded a [%s] return value", executionResult.getResult().getClass().getSimpleName())); } } }); logger.info(sb.toString()); return (i, m) -> m; } }
/** * Get the execution result in case the result is an exception. If the execution yielded no exception this method * returns {@code null}. * * @return The exception raised during execution of the task if any, {@code null} otherwise. */ public Throwable getExceptionResult() { return isExceptionResult() ? (Throwable) result : null; }
/** * Get the execution result in case the result is an exception. If the execution yielded no exception this method * returns {@code null}. * * @return The exception raised during execution of the task if any, {@code null} otherwise. */ public Throwable getExceptionResult() { return isExceptionResult() ? result.exceptionResult() : null; }
/** * Returns the execution result. If the execution was completed successfully but yielded no result this method * returns {@code null}. If the execution gave rise to an exception, invoking this method will throw an * exception. Unchecked exceptions will be thrown directly. Checked exceptions are wrapped by a * {@link org.axonframework.messaging.ExecutionException}. * * @return The result of the execution if the operation was executed without raising an exception. */ public Object getResult() { if (isExceptionResult()) { if (result instanceof RuntimeException) { throw (RuntimeException) result; } if (result instanceof Error) { throw (Error) result; } throw new ExecutionException("Execution of the task gave rise to an exception", (Throwable) result); } return result; }
/** * Set the execution result of processing the current {@link #getMessage() Message}. In case this context has a * previously set ExecutionResult, setting a new result is only allowed if the new result is an exception result. * <p/> * In case the previously set result is also an exception result, the exception in the new execution result is * added to the original exception as a suppressed exception. * * @param executionResult the ExecutionResult of the currently handled Message */ @SuppressWarnings("ThrowableResultOfMethodCallIgnored") public void setExecutionResult(ExecutionResult executionResult) { Assert.state(this.executionResult == null || executionResult.isExceptionResult(), () -> String.format("Cannot change execution result [%s] to [%s] for message [%s].", message, this.executionResult, executionResult)); if (this.executionResult != null && this.executionResult.isExceptionResult()) { this.executionResult.getExceptionResult().addSuppressed(executionResult.getExceptionResult()); } else { this.executionResult = executionResult; } }
/** * Set the execution result of processing the current {@link #getMessage() Message}. In case this context has a * previously set ExecutionResult, setting a new result is only allowed if the new result is an exception result. * <p/> * In case the previously set result is also an exception result, the exception in the new execution result is * added to the original exception as a suppressed exception. * * @param executionResult the ExecutionResult of the currently handled Message */ @SuppressWarnings("ThrowableResultOfMethodCallIgnored") public void setExecutionResult(ExecutionResult executionResult) { Assert.state(this.executionResult == null || executionResult.isExceptionResult(), () -> String.format("Cannot change execution result [%s] to [%s] for message [%s].", message, this.executionResult, executionResult)); if (this.executionResult != null && this.executionResult.isExceptionResult()) { this.executionResult.getExceptionResult().addSuppressed(executionResult.getExceptionResult()); } else { this.executionResult = executionResult; } }
@Override public BiFunction<Integer, EventMessage<?>, EventMessage<?>> handle(List<? extends EventMessage<?>> messages) { StringBuilder sb = new StringBuilder(String.format("Events published: [%s]", messages.stream().map(m -> m.getPayloadType().getSimpleName()).collect(Collectors.joining(", ")))); CurrentUnitOfWork.ifStarted(unitOfWork -> { Message<?> message = unitOfWork.getMessage(); if (message == null) { sb.append(" while processing an operation not tied to an incoming message"); } else { sb.append(String.format(" while processing a [%s]", message.getPayloadType().getSimpleName())); } ExecutionResult executionResult = unitOfWork.getExecutionResult(); if (executionResult != null) { if (executionResult.isExceptionResult()) { @SuppressWarnings("ThrowableResultOfMethodCallIgnored") Throwable exception = executionResult.getExceptionResult(); exception = exception instanceof ExecutionException ? exception.getCause() : exception; sb.append(String.format(" which failed with a [%s]", exception.getClass().getSimpleName())); } else if (executionResult.getResult() != null) { sb.append(String.format(" which yielded a [%s] return value", executionResult.getResult().getClass().getSimpleName())); } } }); logger.info(sb.toString()); return (i, m) -> m; } }
@Override public BiFunction<Integer, EventMessage<?>, EventMessage<?>> handle(List<? extends EventMessage<?>> messages) { StringBuilder sb = new StringBuilder(String.format("Events published: [%s]", messages.stream().map(m -> m.getPayloadType().getSimpleName()).collect(Collectors.joining(", ")))); CurrentUnitOfWork.ifStarted(unitOfWork -> { Message<?> message = unitOfWork.getMessage(); if (message == null) { sb.append(" while processing an operation not tied to an incoming message"); } else { sb.append(String.format(" while processing a [%s]", message.getPayloadType().getSimpleName())); } ExecutionResult executionResult = unitOfWork.getExecutionResult(); if (executionResult != null) { if (executionResult.isExceptionResult()) { @SuppressWarnings("ThrowableResultOfMethodCallIgnored") Throwable exception = executionResult.getExceptionResult(); exception = exception instanceof ExecutionException ? exception.getCause() : exception; sb.append(String.format(" which failed with a [%s]", exception.getClass().getSimpleName())); } else if (executionResult.getResult() != null) { sb.append(String.format(" which yielded a [%s] return value", executionResult.getResult().getClass().getSimpleName())); } } }); logger.info(sb.toString()); return (i, m) -> m; } }