Created
June 12, 2018 07:13
-
-
Save sebastienvermeille/701ae50782f547ca6f0e49bcbc14fa25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment