Search in sources :

Example 1 with CommandDispatcher

use of io.spine.server.commandbus.CommandDispatcher in project core-java by SpineEventEngine.

the class AbstractCommandRouterShould method setUp.

@Before
public void setUp() {
    final BoundedContext boundedContext = BoundedContext.newBuilder().build();
    final CommandBus commandBus = boundedContext.getCommandBus();
    // Register dispatcher for `StringValue` message type.
    // Otherwise we won't be able to post.
    commandBus.register(new CommandDispatcher() {

        @Override
        public Set<CommandClass> getMessageClasses() {
            return CommandClass.setOf(StringValue.class);
        }

        @Override
        public void dispatch(CommandEnvelope envelope) {
        // Do nothing.
        }
    });
    sourceMessage = Wrapper.forString(getClass().getSimpleName());
    sourceContext = requestFactory.createCommandContext();
    router = createRouter(commandBus, sourceMessage, sourceContext);
    router.addAll(messages);
}
Also used : Set(java.util.Set) CommandDispatcher(io.spine.server.commandbus.CommandDispatcher) CommandEnvelope(io.spine.envelope.CommandEnvelope) BoundedContext(io.spine.server.BoundedContext) CommandBus(io.spine.server.commandbus.CommandBus) StringValue(com.google.protobuf.StringValue) Before(org.junit.Before)

Example 2 with CommandDispatcher

use of io.spine.server.commandbus.CommandDispatcher in project core-java by SpineEventEngine.

the class BoundedContext method register.

/**
     * Registers the passed repository with the {@code BoundedContext}.
     *
     * <p>If the repository does not have a storage assigned, it will be initialized
     * using the {@code StorageFactory} associated with this bounded context.
     *
     * @param repository the repository to register
     * @param <I>        the type of IDs used in the repository
     * @param <E>        the type of entities or aggregates
     * @see Repository#initStorage(StorageFactory)
     */
@SuppressWarnings("ChainOfInstanceofChecks")
public <// OK here since ways of registering are way too different
I, E extends Entity<I, ?>> void register(Repository<I, E> repository) {
    checkStorageAssigned(repository);
    guard.register(repository);
    if (repository instanceof CommandDispatcher) {
        commandBus.register((CommandDispatcher) repository);
    }
    if (repository instanceof ProcessManagerRepository) {
        final ProcessManagerRepository procmanRepo = (ProcessManagerRepository) repository;
        commandBus.register(DelegatingCommandDispatcher.of(procmanRepo));
    }
    if (repository instanceof EventDispatcher) {
        eventBus.register((EventDispatcher) repository);
    }
    if (managesVersionableEntities(repository)) {
        stand.registerTypeSupplier(cast(repository));
    }
}
Also used : EventDispatcher(io.spine.server.event.EventDispatcher) ProcessManagerRepository(io.spine.server.procman.ProcessManagerRepository) DelegatingCommandDispatcher(io.spine.server.commandbus.DelegatingCommandDispatcher) CommandDispatcher(io.spine.server.commandbus.CommandDispatcher)

Example 3 with CommandDispatcher

use of io.spine.server.commandbus.CommandDispatcher in project core-java by SpineEventEngine.

the class MultiTenantCommandBusShould method unregister_command_dispatcher.

@Test
public void unregister_command_dispatcher() {
    final CommandDispatcher dispatcher = new AddTaskDispatcher();
    commandBus.register(dispatcher);
    commandBus.unregister(dispatcher);
    commandBus.post(addTask(), responseObserver);
    assertTrue(responseObserver.isError());
}
Also used : CommandDispatcher(io.spine.server.commandbus.CommandDispatcher) Test(org.junit.Test)

Example 4 with CommandDispatcher

use of io.spine.server.commandbus.CommandDispatcher in project core-java by SpineEventEngine.

the class ProcessManagerRepositoryShould method setUp.

@Override
@Before
public void setUp() {
    super.setUp();
    boundedContext = TestBoundedContextFactory.MultiTenant.newBoundedContext();
    boundedContext.getCommandBus().register(new CommandDispatcher() {

        @Override
        public Set<CommandClass> getMessageClasses() {
            return CommandClass.setOf(AddTask.class);
        }

        @Override
        public void dispatch(CommandEnvelope envelope) {
        /* Simply swallow the command. We need this dispatcher for allowing
                                 Process Manager under test to route the AddTask command. */
        }
    });
    repository = new TestProcessManagerRepository(boundedContext);
    repository.initStorage(storageFactory());
    TestProcessManager.clearMessageDeliveryHistory();
}
Also used : Set(java.util.Set) AddTask(io.spine.test.procman.command.AddTask) CommandDispatcher(io.spine.server.commandbus.CommandDispatcher) CommandEnvelope(io.spine.envelope.CommandEnvelope) Before(org.junit.Before)

Aggregations

CommandDispatcher (io.spine.server.commandbus.CommandDispatcher)4 CommandEnvelope (io.spine.envelope.CommandEnvelope)2 Set (java.util.Set)2 Before (org.junit.Before)2 StringValue (com.google.protobuf.StringValue)1 BoundedContext (io.spine.server.BoundedContext)1 CommandBus (io.spine.server.commandbus.CommandBus)1 DelegatingCommandDispatcher (io.spine.server.commandbus.DelegatingCommandDispatcher)1 EventDispatcher (io.spine.server.event.EventDispatcher)1 ProcessManagerRepository (io.spine.server.procman.ProcessManagerRepository)1 AddTask (io.spine.test.procman.command.AddTask)1 Test (org.junit.Test)1