@ThreadSafe class StateMachineManager
A StateMachineManager is responsible for coordination and persistence of multiple ProtocolStateMachine objects. Each such object represents an instantiation of a (two-party) protocol that has reached a particular point.
An implementation of this class will persist state machines to long term storage so they can survive process restarts and, if run with a single-threaded executor, will ensure no two state machines run concurrently with each other (bad for performance, good for programmer mental health).
A "state machine" is a class with a single call method. The call method and any others it invokes are rewritten by a bytecode rewriting engine called Quasar, to ensure the code can be suspended and resumed at any point.
TODO: Session IDs should be set up and propagated automatically, on demand. TODO: Consider the issue of continuation identity more deeply: is it a safe assumption that a serialised continuation is always unique? TODO: Think about how to bring the system to a clean stop so it can be upgraded without any serialised stacks on disk TODO: Timeouts TODO: Surfacing of exceptions via an API and/or management UI TODO: Ability to control checkpointing explicitly, for cases where you know replaying a message cant hurt TODO: Make Kryo (de)serialize markers for heavy objects that are currently in the service hub. This avoids mistakes where services are temporarily put on the stack. TODO: Implement stub/skel classes that provide a basic RPC framework on top of this.
FiberRequest |
class FiberRequest |
SameThreadFiberScheduler |
object SameThreadFiberScheduler : FiberExecutorScheduler |
<init> |
StateMachineManager(serviceHub: ServiceHub, runInThread: Executor) A StateMachineManager is responsible for coordination and persistence of multiple ProtocolStateMachine objects. Each such object represents an instantiation of a (two-party) protocol that has reached a particular point. |
checkpointing |
val checkpointing: Boolean |
runInThread |
val runInThread: Executor |
serviceHub |
val serviceHub: ServiceHub |
add |
fun <T> add(loggerName: String, logic: ProtocolLogic<T>): ListenableFuture<T> Kicks off a brand new state machine of the given class. It will log with the named logger. The state machine will be persisted when it suspends, with automated restart if the StateMachineManager is restarted with checkpointed state machines in the storage service. |
findStateMachines |
fun <T> findStateMachines(klass: Class<out ProtocolLogic<T>>): List<Pair<ProtocolLogic<T>, ListenableFuture<T>>> Returns a list of all state machines executing the given protocol logic at the top level (subprotocols do not count) |