use of io.spine.core.Event in project core-java by SpineEventEngine.
the class StorageRecord method create.
public static AggregateEventRecord create(Timestamp timestamp) {
final Message eventMessage = Sample.messageOfType(AggProjectCreated.class);
final Event event = eventFactory.createEvent(eventMessage);
final AggregateEventRecord.Builder builder = AggregateEventRecord.newBuilder().setTimestamp(timestamp).setEvent(event);
return builder.build();
}
use of io.spine.core.Event in project core-java by SpineEventEngine.
the class StorageRecords method sequenceFor.
/**
* Returns several records sorted by timestamp ascending.
*
* @param start the timestamp of first record.
*/
public static List<AggregateEventRecord> sequenceFor(ProjectId id, Timestamp start) {
final Duration delta = seconds(10);
final Timestamp timestamp2 = add(start, delta);
final Timestamp timestamp3 = add(timestamp2, delta);
final TestEventFactory eventFactory = newInstance(Given.class);
final Event e1 = eventFactory.createEvent(projectCreated(id, Given.projectName(id)), null, start);
final AggregateEventRecord record1 = StorageRecord.create(start, e1);
final Event e2 = eventFactory.createEvent(taskAdded(id), null, timestamp2);
final AggregateEventRecord record2 = StorageRecord.create(timestamp2, e2);
final Event e3 = eventFactory.createEvent(Given.EventMessage.projectStarted(id), null, timestamp3);
final AggregateEventRecord record3 = StorageRecord.create(timestamp3, e3);
return newArrayList(record1, record2, record3);
}
use of io.spine.core.Event in project core-java by SpineEventEngine.
the class BoundedContext method notify.
/**
* Sends an integration event to this {@code BoundedContext}.
*/
@Experimental
@Override
public void notify(IntegrationEvent integrationEvent, StreamObserver<Ack> observer) {
final Event event = EventFactory.toEvent(integrationEvent);
eventBus.post(event, observer);
}
use of io.spine.core.Event in project core-java by SpineEventEngine.
the class Aggregate method ensureEventMessage.
/**
* Ensures that an event applier gets an instance of an event message,
* not {@link Event}.
*
* <p>Instances of {@code Event} may be passed to an applier during
* importing events or processing integration events. This may happen because
* corresponding command handling method returned either {@code List<Event>}
* or {@code Event}.
*
* @param eventOrMsg an event message or {@code Event}
* @return the passed instance or an event message extracted from the passed
* {@code Event} instance
*/
private static Message ensureEventMessage(Message eventOrMsg) {
final Message eventMsg;
if (eventOrMsg instanceof Event) {
final Event event = (Event) eventOrMsg;
eventMsg = getMessage(event);
} else {
eventMsg = eventOrMsg;
}
return eventMsg;
}
use of io.spine.core.Event in project core-java by SpineEventEngine.
the class AggregateRepository method store.
/**
* Stores the passed aggregate and commits its uncommitted events.
*
* @param aggregate an instance to store
*/
@Override
protected void store(A aggregate) {
final I id = aggregate.getId();
final int snapshotTrigger = getSnapshotTrigger();
final AggregateStorage<I> storage = aggregateStorage();
int eventCount = storage.readEventCountAfterLastSnapshot(id);
final Iterable<Event> uncommittedEvents = aggregate.getUncommittedEvents();
for (Event event : uncommittedEvents) {
storage.writeEvent(id, event);
++eventCount;
if (eventCount >= snapshotTrigger) {
final Snapshot snapshot = aggregate.toShapshot();
aggregate.clearRecentHistory();
storage.writeSnapshot(id, snapshot);
eventCount = 0;
}
}
aggregate.commitEvents();
storage.writeEventCountAfterLastSnapshot(id, eventCount);
if (aggregate.lifecycleFlagsChanged()) {
storage.writeLifecycleFlags(aggregate.getId(), aggregate.getLifecycleFlags());
}
}
Aggregations