public interface AppLibLifecycleListener
Listener to get notifications about lifecycle state changes for an AppLib
instance. AppLib attempts to connect to a local SCAMPI router
instance over TCP. Once TCP has connected and the API protocol handshake
has completed, onConnected(java.lang.String)
will be called. If the API link drops,
e.g., due to the SCAMPI router shutting down, onDisconnected()
will
be called. The lifecycle state diagram is shown below.
+-------------+ | NEW | +-------------+ | | start() V +--------------+ +----| IDLE |<---+<-----+ | +--------------+ | | | | | | | connect() | onConnectFailed | V | | +--------------+ | | stop() +<---| CONNECTING |----+ | | +--------------+ | | | | onDisconnected | | onConnected | | V | | +-------------+ | | | CONNECTED |------------+ | +-------------+ | | | | stop() | V | +--------------+ +--->| STOPPING | +--------------+ | | onStopped V *=================* || TERMINATED || *=================*
The listener methods are invoked from a dedicated, single thread and will
not block the AppLib
(although will block other listeners). Therefore
there is no guarantee what the lifecycle state of the AppLib
will
be at the time of invocation, since the state may have changed while the
listeners are being called. In particular, while executing onConnected(java.lang.String)
, the AppLib
instance may already have entered the
IDLE
state (onDisconnected()
calls will be executed after
all the onConnected
calls have finished executing).
AppLib
methods (e.g.,
AppLib.publish(SCAMPIMessage,
String)
)
can be called in NEW
, IDLE
, CONNECTING
and
CONNECTED
states.
AppLib
will take care of buffering the calls if they cannot be
passed to the API server immediately (e.g., due to being in IDLE
state).
Modifier and Type | Method and Description |
---|---|
void |
onConnected(java.lang.String scampiId)
AppLib has connected to the API server.
|
void |
onConnectFailed()
Attempt to connect to a local API server has failed.
|
void |
onDisconnected()
AppLib has disconnected from the API server.
|
void |
onStopped()
AppLib has stopped.
|
void onConnected(java.lang.String scampiId)
scampiId
- identity of the Scampi instance that the API connected tovoid onDisconnected()
void onConnectFailed()
AppLib.connect()
call or an automatic reconnect attempt if they are enabled.void onStopped()