Search in sources :

Example 1 with EventId

use of io.spine.core.EventId in project core-java by SpineEventEngine.

the class EventFactory method createEvent.

/**
 * Creates an event for the passed event message.
 *
 * <p>The message passed is validated according to the constraints set in its Protobuf
 * definition. In case the message isn't valid, an {@linkplain ValidationException
 * exception} is thrown.
 *
 * <p>In the message is an instance of {@code Any}, it is unpacked for validation.
 *
 * <p>It is recommended to use a corresponding {@linkplain io.spine.validate.ValidatingBuilder
 * ValidatingBuilder} implementation to create a message.
 *
 * @param messageOrAny the message of the event or the message packed into {@code Any}
 * @param version      the version of the entity which produces the event
 * @throws ValidationException if the passed message does not satisfy the constraints
 *                             set for it in its Protobuf definition
 */
public Event createEvent(Message messageOrAny, @Nullable Version version) throws ValidationException {
    checkNotNull(messageOrAny);
    // we must validate it now before emitting the next ID.
    validate(messageOrAny);
    final EventId eventId = Events.generateId();
    final EventContext context = createContext(version);
    final Event result = createEvent(eventId, messageOrAny, context);
    return result;
}
Also used : EventContext(io.spine.core.EventContext) IntegrationEventContext(io.spine.server.integration.IntegrationEventContext) EventId(io.spine.core.EventId) Event(io.spine.core.Event) IntegrationEvent(io.spine.server.integration.IntegrationEvent)

Aggregations

Event (io.spine.core.Event)1 EventContext (io.spine.core.EventContext)1 EventId (io.spine.core.EventId)1 IntegrationEvent (io.spine.server.integration.IntegrationEvent)1 IntegrationEventContext (io.spine.server.integration.IntegrationEventContext)1