Applying a new event from a polling thread.

Hello guys,

Once in a year, when a new ring appears inside of a tree, I create a treeChangedEvent, from inside a polling Thread (inside the Tree class).

public class Tree extends AbstractAnnotatedAggregateRoot {

@AggregateIdentifier
private int id;
private int years;

public Tree(int years) {

myApplyMethod(years);

}

private void myApplyMethod(int years) {

apply(new TreeYearsChangedEvent(this.id, years));

}

@EventSourcingHandler
private void on(TreeYearsChangedEvent event) {

this.years = event.getYears();

}

// Here I have some polling, that throws a TreeYearsChangedEvent, whenever a new year has passed, by calling the myApplyMethod from a new Thread

}

So after reading the documentation I am still not sure, what the easiest way is to “register” the new Thread properly is.
Is there a command that does that, or do I have to change my architecture?

Hi Stefan,

right now, the most common approach to work with time, is by using an EventScheduler. It schedules an event for publication at a specific date/time or after a specified duration. Usually, these events indicate the passing of a deadline, such as a payment deadline. A Saga would pick that up and send a command to e.g. an Invoice to have a reminder sent.
In your case, there could be a simple component that sends a command to all the (relevant) trees each year, to grow a new ring.

In future versions, we would like for aggregates to “plan” activities in a more direct way, without the intervention of an external component.

Hope this gives you a bit of direction.
Cheers,

Allard