Package org.axonframework.eventhandling

Examples of org.axonframework.eventhandling.SimpleEventBus


    public static void main(String[] args) throws InterruptedException {
        // we'll store Events on the FileSystem, in the "events" folder
        EventStore eventStore = new FileSystemEventStore(new SimpleEventFileResolver(new File("./events")));

        // a Simple Event Bus will do
        EventBus eventBus = new SimpleEventBus();

        // we register the event handlers
        AnnotationEventListenerAdapter.subscribe(new ToDoEventHandler(), eventBus);

        // we use default settings for the disruptor command bus
View Full Code Here


    @SuppressWarnings("unchecked")
    public static void main(String[] args) throws InterruptedException {

        // first of all, we need an Event Bus
        EventBus eventBus = new SimpleEventBus();

        // Sagas often need to send commands, so let's create a Command Bus
        CommandBus commandBus = new SimpleCommandBus();

        // a CommandGateway has a much nicer API
        CommandGateway commandGateway = new DefaultCommandGateway(commandBus);

        // let's register a Command Handler that writes to System Out so we can see what happens
        commandBus.subscribe(MarkToDoItemOverdueCommand.class.getName(),
                new CommandHandler<MarkToDoItemOverdueCommand>() {
                    @Override
                    public Object handle(CommandMessage<MarkToDoItemOverdueCommand> commandMessage,
                                         UnitOfWork unitOfWork) throws Throwable {
                        System.out.println(String.format("Got command to mark [%s] overdue!",
                                commandMessage.getPayload().getTodoId()));
                        return null;
                    }
                });

        // The Saga will schedule some deadlines in our sample
        final ScheduledExecutorService executorService = newSingleThreadScheduledExecutor();
        EventScheduler eventScheduler = new SimpleEventScheduler(executorService, eventBus);

        // we need to store a Saga somewhere. Let's do that in memory for now
        InMemorySagaRepository sagaRepository = new InMemorySagaRepository();

        // we want to inject resources in our Saga, so we need to tweak the GenericSagaFactory
        GenericSagaFactory sagaFactory = new GenericSagaFactory();
        // this will allow the eventScheduler and commandGateway to be injected in our Saga
        sagaFactory.setResourceInjector(new SimpleResourceInjector(eventScheduler, commandGateway));

        // Sagas instances are managed and tracked by a SagaManager.
        AnnotatedSagaManager sagaManager = new AnnotatedSagaManager(sagaRepository, sagaFactory,
                eventBus, ToDoSaga.class);

        // and we need to subscribe the Saga Manager to the Event Bus
        sagaManager.subscribe();

        // That's the infrastructure we need...
        // Let's pretend a few things are happening

        // We create 2 items
        eventBus.publish(asEventMessage(new ToDoItemCreatedEvent("todo1", "Got something to do")));
        eventBus.publish(asEventMessage(new ToDoItemCreatedEvent("todo2", "Got something else to do")));
        // We mark the first completed, before the deadline expires. The Saga has a hard-coded deadline of 2 seconds
        eventBus.publish(asEventMessage(new ToDoItemCompletedEvent("todo1")));
        // we wait 3 seconds. Enough time for the deadline to expire
        Thread.sleep(3000);
        // Just a System out to remind us that we should see something
        System.out.println("Should have seen an item marked overdue, now");
View Full Code Here

        // we'll store Events on the FileSystem, in the "events" folder
        EventStore eventStore = new FileSystemEventStore(new SimpleEventFileResolver(new File("./events")));

        // a Simple Event Bus will do
        EventBus eventBus = new SimpleEventBus();

        // we need to configure the repository
        EventSourcingRepository<ToDoItem> repository = new EventSourcingRepository<ToDoItem>(ToDoItem.class,
                                                                                             eventStore);
        repository.setEventBus(eventBus);
View Full Code Here

    private String identifier;

    @Before
    public void setUp() throws Exception {
        commandBus = new RecordingCommandBus();
        eventBus = new SimpleEventBus();
        eventScheduler = new StubEventScheduler();
        sagaRepository = new InMemorySagaRepository();
        testSubject = new FixtureExecutionResultImpl(sagaRepository, eventScheduler, eventBus,
                                                     commandBus, StubSaga.class);
        testSubject.startRecording();
View Full Code Here

    private UnitOfWorkFactory uowFactory;
    private EventBus eventBus;

    @Before
    public void setUp() throws Exception {
        eventBus = new SimpleEventBus();
        uowFactory = new DefaultUnitOfWorkFactory();
    }
View Full Code Here

    @Before
    public void setUp() throws Exception {
        while (CurrentUnitOfWork.isStarted()) {
            CurrentUnitOfWork.get().rollback();
        }
        eventBus = new SimpleEventBus();
        eventListener = mock(EventListener.class);
        eventBus.subscribe(eventListener);
    }
View Full Code Here

        // we'll store Events on the FileSystem, in the "events" folder
        EventStore eventStore = new FileSystemEventStore(new SimpleEventFileResolver(new File("./events")));

        // a Simple Event Bus will do
        EventBus eventBus = new SimpleEventBus();

        // we need to configure the repository
        EventSourcingRepository<ToDoItem> repository = new EventSourcingRepository<ToDoItem>(ToDoItem.class, eventStore);
        repository.setEventBus(eventBus);

        // Register the Command Handlers with the command bus by subscribing to the name of the command
        commandBus.subscribe(CreateToDoItemCommand.class.getName(),
                new CreateToDoCommandHandler(repository));
        commandBus.subscribe(MarkCompletedCommand.class.getName(),
                new MarkCompletedCommandHandler(repository));

        // We register an event listener to see which events are created
        eventBus.subscribe(new ToDoEventListener());

        // and let's send some Commands on the CommandBus using the special runner configured with our CommandGateway.
        CommandGenerator.sendCommands(commandGateway);
    }
View Full Code Here

    @Before
    public void setUp() throws Exception {
        CorrelationDataHolder.clear();
        sagaRepository = spy(new InMemorySagaRepository());
        manager = new AnnotatedSagaManager(sagaRepository, new SimpleEventBus(), MyTestSaga.class);
    }
View Full Code Here

        assertEquals(0, repositoryContents("12", MyTestSaga.class).size());
    }

    @Test
    public void testSagaTypeTakenIntoConsiderationWhenCheckingForSagasInCreation() throws InterruptedException {
        manager = new AnnotatedSagaManager(sagaRepository, new SimpleEventBus(),
                                           MyOtherTestSaga.class, MyTestSaga.class);

        ExecutorService executorService = Executors.newFixedThreadPool(8);
        for (int i = 0; i < 100; i++) {
            executorService.execute(new HandleEventTask(
View Full Code Here

    @Test
    public void testRegisterBeanTwice()
            throws MalformedObjectNameException, InterruptedException, MBeanRegistrationException,
                   InstanceAlreadyExistsException, NotCompliantMBeanException {
        SimpleEventBus sb = new SimpleEventBus();
        SimpleEventBus sb2 = new SimpleEventBus();

        MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
        Set<ObjectName> mbeans = mBeanServer.queryNames(new ObjectName("org.axonframework", "type", "Simple*"), null);
        assertTrue(mbeans.contains(new ObjectName("org.axonframework", "type", "SimpleEventBus")));
        assertTrue(mbeans.contains(new ObjectName("org.axonframework", "type", "SimpleEventBus_1")));
View Full Code Here

TOP

Related Classes of org.axonframework.eventhandling.SimpleEventBus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.