use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class ProjectionRepository method catchUp.
/**
* Updates projections from the event stream obtained from {@code EventStore}.
*/
public void catchUp() {
setStatus(Status.CATCHING_UP);
final AllTenantOperation op = new AllTenantOperation(boundedContext.getTenantIndex()) {
private final EventStore eventStore = getBoundedContext().getEventBus().getEventStore();
private final Set<EventFilter> eventFilters = getEventFilters();
@Override
public void run() {
// Get the timestamp of the last event. This also ensures we have the storage.
final Timestamp timestamp = nullToDefault(projectionStorage().readLastHandledEventTime());
final EventStreamQuery query = EventStreamQuery.newBuilder().setAfter(timestamp).addAllFilter(eventFilters).build();
eventStore.read(query, new EventStreamObserver(ProjectionRepository.this));
}
};
op.execute();
completeCatchUp();
logCatchUpComplete();
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class ProjectionRepository method dispatchToEntity.
@Override
protected void dispatchToEntity(I id, Message eventMessage, EventContext context) {
final P projection = findOrCreate(id);
final ProjectionTransaction<I, ?, ?> tx = ProjectionTransaction.start((Projection<I, ?, ?>) projection);
projection.handle(eventMessage, context);
tx.commit();
if (projection.isChanged()) {
final Timestamp eventTime = context.getTimestamp();
if (isBulkWriteInProgress()) {
storePostponed(projection, eventTime);
} else {
storeNow(projection, eventTime);
}
stand.post(projection, context.getCommandContext());
}
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class BulkWriteOperationShould method store_given_projections_in_memory.
@SuppressWarnings("MethodWithMultipleLoops")
@Test
public void store_given_projections_in_memory() {
final int projectionsCount = 5;
final Set<TestProjection> projections = new HashSet<>(projectionsCount);
for (int i = 0; i < projectionsCount; i++) {
projections.add(new TestProjection(i));
}
final Timestamp whenHandled = Timestamp.getDefaultInstance();
final BulkWriteOperation<Object, TestProjection> operation = newOperation(projections, whenHandled);
assertTrue(operation.isInProgress());
for (TestProjection projection : projections) {
operation.storeProjection(projection);
}
operation.complete();
assertFalse(operation.isInProgress());
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class BulkWriteOperationShould method store_the_very_last_timestamp_only.
@Test
public void store_the_very_last_timestamp_only() {
final Set<TestProjection> projections = emptySet();
final Timestamp firstEvent = TimeTests.Past.secondsAgo(5L);
final Timestamp secondEvent = TimeTests.Past.secondsAgo(5L);
final Timestamp lastEvent = TimeTests.Past.secondsAgo(5L);
final BulkWriteOperation<Object, TestProjection> operation = newOperation(projections, lastEvent);
assertTrue(operation.isInProgress());
operation.storeLastHandledEventTime(firstEvent);
operation.storeLastHandledEventTime(secondEvent);
operation.storeLastHandledEventTime(lastEvent);
operation.complete();
assertFalse(operation.isInProgress());
}
use of com.google.protobuf.Timestamp in project core-java by SpineEventEngine.
the class MessageFieldValidator method validateTimestamps.
private void validateTimestamps() {
final Time when = timeOption.getIn();
if (when == TIME_UNDEFINED) {
return;
}
final Timestamp now = getCurrentTime();
for (Message value : getValues()) {
final Timestamp time = (Timestamp) value;
if (isTimeInvalid(time, when, now)) {
addViolation(newTimeViolation(time));
// return because one error message is enough for the "time" option
return;
}
}
}
Aggregations