@Override public R getPayload() { if (isExceptional()) { throw new IllegalPayloadAccessException( "This result completed exceptionally, payload is not available. " + "Try calling 'exceptionResult' to see the cause of failure.", exception ); } return super.getPayload(); } }
@Override public Message<T> withMetaData(Map<String, ?> metaData) { if (getMetaData().equals(metaData)) { return this; } return withMetaData(MetaData.from(metaData)); }
/** * Initializes {@link GenericSubscriptionQueryUpdateMessage} with incremental update. * * @param payload payload of the message which represent incremental update */ public GenericSubscriptionQueryUpdateMessage(U payload) { this(new GenericMessage<>(payload, MetaData.emptyInstance())); }
/** * Creates a ResultMessage with the given {@code result} as the payload. * * @param result the payload for the Message */ public GenericResultMessage(R result) { this(result, MetaData.emptyInstance()); }
/** * Initializes {@link GenericSubscriptionQueryUpdateMessage} with incremental update of provided {@code * declaredType} and {@code metaData}. * * @param declaredType the type of the update * @param payload the payload of the update * @param metaData the metadata of the update */ public GenericSubscriptionQueryUpdateMessage(Class<U> declaredType, U payload, Map<String, ?> metaData) { super(new GenericMessage<>(declaredType, payload, metaData)); }
@Override public Message<T> andMetaData(Map<String, ?> metaData) { if (metaData.isEmpty()) { return this; } return withMetaData(getMetaData().mergedWith(metaData)); }
@SuppressWarnings("unchecked") private <Q, R, T extends QueryMessage<Q, R>> T intercept(T query) { T intercepted = query; for (MessageDispatchInterceptor<? super QueryMessage<?, ?>> interceptor : dispatchInterceptors) { intercepted = (T) interceptor.handle(intercepted); } return intercepted; }
@Override public GenericEventMessage<T> withMetaData(Map<String, ?> metaData) { if (getMetaData().equals(metaData)) { return this; } return new GenericEventMessage<>(getDelegate().withMetaData(metaData), timestampSupplier); }
@Override public GenericResultMessage<R> andMetaData(Map<String, ?> metaData) { return new GenericResultMessage<>(getDelegate().andMetaData(metaData), exception); }
@Override public GenericResultMessage<R> withMetaData(Map<String, ?> metaData) { return new GenericResultMessage<>(getDelegate().withMetaData(metaData), exception); }
/** * Get the current {@link AggregateLifecycle} instance for the current thread. If none exists an {@link * IllegalStateException} is thrown. * * @return the thread's current {@link AggregateLifecycle} */ protected static AggregateLifecycle getInstance() { return Scope.getCurrentScope(); }
/** * Initializes the exception using the given {@code exceptionDescription} describing the remote cause-chain. * * @param exceptionDescription a {@link String} describing the remote exceptions */ public RemoteHandlingException(RemoteExceptionDescription exceptionDescription) { super("An exception was thrown by the remote message handling component: " + exceptionDescription.toString()); this.exceptionDescriptions = exceptionDescription.getDescriptions(); }
/** * Initializes the message with the given {@code payload}, {@code queryName} and expected {@code responseType}. * * @param payload The payload expressing the query * @param queryName The name identifying the query to execute * @param responseType The expected response type of type * {@link ResponseType} */ public GenericQueryMessage(T payload, String queryName, ResponseType<R> responseType) { this(new GenericMessage<>(payload, MetaData.emptyInstance()), queryName, responseType); }
/** * Initialize a DomainEventMessage originating from an Aggregate with the given {@code aggregateIdentifier}, * with given {@code sequenceNumber} and {@code payload}. The MetaData of the message is empty. * * @param type The domain type * @param aggregateIdentifier The identifier of the aggregate generating this message * @param sequenceNumber The message's sequence number * @param payload The application-specific payload of the message */ public GenericDomainEventMessage(String type, String aggregateIdentifier, long sequenceNumber, T payload) { this(type, aggregateIdentifier, sequenceNumber, payload, MetaData.emptyInstance()); }
/** * Constructor to reconstruct an EventMessage using existing data. * * @param identifier The identifier of the Message * @param timestamp The timestamp of the Message creation * @param payload The payload of the message * @param metaData The meta data of the message */ public GenericEventMessage(String identifier, T payload, Map<String, ?> metaData, Instant timestamp) { this(new GenericMessage<>(identifier, payload, metaData), timestamp); }
/** * Initialize the response message with given {@code declaredResultType} and {@code exception}. * * @param declaredResultType The declared type of the Query Response Message to be created * @param exception The Exception describing the cause of an error */ public GenericQueryResponseMessage(Class<R> declaredResultType, Throwable exception) { this(declaredResultType, exception, MetaData.emptyInstance()); }
/** * Creates a ResultMessage with the given {@code exception} and {@code metaData}. * * @param exception the Exception describing the cause of an error * @param metaData the meta data for the Message */ public GenericResultMessage(Throwable exception, Map<String, ?> metaData) { this(new GenericMessage<>(null, metaData), exception); }
/** * Create a CommandMessage with the given {@code command} as payload and empty metaData * * @param payload the payload for the Message */ public GenericCommandMessage(T payload) { this(payload, MetaData.emptyInstance()); }
/** * Creates a ResultMessage with the given {@code exception}. * * @param exception the Exception describing the cause of an error */ public GenericResultMessage(Throwable exception) { this(exception, MetaData.emptyInstance()); }
/** * Creates a GenericEventMessage with given {@code payload}, and an empty MetaData. * * @param payload The payload for the message * @see #asEventMessage(Object) */ public GenericEventMessage(T payload) { this(payload, MetaData.emptyInstance()); }