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);
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations