Application lifecycle

While the framework is launching/running, there are several phases of which plugins are notified.
In addition to the normal events, there are intermediate events that may or may not occur during one run cycle of the framework.
They occur in the following order:

1. Plugins loaded

2. Pre-Initialization

During this phase, plugins should create their service instances and register them to the ServiceManager so they are available to other plugins.

3. Initialization

During this phase, actual semantic initialization shall occur.
For example:

  • Loading configuration

This event can be "canceled" meaning that the bot will shut down when all listeners have consumed the event.
Plugins may use this to prevent the bot from starting with invalid or default configurations.

4. Pre-Connect

The framework is about to try establishing a connection to the TeamSpeak server.
This event can be fired multiple times during the life cycle as disconnects and failed attempts will revert the life cycle state to this event. (See the graphic below)

5. Post-Connect

The framework successfully established the connection to the TeamSpeak server.
This event can be fired multiple times as as disconnects will revert the life cycle to pre-connect. (See the graphic below)

Intermediate: Disconnect

When the connection to the TeamSpeak server has been closed, this event will be fired.
The event provides information about whether or not the disconnect was intentional (graceful) or not.
When the disconnect was intentional, the framework will continue shutting down.
When the disconnect was not intentional, the framework will attempt to re-connect to the server (unless a maximum of 0 retries is configured by the administrator).

Intermediate: ConnectFailed

An attempt to connect to the server has failed.
The framework will try to re-connect to the framework as long as the connection attempts count has not reached its configured maximum.
The event allows access to this information.

6. Pre-Shutdown

Signals all plugins to gracefully stop operating as the bot and its services will shut down shortly after.

7. Post-Shutdown

Most services have been shut down. Some (like the Hibernate integration) will be forcefully stopped after this event has been consumed.
This phase is used to free resources that were required to be available until the last possible life-cycle phase.

Additional information

🚧

Remember

The JVM will not exit until no running threads are left.
If a plugin happens to use concurrency features not provided by Jeak, their developer must make sure that all processing has to stop in a timely fashion after Pre-/Post-Shutdown so it is guaranteed that the bot will be completely shut down.

❗️

Attention

Phase-Events are synchronized events. Meaning that they block some threads while the listeners are working. (Including other events)
This makes sure that you can register listeners for any later phase inside a listener method.

When a plugin has to do a lot of work which is started by a phase event, please consider using Tasks so the work can be put into an asynchronous thread.

Visualization of the lifecycle

For a better understanding of when what life cycle phase event is fired there is a flowchart available:PDF-View/Download


What’s Next