styx icon indicating copy to clipboard operation
styx copied to clipboard

Add timing capability to FSMs

Open mikkokar opened this issue 5 years ago • 0 comments

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 FlowControllerTimer class.
  • The FlowControllerTimer must not have any knowledge about FSM internal state such as:
        if (producer.state() != COMPLETED && producer.state() != TERMINATED) {
            resetTimerOrTearDownFlowController();
        }
  • The FlowControllerTimer should provide start, stop and restart methods.
  • A timer instance could be injected in the FlowControllingHttpContentProducer and the timer implementation should encapsulate any threading model etc away from the FSM.

mikkokar avatar Mar 31 '20 11:03 mikkokar