use of io.spine.server.tenant.TenantAwareOperation in project core-java by SpineEventEngine.
the class CommandStore method store.
/**
* Stores a command with the given status.
*
* @param command a command to store
* @param status a command status
*/
public void store(final Command command, final CommandStatus status) {
keepTenantId(command);
final TenantAwareOperation op = new Operation(this, command) {
@Override
public void run() {
storage.store(command, status);
}
};
op.execute();
}
use of io.spine.server.tenant.TenantAwareOperation in project core-java by SpineEventEngine.
the class Rescheduler method rescheduleForTenant.
private void rescheduleForTenant(final TenantId tenantId) {
final TenantAwareFunction0<Iterator<Command>> func = new TenantAwareFunction0<Iterator<Command>>(tenantId) {
@Override
public Iterator<Command> apply() {
return commandStore().iterator(SCHEDULED);
}
};
final Iterator<Command> commands = func.execute(Empty.getDefaultInstance());
final TenantAwareOperation op = new TenantAwareOperation(tenantId) {
@Override
public void run() {
while (commands.hasNext()) {
final Command command = commands.next();
reschedule(command);
}
}
};
op.execute();
}
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 EventStore method append.
/**
* Appends the passed event to the history of events.
*
* @param event the record to append
*/
public void append(final Event event) {
final TenantAwareOperation op = new EventOperation(event) {
@Override
public void run() {
store(event);
}
};
op.execute();
logStored(event);
}
use of io.spine.server.tenant.TenantAwareOperation in project core-java by SpineEventEngine.
the class TenantAwareOperationShould method create_instance_for_non_command_execution_context.
@Test
public void create_instance_for_non_command_execution_context() {
final TenantId tenant = newTenantUuid();
CurrentTenant.set(tenant);
final TenantAwareOperation op = createOperation();
assertEquals(tenant, op.tenantId());
op.execute();
assertEquals(tenant, getTenantFromRun(op));
}
Aggregations