Add timing capability to FSMs
Requirement
This Issue is a continuation (a second increment) to PR #560.
The Styx FSMs need a capability to trigger timed state transitions. To protect from being trapped indefinitely within a state, or to perform certain transitions in a repeated fashion.
A PR #560 demonstrates a use case. The FSM needs to detect a ByteStream subscriber inactivity. But it solved the problem by implementing a custom trimer for this purpose only. This timer is intimately tied to the particular FSM and cannot be reused for other uses.
We could use a generic timer also for detecting Netty channel inactivity. Currently we need an IdleStateHandler in a Netty pipeline that feeds an external event into a FlowControllingHttpContentProducer FSM. From design point of view it would be much simpler if the FlowControllingHttpContentProducer could detect this itself by timing the ContentChunkEvents.
Acceptance Criteria
- Remove all inactive subscriber related logic away from
FlowControllerTimerclass. - The
FlowControllerTimermust not have any knowledge about FSM internal state such as:
if (producer.state() != COMPLETED && producer.state() != TERMINATED) {
resetTimerOrTearDownFlowController();
}
- The
FlowControllerTimershould providestart,stopandrestartmethods. - A timer instance could be injected in the
FlowControllingHttpContentProducerand the timer implementation should encapsulate any threading model etc away from the FSM.