Java based state machine