Overview

KStateMachine is a Kotlin DSL library for creating state machines and statecharts.

The library follows concepts from the following great and well known works and specs:

IntelliJ IDEA Plugin

KStateMachine Visual is an IntelliJ IDEA plugin that visualizes and navigates your state machines directly from Kotlin source.

Install from the JetBrains Marketplace or read the full plugin documentation.


Workflow

Building blocks (main interfaces) of the library:

  • StateMachine - is a collection of states and transitions between them, processes events when started
  • IState - states where state machine can go to
  • Transition - is an operation of moving from one state to another
  • Event - is a base interface for events which are processed by state machine and may trigger transitions

Working with state machine consists of two major sequential phases:

  1. Creation with initial setup and starting
  2. Processing events, on which state machine can switch its states and notify about changes
val machine = createStateMachine(scope) {
    // Setup is made in this block ...
}
// After setup and start, it is ready to process events
machine.processEvent(FirstEvent)
// ...
machine.processEvent(OtherEvent)

This site uses Just the Docs, a documentation theme for Jekyll.