Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Buncher extends AbstractFSM<State, Data> {
- {
- startWith(Idle, Uninitialized);
- when(Idle,
- matchEvent(SetTarget.class, Uninitialized.class,
- (setTarget, uninitialized) ->
- stay().using(new Todo(setTarget.getRef(), new LinkedList<>()))));
- onTransition(
- matchState(Active, Idle, () -> {
- // reuse this matcher
- final UnitMatch<Data> m = UnitMatch.create(
- matchData(Todo.class,
- todo -> todo.getTarget().tell(new Batch(todo.getQueue()), getSelf())));
- m.match(stateData());
- }).
- state(Idle, Active, () -> {/* Do something here */}));
- when(Active, Duration.ofSeconds(1L),
- matchEvent(Arrays.asList(Flush.class, StateTimeout()), Todo.class,
- (event, todo) -> goTo(Idle).using(todo.copy(new LinkedList<>()))));
- whenUnhandled(
- matchEvent(Queue.class, Todo.class,
- (queue, todo) -> goTo(Active).using(todo.addElement(queue.getObj()))).
- anyEvent((event, state) -> {
- log().warning("received unhandled request {} in state {}/{}",
- event, stateName(), state);
- return stay();
- }));
- initialize();
- }
- }
Add Comment
Please, Sign In to add comment