SessionState.java
package com.shengzhiai.yugu;
/**
* States of a {@link StreamSession}.
*
* <pre>
* IDLE -> CONNECTING -> CONNECTED (server "connected") -> STARTED (server "started")
* STARTED -> ENDING (end sent) -> COMPLETED (final result) -> CLOSED
* CONNECTING|CONNECTED|STARTED|ENDING -> RECONNECTING -> CONNECTING ...
* any non-terminal state -> FAILED -> CLOSED
* any non-terminal state -> CANCELLED -> CLOSED
* </pre>
*/
public enum SessionState {
/** Created, not connected yet. */
IDLE,
/** Opening the WebSocket. */
CONNECTING,
/** Server sent "connected", start frame sent. */
CONNECTED,
/** Server sent "started", audio flows. */
STARTED,
/** End frame sent, waiting for the final result. */
ENDING,
/** Connection lost, waiting to reconnect. */
RECONNECTING,
/** Final result delivered. */
COMPLETED,
/** Error delivered. */
FAILED,
/** Cancelled by the caller or by closing the client. */
CANCELLED,
/** Connection released; always the last state. */
CLOSED;
/** @return true for COMPLETED, FAILED, CANCELLED and CLOSED */
public boolean isTerminal() {
return this == COMPLETED || this == FAILED || this == CANCELLED || this == CLOSED;
}
}