Search in sources :

Example 56 with Event

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

the class AggregateStorage method writeEvent.

/**
 * Writes an event to the storage by an aggregate ID.
 *
 * <p>Before the storing, {@linkplain io.spine.core.Events#clearEnrichments(Event) enrichments}
 * will be removed from the event.
 *
 * @param id    the aggregate ID
 * @param event the event to write
 */
void writeEvent(I id, Event event) {
    checkNotClosedAndArguments(id, event);
    final Event eventWithoutEnrichments = clearEnrichments(event);
    final AggregateEventRecord record = toStorageRecord(eventWithoutEnrichments);
    writeRecord(id, record);
}
Also used : Event(io.spine.core.Event)

Example 57 with Event

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

the class EventPlayingEntity method play.

/**
 * Plays the given events upon this entity.
 *
 * <p>Please note that the entity version is set according to the version of the event context.
 * Therefore, if the passed event(s) are in fact so called "integration" events and originated
 * from another application, they should be properly imported first.
 * Otherwise, the version conflict is possible.
 *
 * <p>Execution of this method requires the {@linkplain #isTransactionInProgress()
 * presence of active transaction}.
 *
 * @param events the events to play
 */
protected void play(Iterable<Event> events) {
    final Transaction<I, ? extends EventPlayingEntity<I, S, B>, S, B> tx = tx();
    for (Event event : events) {
        final EventEnvelope eventEnvelope = EventEnvelope.of(event);
        tx.apply(eventEnvelope);
    }
}
Also used : EventEnvelope(io.spine.core.EventEnvelope) Event(io.spine.core.Event)

Example 58 with Event

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

the class DelegatingEventDispatcher method asEventEnvelope.

private static EventEnvelope asEventEnvelope(ExternalMessageEnvelope envelope) {
    final ExternalMessage externalMessage = envelope.getOuterObject();
    final Event event = unpack(externalMessage.getOriginalMessage());
    return EventEnvelope.of(event);
}
Also used : Event(io.spine.core.Event) ExternalMessage(io.spine.server.integration.ExternalMessage)

Example 59 with Event

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

the class ERepository method iterator.

Iterator<Event> iterator(EventStreamQuery query) {
    checkNotNull(query);
    final EntityFilters filters = toEntityFilters(query);
    final Iterator<EEntity> entities = find(filters, FieldMask.getDefaultInstance());
    // A predicate on the Event message and EventContext fields.
    final Predicate<EEntity> detailedLookupFilter = createEntityFilter(query);
    final Iterator<EEntity> filtered = filter(entities, detailedLookupFilter);
    final List<EEntity> entityList = newArrayList(filtered);
    sort(entityList, comparator());
    final Iterator<Event> result = transform(entityList.iterator(), getEvent());
    return result;
}
Also used : EntityFilters(io.spine.client.EntityFilters) Event(io.spine.core.Event)

Example 60 with Event

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

the class EventFactory method createEvent.

/**
 * Creates a new {@code Event} instance.
 *
 * @param id           the ID of the event
 * @param messageOrAny the event message or {@code Any} containing the message
 * @param context      the event context
 * @return created event instance
 */
private static Event createEvent(EventId id, Message messageOrAny, EventContext context) {
    checkNotNull(messageOrAny);
    checkNotNull(context);
    final Any packed = pack(messageOrAny);
    final Event result = Event.newBuilder().setId(id).setMessage(packed).setContext(context).build();
    return result;
}
Also used : Event(io.spine.core.Event) IntegrationEvent(io.spine.server.integration.IntegrationEvent) TypeConverter.toAny(io.spine.protobuf.TypeConverter.toAny) Any(com.google.protobuf.Any)

Aggregations

Event (io.spine.core.Event)115 Test (org.junit.Test)75 Command (io.spine.core.Command)19 EventContext (io.spine.core.EventContext)12 BoundedContext (io.spine.server.BoundedContext)12 GivenEvent (io.spine.server.event.given.EventBusTestEnv.GivenEvent)12 Version (io.spine.core.Version)10 TestEventFactory (io.spine.server.command.TestEventFactory)10 Message (com.google.protobuf.Message)9 EventEnvelope (io.spine.core.EventEnvelope)9 InMemoryTransportFactory (io.spine.server.integration.memory.InMemoryTransportFactory)9 Timestamp (com.google.protobuf.Timestamp)6 Ack (io.spine.core.Ack)6 TenantId (io.spine.core.TenantId)6 Error (io.spine.base.Error)5 AggregateMessageDispatcher.dispatchCommand (io.spine.server.aggregate.AggregateMessageDispatcher.dispatchCommand)5 AggregateTestEnv.newTenantId (io.spine.server.aggregate.given.aggregate.AggregateTestEnv.newTenantId)5 StringValue (com.google.protobuf.StringValue)4 GivenEvent (io.spine.core.given.GivenEvent)4 Duration (com.google.protobuf.Duration)3