Examples of ToDoItemCreatedEvent


Examples of org.axonframework.quickstart.api.ToDoItemCreatedEvent

        // 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
View Full Code Here

Examples of org.axonframework.quickstart.api.ToDoItemCreatedEvent

    public ToDoItem() {
    }

    public ToDoItem(String id, String description) {
        apply(new ToDoItemCreatedEvent(id, description));
    }
View Full Code Here

Examples of org.axonframework.quickstart.api.ToDoItemCreatedEvent

    }

    @Override
    protected void handle(DomainEventMessage eventMessage) {
        if (eventMessage.getPayloadType().equals(ToDoItemCreatedEvent.class)) {
            ToDoItemCreatedEvent event = (ToDoItemCreatedEvent) eventMessage.getPayload();
            this.id = event.getTodoId();
        }
    }
View Full Code Here

Examples of org.axonframework.quickstart.api.ToDoItemCreatedEvent

        eventStore.setUpcasterChain(new LazyUpcasterChain(serializer,
                                                          Collections.<Upcaster>singletonList(new ToDoItemUpcaster())));

        // we append some events. Notice we append a "ToDoItemCreatedEvent".
        eventStore.appendEvents("UpcasterSample", new SimpleDomainEventStream(
                new GenericDomainEventMessage("todo1", 0, new ToDoItemCreatedEvent("todo1", "I need to do this today")),
                new GenericDomainEventMessage("todo1", 1, new ToDoItemCompletedEvent("todo1"))
        ));
        eventStore.appendEvents("UpcasterSample", new SimpleDomainEventStream(
                new GenericDomainEventMessage("todo2", 0, new ToDoItemCreatedEvent("todo2", "I also need to do this"))
        ));

        // now, we read the events from the "todo1" stream
        DomainEventStream eventStream = eventStore.readEvents("UpcasterSample", "todo1");
        while (eventStream.hasNext()) {
View Full Code Here

Examples of org.axonframework.quickstart.api.ToDoItemCreatedEvent

                                     });

        EventBus eventBus = applicationContext.getBean(EventBus.class);

        // 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
View Full Code Here

Examples of org.axonframework.quickstart.api.ToDoItemCreatedEvent

        AnnotationEventListenerAdapter.subscribe(new AnotherThreadPrintingEventListener(), eventBus);

        // we append some events to simulate a full event store
        final DomainEventMessage[] domainEventMessages = {
                new GenericDomainEventMessage<ToDoItemCreatedEvent>(
                        "todo1", 0, new ToDoItemCreatedEvent("todo1", "Need to do something")),
                new GenericDomainEventMessage<ToDoItemCreatedEvent>(
                        "todo2", 0, new ToDoItemCreatedEvent("todo2", "Another thing to do")),
                new GenericDomainEventMessage<ToDoItemCompletedEvent>("todo2", 0, new ToDoItemCompletedEvent("todo2"))
        };
        eventStore.appendEvents("mock", new SimpleDomainEventStream(domainEventMessages));

        // we create an executor service with a single thread and start the replay as an asynchronous process
        ExecutorService executor = Executors.newSingleThreadExecutor();
        Future<Void> future = replayingCluster.startReplay(executor);

        // we want to wait for the cluster to have switched to replay mode, so we can send some messages to it.
        // if we were to publish events right away, there is a big chance the Cluster didn't switch to replay mode, yet.
        waitForReplayToHaveStarted(replayingCluster);

        // this is a new event, so it should be backlogged and handled at the end of the replay
        eventBus.publish(asEventMessage(new ToDoItemCreatedEvent("todo3", "Came in just now...")));

        // this message is also part of the replay, and should therefore not be handled twice.
        eventBus.publish(domainEventMessages[2]);

        // we wait (at most 10 seconds) for the replay to complete.
View Full Code Here

Examples of org.axonframework.quickstart.api.ToDoItemCreatedEvent

        ReplayingCluster replayingCluster = applicationContext.getBean("cluster", ReplayingCluster.class);

        // we append some events to simulate a full event store
        final DomainEventMessage[] domainEventMessages = {
                new GenericDomainEventMessage<ToDoItemCreatedEvent>(
                        "todo1", 0, new ToDoItemCreatedEvent("todo1", "Need to do something")),
                new GenericDomainEventMessage<ToDoItemCreatedEvent>(
                        "todo2", 0, new ToDoItemCreatedEvent("todo2", "Another thing to do")),
                new GenericDomainEventMessage<ToDoItemCompletedEvent>("todo2", 0, new ToDoItemCompletedEvent("todo2"))
        };
        eventStore.appendEvents("mock", new SimpleDomainEventStream(domainEventMessages));

        // we get the executor service from the application context and start the replay as an asynchronous process
        Future<Void> future = replayingCluster.startReplay(executor);

        // we want to wait for the cluster to have switched to replay mode, so we can send some messages to it.
        // if we were to publish events right away, there is a big chance the Cluster didn't switch to replay mode, yet.
        waitForReplayToHaveStarted(replayingCluster);

        // this is a new event, so it should be backlogged and handled at the end of the replay
        eventBus.publish(asEventMessage(new ToDoItemCreatedEvent("todo3", "Came in just now...")));

        // this message is also part of the replay, and should therefore not be handled twice.
        eventBus.publish(domainEventMessages[2]);

        // we wait (at most 10 seconds) for the replay to complete.
View Full Code Here

Examples of org.axonframework.quickstart.api.ToDoItemCreatedEvent

        // we fetch the EventStore from the application context
        EventStore eventStore = applicationContext.getBean(EventStore.class);

        // we append some events. Notice we append a "ToDoItemCreatedEvent".
        eventStore.appendEvents("UpcasterSample", new SimpleDomainEventStream(
                new GenericDomainEventMessage("todo1", 0, new ToDoItemCreatedEvent("todo1", "I need to do this today")),
                new GenericDomainEventMessage("todo1", 1, new ToDoItemCompletedEvent("todo1"))
        ));
        eventStore.appendEvents("UpcasterSample", new SimpleDomainEventStream(
                new GenericDomainEventMessage("todo2", 0, new ToDoItemCreatedEvent("todo2", "I also need to do this"))
        ));


        // now, we read the events from the "todo1" stream
        DomainEventStream upcastEvents = eventStore.readEvents("UpcasterSample", "todo1");
View Full Code Here

Examples of org.axonframework.quickstart.api.ToDoItemCreatedEvent

public class ToDoEventListener implements EventListener {

    @Override
    public void handle(EventMessage eventMessage) {
        if (eventMessage.getPayloadType().equals(ToDoItemCreatedEvent.class)) {
            ToDoItemCreatedEvent event = (ToDoItemCreatedEvent) eventMessage.getPayload();
            System.out.println(String.format("We've got something to do: %s (%s)",
                                             event.getDescription(),
                                             event.getTodoId()));
        } else if (eventMessage.getPayloadType().equals(ToDoItemCompletedEvent.class)) {
            ToDoItemCompletedEvent event = (ToDoItemCompletedEvent) eventMessage.getPayload();
            System.out.println(String.format("We've completed the task with id %s", event.getTodoId()));
        }
    }
View Full Code Here

Examples of org.axonframework.quickstart.api.ToDoItemCreatedEvent

    public ToDoItem() {
    }

    @CommandHandler
    public ToDoItem(CreateToDoItemCommand command) {
        apply(new ToDoItemCreatedEvent(command.getTodoId(), command.getDescription()));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.