Skip to content

Latest commit

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Build Status

Introduction

Stateful is a simple and lightweight event driven state machine library. With Stateful you can implement complex state dependant logic with a clean and simple design.

Installation

The project is built using Maven and the artifacts are available from Maven Central.

 <dependency>
<groupId>com.github.zevada</groupId>
<artifactId>stateful</artifactId>
<version>1.0.0</version>
</dependency>

Usage

Simple Transitions

enumState {
INIT, RUNNING, COMPLETED
}
enumEvent {
RUN, END
}
...
StateMachine<State, Event> stateMachine =
newStateMachineBuilder<State, Event>(State.INIT)
.addTransition(State.INIT, Event.RUN, State.RUNNING)
.addTransition(State.RUNNING, Event.END, State.COMPLETED)
.build();
stateMachine.getState(); // State.INITstateMachine.apply(Event.RUN);
stateMachine.getState(); // State.RUNNING

On State Enter/Exit Listeners

StateMachine<State, Event> stateMachine =
newStateMachineBuilder<State, Event>(State.INIT)
.addTransition(State.INIT, Event.RUN, State.RUNNING)
.onExit(State.INIT, () -> System.out.println("Exiting Init!"))
.onEnter(State.RUNNING, () -> System.out.println("Entering Running!"))
.build();
stateMachine.apply(Event.RUN);

About

A simple and lightweight event driven state machine library

Resources

Stars

22 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages