Guest User

Untitled

a guest
Jun 14th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public class Buncher extends AbstractFSM<State, Data> {
  2. {
  3. startWith(Idle, Uninitialized);
  4.  
  5. when(Idle,
  6. matchEvent(SetTarget.class, Uninitialized.class,
  7. (setTarget, uninitialized) ->
  8. stay().using(new Todo(setTarget.getRef(), new LinkedList<>()))));
  9.  
  10. onTransition(
  11. matchState(Active, Idle, () -> {
  12. // reuse this matcher
  13. final UnitMatch<Data> m = UnitMatch.create(
  14. matchData(Todo.class,
  15. todo -> todo.getTarget().tell(new Batch(todo.getQueue()), getSelf())));
  16. m.match(stateData());
  17. }).
  18. state(Idle, Active, () -> {/* Do something here */}));
  19.  
  20. when(Active, Duration.ofSeconds(1L),
  21. matchEvent(Arrays.asList(Flush.class, StateTimeout()), Todo.class,
  22. (event, todo) -> goTo(Idle).using(todo.copy(new LinkedList<>()))));
  23.  
  24. whenUnhandled(
  25. matchEvent(Queue.class, Todo.class,
  26. (queue, todo) -> goTo(Active).using(todo.addElement(queue.getObj()))).
  27. anyEvent((event, state) -> {
  28. log().warning("received unhandled request {} in state {}/{}",
  29. event, stateName(), state);
  30. return stay();
  31. }));
  32.  
  33. initialize();
  34. }
  35. }
Add Comment
Please, Sign In to add comment