/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * 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()); }
/** * Initializes {@link GenericSubscriptionQueryUpdateMessage} with incremental update of provided {@code * declaredType}. * * @param declaredType the type of the update * @param payload the payload of the update */ public GenericSubscriptionQueryUpdateMessage(Class<U> declaredType, U payload) { this(declaredType, payload, MetaData.emptyInstance()); }
/** * Constructs a Message for the given {@code payload} using the correlation data of the current Unit of Work, if * present. * * @param payload The payload for the message */ public GenericMessage(T payload) { this(payload, MetaData.emptyInstance()); }
/** * Instantiate a GenericDeadlineMessage with the given {@code deadlineName}, a {@code payload} of type {@code T} * and en empty {@link MetaData}. * * @param deadlineName A {@link String} denoting the deadline's name * @param payload The payload of type {@code T} for the DeadlineMessage */ public GenericDeadlineMessage(String deadlineName, T payload) { this(deadlineName, payload, MetaData.emptyInstance()); }
/** * Initialize a response message with given {@code result} and {@code declaredResultType}. This constructor allows * the actual result to be {@code null}. * * @param declaredResultType The declared type of the result * @param result The actual result. May be {@code null} */ public GenericQueryResponseMessage(Class<R> declaredResultType, R result) { this(declaredResultType, result, MetaData.emptyInstance()); }
/** * Initialize the response message with given {@code result}. * * @param result The result reported by the Query Handler, may not be {@code null} */ @SuppressWarnings("unchecked") public GenericQueryResponseMessage(R result) { this((Class<R>) result.getClass(), result, MetaData.emptyInstance()); }
/** * Java Serialization specification method that will ensure that deserialization will maintain a single instance of * empty MetaData. * * @return the MetaData instance to use after deserialization */ protected Object readResolve() { if (isEmpty()) { return MetaData.emptyInstance(); } return this; }
/** * 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())); }
/** * 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); }
/** * Returns the Correlation Data attached to the current Unit of Work, or an empty {@link MetaData} instance * if no Unit of Work is started. * * @return a MetaData instance representing the current Unit of Work's correlation data, or an empty MetaData * instance if no Unit of Work is started. * @see UnitOfWork#getCorrelationData() */ public static MetaData correlationData() { return CurrentUnitOfWork.map(UnitOfWork::getCorrelationData).orElse(MetaData.emptyInstance()); }
@Override public ResultValidator<T> when(Object command) { return when(command, MetaData.emptyInstance()); }
@Override public MetaData get() { if (metaData.isEmpty()){ if (map.isEmpty()) { metaData.add(emptyInstance()); } else { metaData.add(from(map.entrySet().stream().collect(toMap(Map.Entry::getKey, e -> convert(e.getValue()))))); } } return metaData.get(0); }
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { if (!reader.hasMoreChildren()) { return MetaData.emptyInstance(); } Map<String, Object> contents = new HashMap<>(); populateMap(reader, context, contents); if (contents.isEmpty()) { return MetaData.emptyInstance(); } else { return MetaData.from(contents); } } }
@Override public MetaData getCorrelationData() { if (correlationDataProviders.isEmpty()) { return MetaData.emptyInstance(); } Map<String, Object> result = new HashMap<>(); for (CorrelationDataProvider correlationDataProvider : correlationDataProviders) { final Map<String, ?> extraData = correlationDataProvider.correlationDataFor(getMessage()); if (extraData != null) { result.putAll(extraData); } } return MetaData.from(result); }
private MetaData deserializeMetaData(Map<String, MetaDataValue> metaDataMap) { if (metaDataMap.isEmpty()) { return MetaData.emptyInstance(); } GrpcMetaDataConverter grpcMetaDataConverter = new GrpcMetaDataConverter(serializer); return MetaData.from(grpcMetaDataConverter.convert(metaDataMap)); } }