Search in sources :

Example 6 with EventId

use of io.spine.base.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 ConstraintViolationThrowable
     * 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 ConstraintViolationThrowable 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 ConstraintViolationThrowable {
    checkNotNull(messageOrAny);
    // we must validate it now before emitting the next ID.
    validate(messageOrAny);
    final EventId eventId = idSequence.next();
    final EventContext context = createContext(producerId, commandContext, version);
    final Event result = createEvent(eventId, messageOrAny, context);
    return result;
}
Also used : IntegrationEventContext(io.spine.server.integration.IntegrationEventContext) EventContext(io.spine.base.EventContext) EventId(io.spine.base.EventId) IntegrationEvent(io.spine.server.integration.IntegrationEvent) Event(io.spine.base.Event)

Aggregations

EventId (io.spine.base.EventId)6 Event (io.spine.base.Event)2 EventRecordStorage (io.spine.server.storage.EventRecordStorage)2 Test (org.junit.Test)2 EventContext (io.spine.base.EventContext)1 Identifiers.idToString (io.spine.base.Identifiers.idToString)1 EntityRecord (io.spine.server.entity.EntityRecord)1 IntegrationEvent (io.spine.server.integration.IntegrationEvent)1 IntegrationEventContext (io.spine.server.integration.IntegrationEventContext)1