- java.lang.Object
-
- aeonics.entity.Entity
-
- aeonics.manager.Manager.Type
-
- aeonics.manager.Lifecycle
-
- All Implemented Interfaces:
Exportable
,Snapshotable
public abstract class Lifecycle extends Manager.Type
The lifecycle manager should be considered as a global event bus for different application phases.Distinct
Lifecycle.Phase
will occur during the application lifecycle. Plugins or other components may register calback handlers to perform some business logic accordingly, either before the event is triggered, on (when) the event is triggered, or after the event has been trigered.Handlers must be instances of the
Callback.Once
class so that they will be executed only once. This is to prevent accidential executions in case a phase is triggered multiple times.A phase is complete when all handlers have completed, therefore it is not considered as an applicaiton "state" but more like an event. A phase could (but should not) be triggered multiple times over the entire application lifecycle. In regular conditions, only one phase will run at a time. Unless you have valid reasons to do so, it is always preferable to use the
on
methods to avoid unintended side effects.The lifecycle phases will always happen in this sequence:
Lifecycle.Phase.BOOT
: this is the initial state and it does not raise any events.Lifecycle.Phase.LOAD
: when all plugins have been preloaded usingPlugin.start()
, the load phase begins.- before: in this stage, you may perform some of your own initialization logic but it should not rely on any other plugin, managers, registry or factory.
- during: the
Lifecycle
,Executor
andConfig
managers are available but not populated yet. At this stage, you can registerFactory
items and declareConfig
parameters. - after: this step is the last moment to register an initial
Snapshot.onRestore(aeonics.util.Functions.Consumer)
handler. All remaining managers are available but not fully populated yet.
Lifecycle.Phase.CONFIG
: when managers and entity types are registered, the initial configuration loading begins.- before: in this stage, the initial snapshot restore happens. It means that the default config and registry is being populated now and will only be available in the next stage. Although, you may perform some restore and initialization, or defer it for the next phase by keeping a reference to the restore data.
- during: The config manager is now fully populated thanks to the snapshot restore operation. The registry is also populated with restored entities and you can also register your own entities.
- after: if you need to act on existing registry items, it may be a convenient time to do so.
Lifecycle.Phase.RUN
: everything is setup and populated, so the system is entering the run phase.- before: in this stage, the
Logger
manager is started instead of simple stdout. In case there is no security provider defined from the previous stage, a default one is created with basic permissive security rules. All the managers that have active components are starting in this phase. - during: in this stage, you can start your own entities, use the network and executor managers.
All
Origin
entities will be started automatically in this phase. - after: this is the last stage for the normal startup sequence.
- before: in this stage, the
Lifecycle.Phase.SHUTDOWN
: when the system is requested to stop, the shutdown phase begins.- before: you may handle some business logic before other elements apply their shutdown sequence.
- during: all executor tasks are being terminated, the network is closing and everything gets ready for shutdown.
- after: in this stage, you shall not use any managers, registry or factory anymore.
The logger is falling back to stdout and all remaining
Origin
entities are stopped.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Lifecycle.Phase
The different application phases.
-
Constructor Summary
Constructors Constructor Description Lifecycle()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static Callback<Lifecycle.Phase,Lifecycle>
after(Lifecycle.Phase phase)
Returns the global callback for the given phase.static void
after(Lifecycle.Phase phase, Callback.Once<Lifecycle.Phase,Lifecycle> handler)
Registers a handler to run after other handlers in the specified phase.static void
after(Lifecycle.Phase phase, Functions.Runnable handler)
Registers a handler to run after other handlers in the specified phase.protected static Callback<Lifecycle.Phase,Lifecycle>
before(Lifecycle.Phase phase)
Returns the global callback for the given phasestatic void
before(Lifecycle.Phase phase, Callback.Once<Lifecycle.Phase,Lifecycle> handler)
Registers a handler to run before other handlers in the specified phase.static void
before(Lifecycle.Phase phase, Functions.Runnable handler)
Registers a handler to run before other handlers in the specified phase.abstract void
boot()
Initiates the boot sequence.java.lang.Class<? extends Manager.Type>
manager()
Hardcoded manager typeprotected static Callback<Lifecycle.Phase,Lifecycle>
on(Lifecycle.Phase phase)
Returns the global callback for the given phasestatic void
on(Lifecycle.Phase phase, Callback.Once<Lifecycle.Phase,Lifecycle> handler)
Registers a handler to run in the specified phase.static void
on(Lifecycle.Phase phase, Functions.Runnable handler)
Registers a handler to run in the specified phase.abstract Lifecycle.Phase
phase()
Returns the current lifecycle phase-
Methods inherited from class aeonics.manager.Manager.Type
category, internal
-
Methods inherited from class aeonics.entity.Entity
addRelation, addRelation, addRelation, cast, clearRelation, config, defineRelation, equals, export, firstRelation, hashCode, hasRelation, id, name, name, onCreate, onRemove, onUpdate, parameter, relations, relationships, removeRelation, snapshot, type, valueOf, valueOf
-
-
-
-
Method Detail
-
manager
public final java.lang.Class<? extends Manager.Type> manager()
Hardcoded manager type- Specified by:
manager
in classManager.Type
- Returns:
- the type of manager
-
phase
public abstract Lifecycle.Phase phase()
Returns the current lifecycle phase- Returns:
- the current lifecycle phase
-
boot
public abstract void boot()
Initiates the boot sequence. This method must return only after theLifecycle.Phase.SHUTDOWN
is complete.
-
before
public static void before(Lifecycle.Phase phase, Callback.Once<Lifecycle.Phase,Lifecycle> handler)
Registers a handler to run before other handlers in the specified phase. All handlers are global and shared for all instances of the Lifecycle manager.- Parameters:
phase
- the application phasehandler
- the handler to run
-
before
public static void before(Lifecycle.Phase phase, Functions.Runnable handler)
Registers a handler to run before other handlers in the specified phase. All handlers are global and shared for all instances of the Lifecycle manager.- Parameters:
phase
- the application phasehandler
- the handler to run
-
before
protected static Callback<Lifecycle.Phase,Lifecycle> before(Lifecycle.Phase phase)
Returns the global callback for the given phase- Parameters:
phase
- the phase- Returns:
- the matching callback
-
on
public static void on(Lifecycle.Phase phase, Callback.Once<Lifecycle.Phase,Lifecycle> handler)
Registers a handler to run in the specified phase. All handlers are global and shared for all instances of the Lifecycle manager.- Parameters:
phase
- the application phasehandler
- the handler to run
-
on
public static void on(Lifecycle.Phase phase, Functions.Runnable handler)
Registers a handler to run in the specified phase. All handlers are global and shared for all instances of the Lifecycle manager.- Parameters:
phase
- the application phasehandler
- the handler to run
-
on
protected static Callback<Lifecycle.Phase,Lifecycle> on(Lifecycle.Phase phase)
Returns the global callback for the given phase- Parameters:
phase
- the phase- Returns:
- the matching callback
-
after
public static void after(Lifecycle.Phase phase, Callback.Once<Lifecycle.Phase,Lifecycle> handler)
Registers a handler to run after other handlers in the specified phase. All handlers are global and shared for all instances of the Lifecycle manager.- Parameters:
phase
- the application phasehandler
- the handler to run
-
after
public static void after(Lifecycle.Phase phase, Functions.Runnable handler)
Registers a handler to run after other handlers in the specified phase. All handlers are global and shared for all instances of the Lifecycle manager.- Parameters:
phase
- the application phasehandler
- the handler to run
-
after
protected static Callback<Lifecycle.Phase,Lifecycle> after(Lifecycle.Phase phase)
Returns the global callback for the given phase.- Parameters:
phase
- the phase- Returns:
- the matching callback
-
-