daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Jun 14th, 2018 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top