Package org.apache.coyote

# Class AsyncStateMachine

java.lang.Object
org.apache.coyote.AsyncStateMachine

public class AsyncStateMachine extends Object
Manages the state transitions for async requests.

     The internal states that are used are:
     DISPATCHED       - Standard request. Not in Async mode.
     STARTING         - ServletRequest.startAsync() has been called from
                        Servlet.service() but service() has not exited.
     STARTED          - ServletRequest.startAsync() has been called from
                        Servlet.service() and service() has exited.
     READ_WRITE_OP    - Performing an asynchronous read or write.
     MUST_COMPLETE    - ServletRequest.startAsync() followed by complete() have
                        been called during a single Servlet.service() method. The
                        complete() will be processed as soon as Servlet.service()
                        exits.
     COMPLETE_PENDING - ServletRequest.startAsync() has been called from
                        Servlet.service() but, before service() exited, complete()
                        was called from another thread. The complete() will
                        be processed as soon as Servlet.service() exits.
     COMPLETING       - The call to complete() was made once the request was in
                        the STARTED state.
     TIMING_OUT       - The async request has timed out and is waiting for a call
                        to complete() or dispatch(). If that isn't made, the error
                        state will be entered.
     MUST_DISPATCH    - ServletRequest.startAsync() followed by dispatch() have
                        been called during a single Servlet.service() method. The
                        dispatch() will be processed as soon as Servlet.service()
                        exits.
     DISPATCH_PENDING - ServletRequest.startAsync() has been called from
                        Servlet.service() but, before service() exited, dispatch()
                        was called from another thread. The dispatch() will
                        be processed as soon as Servlet.service() exits.
     DISPATCHING      - The dispatch is being processed.
     MUST_ERROR       - ServletRequest.startAsync() has been called from
                        Servlet.service() but, before service() exited, an I/O
                        error occurred on another thread. The container will
                        perform the necessary error handling when
                        Servlet.service() exits.
     ERROR            - Something went wrong.

     The valid state transitions are:

                      post()                                        dispatched()
        |-------»------------------»---------|    |-------«-----------------------«-----|
        |                                    |    |                                     |
        |                                    |    |        post()                       |
        |               post()              \|/  \|/       dispatched()                 |
        |           |-----»----------------»DISPATCHED«-------------«-------------|     |
        |           |                          | /|\ |                            |     |
        |           |              startAsync()|  |--|timeout()                   |     |
        ^           |                          |                                  |     |
        |           |        complete()        |                  dispatch()      ^     |
        |           |   |--«---------------«-- | ---«--MUST_ERROR--»-----|        |     |
        |           |   |                      |         /|\             |        |     |
        |           ^   |                      |          |              |        |     |
        |           |   |                      |    /-----|error()       |        |     |
        |           |   |                      |   /                     |        ^     |
        |           |  \|/  ST-complete()     \|/ /   ST-dispatch()     \|/       |     |
        |    MUST_COMPLETE«--------«--------STARTING--------»---------»MUST_DISPATCH    |
        |                                    / | \                                      |
        |                                   /  |  \                                     |
        |                    OT-complete() /   |   \    OT-dispatch()                   |
        |   COMPLETE_PENDING«------«------/    |    \-------»---------»DISPATCH_PENDING |
        |        |      /|\                    |                       /|\ |            |
        |        |       |                     |                        |  |post()      |
        |        |       |OT-complete()        |           OT-dispatch()|  |            |
        |        |       |---------«-------«---|---«--\                 |  |            |
        |        |                             |       \                |  |            |
        |        |         /-------«-------«-- | --«---READ_WRITE--»----|  |            |
        |        |        / ST-complete()      |        /  /|\  \          |            |
        |        |       /                     | post()/   /     \         |            |
        |        |      /                      |      /   /       \        |            |
        |        |     /                       |     /   /         \       |            |
        |        |    /                        |    /   /           \      |            |
        |        |   /                         |   |   /             \     |            |
        |        |  /                          |   |  /  ST-dispatch()\    |            |
        |        |  |                          |   | |                 \   |            |
        |  post()|  |  timeout()         post()|   | |asyncOperation()  \  |  timeout() |
        |        |  |  |--|                    |   | |                  |  |    |--|    |
        |       \|/\|/\|/ |     complete()    \|/ \|/|   dispatch()    \|/\|/  \|/ |    |
        |--«-----COMPLETING«--------«----------STARTED--------»---------»DISPATCHING----|
                /|\  /|\                       | /|\ |                       /|\ /|\
                 |    |                        |  |--|                        |   |
                 |    |               timeout()|  post()                      |   |
                 |    |                        |                              |   |
                 |    |       complete()      \|/         dispatch()          |   |
                 |    |------------«-------TIMING_OUT--------»----------------|   |
                 |                                                                |
                 |            complete()                     dispatch()           |
                 |---------------«-----------ERROR--------------»-----------------|

     Notes: * For clarity, the transitions to ERROR which are valid from every state apart from
              STARTING are not shown.
            * All transitions may happen on either the Servlet.service() thread (ST) or on any
              other thread (OT) unless explicitly marked.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AsyncStateMachine(AbstractProcessor processor)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `asyncComplete()`
  `boolean`
  `asyncDispatch()`
  `void`
  `asyncDispatched()`
  `boolean`
  `asyncError()`
  `void`
  `asyncOperation()`
  `AbstractEndpoint.Handler.SocketState`
  `asyncPostProcess()`
  `void`
  `asyncRun(Runnable runnable)`
  `void`
  `asyncStart(AsyncContextCallback asyncCtxt)`
  `boolean`
  `asyncTimeout()`
  `long`
  `getLastAsyncStart()`
  Obtain the time that this connection last transitioned to async processing.
  `boolean`
  `isAsync()`
  `boolean`
  `isAsyncDispatching()`
  `boolean`
  `isAsyncError()`
  `boolean`
  `isAsyncStarted()`
  `boolean`
  `isAsyncTimingOut()`
  `boolean`
  `isCompleting()`
  `void`
  `recycle()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### AsyncStateMachine

    public AsyncStateMachine(AbstractProcessor processor)

- ## Method Details

  - ### isAsync

    public boolean isAsync()

  - ### isAsyncDispatching

    public boolean isAsyncDispatching()

  - ### isAsyncStarted

    public boolean isAsyncStarted()

  - ### isAsyncTimingOut

    public boolean isAsyncTimingOut()

  - ### isAsyncError

    public boolean isAsyncError()

  - ### isCompleting

    public boolean isCompleting()

  - ### getLastAsyncStart

    public long getLastAsyncStart()
    Obtain the time that this connection last transitioned to async processing.
    Returns:
      The time (as returned by `System.currentTimeMillis()`) that this connection last transitioned to async

  - ### asyncStart

    public void asyncStart(AsyncContextCallback asyncCtxt)

  - ### asyncOperation

    public void asyncOperation()

  - ### asyncPostProcess

    public AbstractEndpoint.Handler.SocketState asyncPostProcess()

  - ### asyncComplete

    public boolean asyncComplete()

  - ### asyncTimeout

    public boolean asyncTimeout()

  - ### asyncDispatch

    public boolean asyncDispatch()

  - ### asyncDispatched

    public void asyncDispatched()

  - ### asyncError

    public boolean asyncError()

  - ### asyncRun

    public void asyncRun(Runnable runnable)

  - ### recycle

    public void recycle()