Search in sources :

Example 1 with TenantAwareOperation

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();
}
Also used : CommandOperation(io.spine.server.tenant.CommandOperation) TenantAwareOperation(io.spine.server.tenant.TenantAwareOperation) TenantAwareOperation(io.spine.server.tenant.TenantAwareOperation)

Example 2 with TenantAwareOperation

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();
}
Also used : Command(io.spine.base.Command) TenantAwareFunction0(io.spine.server.tenant.TenantAwareFunction0) Iterator(java.util.Iterator) TenantAwareOperation(io.spine.server.tenant.TenantAwareOperation)

Example 3 with TenantAwareOperation

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();
}
Also used : TenantId(io.spine.users.TenantId) Subscription(io.spine.client.Subscription) TenantAwareOperation(io.spine.server.tenant.TenantAwareOperation)

Example 4 with TenantAwareOperation

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);
}
Also used : EventOperation(io.spine.server.tenant.EventOperation) TenantAwareOperation(io.spine.server.tenant.TenantAwareOperation)

Example 5 with TenantAwareOperation

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));
}
Also used : TenantId(io.spine.users.TenantId) TenantAwareOperation(io.spine.server.tenant.TenantAwareOperation) Test(org.junit.Test)

Aggregations

TenantAwareOperation (io.spine.server.tenant.TenantAwareOperation)15 CommandOperation (io.spine.server.tenant.CommandOperation)6 Test (org.junit.Test)5 TenantId (io.spine.users.TenantId)4 Command (io.spine.base.Command)1 Subscription (io.spine.client.Subscription)1 EventOperation (io.spine.server.tenant.EventOperation)1 TenantAwareFunction0 (io.spine.server.tenant.TenantAwareFunction0)1 Iterator (java.util.Iterator)1