use of io.spine.server.tenant.TenantAwareOperation in project core-java by SpineEventEngine.
the class EventStore method appendAll.
/**
* Appends the passed events to the history of events.
*
* <p>If the passed {@link Iterable} is empty, no action is performed.
*
* <p>If the passed {@linkplain Event Events} belong to the different
* {@linkplain TenantId tenants}, an {@link IllegalArgumentException} is thrown.
*
* @param events the events to append
*/
public void appendAll(final Iterable<Event> events) {
checkNotNull(events);
final Optional<Event> tenantDefiningEvent = tryFind(events, Predicates.<Event>notNull());
if (!tenantDefiningEvent.isPresent()) {
return;
}
final Event event = tenantDefiningEvent.get();
final TenantAwareOperation op = new EventOperation(event) {
@Override
public void run() {
if (isTenantSet()) {
// If multitenant context
ensureSameTenant(events);
}
store(events);
}
};
op.execute();
logStored(events);
}
use of io.spine.server.tenant.TenantAwareOperation in project core-java by SpineEventEngine.
the class Stand method subscribe.
/**
* Subscribes for all further changes of an entity state, which satisfies the {@link Topic}.
*
* <p>Once this instance of {@code Stand} receives an update of an entity
* with the given {@code TypeUrl}, all such callbacks are executed.
*
* @param topic an instance {@link Topic}, defining the entity and criteria,
* which changes should be propagated to the {@code callback}
*/
public void subscribe(final Topic topic, final StreamObserver<Subscription> responseObserver) {
topicValidator.validate(topic, responseObserver);
final TenantId tenantId = topic.getContext().getTenantId();
final TenantAwareOperation op = new TenantAwareOperation(tenantId) {
@Override
public void run() {
final Subscription subscription = subscriptionRegistry.add(topic);
responseObserver.onNext(subscription);
responseObserver.onCompleted();
}
};
op.execute();
}
use of io.spine.server.tenant.TenantAwareOperation in project core-java by SpineEventEngine.
the class CommandStore method updateStatus.
/**
* Updates the status of the command with the business failure.
* @param commandEnvelope the command to update
* @param failure the business failure occurred during command processing
*/
private void updateStatus(CommandEnvelope commandEnvelope, final Failure failure) {
keepTenantId(commandEnvelope.getCommand());
final TenantAwareOperation op = new Operation(this, commandEnvelope) {
@Override
public void run() {
storage.updateStatus(commandId(), failure);
}
};
op.execute();
}
use of io.spine.server.tenant.TenantAwareOperation in project core-java by SpineEventEngine.
the class RepositoryShould method createAndStoreEntities.
/**
* Creates three entities in the repository.
*/
private void createAndStoreEntities() {
final TenantAwareOperation op = new TenantAwareOperation(tenantId) {
@Override
public void run() {
repository.initStorage(storageFactory);
createAndStore("Eins");
createAndStore("Zwei");
createAndStore("Drei");
}
};
op.execute();
}
use of io.spine.server.tenant.TenantAwareOperation in project core-java by SpineEventEngine.
the class AggregateRepositoryShould method throw_ISE_if_unable_to_load_entity_by_id_from_storage_index.
@Test(expected = IllegalStateException.class)
public void throw_ISE_if_unable_to_load_entity_by_id_from_storage_index() {
// Store a valid aggregate.
givenStoredAggregate();
// Store a troublesome entity, which cannot be loaded.
final TenantAwareOperation op = new TenantAwareOperation(newUuid()) {
@Override
public void run() {
givenStoredAggregateWithId(ProjectAggregateRepository.troublesome.getId());
}
};
op.execute();
final Iterator<ProjectAggregate> iterator = repository.iterator(Predicates.<ProjectAggregate>alwaysTrue());
// This should iterate through all and fail.
Lists.newArrayList(iterator);
}
Aggregations