|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jvnet.hk2.component.internal.runlevel.DefaultRunLevelService
public class DefaultRunLevelService
The default environment RunLevelService implementation. Assume ServiceA, ServiceB, and ServiceC are all in the same RunLevel and the dependencies are: ServiceA -> ServiceB -> ServiceC Expected start order: ServiceC, ServiceB, ServiceA Expected shutdown / PreDestroy order: ServiceA, ServiceB, ServiceC So, how do we decide when to record events to the recorder? The answer is hook into (post) PostConstruct activations. Since the model is not in the habitat, we will just need to randomly pick a start service. Case 1: A, B, then C by RLS. get ServiceA (called by RLS) Start ServiceA: get ServiceB Start ServiceB: get ServiceC Start ServiceC wire ServiceC PostConstruct ServiceC wire ServiceB PostConstruct ServiceB wire ServiceA PostConstruct ServiceA get ServiceB (called by RLS) get ServiceC (called by RLS) Case 2: B, C, then A by RLS. get ServiceB (called by RLS) Start ServiceB: get ServiceC Start ServiceC wire ServiceC PostConstruct ServiceC wire ServiceB PostConstruct ServiceB get ServiceC (called by RLS) get ServiceA (called by RLS) Start ServiceA: get ServiceB wire ServiceA PostConstruct ServiceA Case 3: B, A, then C by RLS. get ServiceB (called by RLS) Start ServiceB: get ServiceC Start ServiceC wire ServiceC PostConstruct ServiceC wire ServiceB PostConstruct ServiceB get ServiceA (called by RLS) Start ServiceA: get ServiceB wire ServiceA PostConstruct ServiceA get ServiceC (called by RLS) Case 4: C, B, then A by RLS. get ServiceC (called by RLS) Start ServiceC: wire ServiceC PostConstruct ServiceC get ServiceB (called by RLS) Start ServiceB: get ServiceC wire ServiceB PostConstruct ServiceB get ServiceA (called by RLS) Start ServiceA: get ServiceB wire ServiceA PostConstruct ServiceA get ServiceA (called by RLS) ~~~ Note that the implementation performs some level of constraint checking during injection. For example, - It is an error to have a RunLevel-annotated service at RunLevel X to depend on (i.e., be injected with) a RunLevel-annotated service at RunLevel Y when Y > X. - It is an error to have a non-RunLevel-annotated service to depend on a RunLevel-annotated service at any RunLevel. Note that the implementation does not handle Holder and Collection injection constraint validations. ~~~ The implementation will automatically proceedTo(-1) after the habitat has been initialized. Note that all RunLevel values less than -1 will be ignored.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface org.jvnet.hk2.component.InhabitantListener |
|---|
InhabitantListener.EventType |
| Nested classes/interfaces inherited from interface org.jvnet.hk2.component.HabitatListener |
|---|
HabitatListener.EventType |
| Constructor Summary | |
|---|---|
DefaultRunLevelService(Habitat habitat)
|
|
| Method Summary | |
|---|---|
protected void |
activateRunLevel()
|
java.lang.Integer |
getCurrentRunLevel()
The current run level state. |
java.lang.Class<java.lang.Void> |
getEnvironment()
The environment value for this state. |
java.lang.Integer |
getPlannedRunLevel()
The planned run level state. |
RunLevelState<java.lang.Void> |
getState()
Returns the current state of this RunLevelService instance. |
boolean |
inhabitantChanged(HabitatListener.EventType eventType,
Habitat habitat,
Inhabitant<?> inhabitant)
Called when the habitat has changed. |
boolean |
inhabitantChanged(InhabitantListener.EventType eventType,
Inhabitant<?> inhabitant)
Called when the inhabitant has changed. |
boolean |
inhabitantIndexChanged(HabitatListener.EventType eventType,
Habitat habitat,
Inhabitant<?> inhabitant,
java.lang.String index,
java.lang.String name,
java.lang.Object service)
Called when the habitat index has changed. |
void |
proceedTo(int runLevel)
Causes this RunLevelService to move to the specified run level for all RunLevel instances (identified by environment), orchestrating the appropriate lifecycle events based on the given implementation strategy. |
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DefaultRunLevelService(Habitat habitat)
| Method Detail |
|---|
public java.lang.String toString()
toString in class java.lang.Objectpublic void proceedTo(int runLevel)
RunLevelServiceIf the RunLevel specified is the same as the current RunLevel then the RunLevelService will return immediately.
Note that the underlying implementation may perform this operation asynchronously. Implementors who choose the asynchronous approach are expected to treat a subsequent proceedTo(newRunLevel) call as an implicit cancellation of any currently running proceedTo() that is running on one or more managed threads. Again, see the javadoc for each implementation for details.
proceedTo in interface RunLevelService<java.lang.Void>runLevel - the run level to move to.protected void activateRunLevel()
public RunLevelState<java.lang.Void> getState()
RunLevelService
getState in interface RunLevelService<java.lang.Void>public java.lang.Class<java.lang.Void> getEnvironment()
RunLevelState
getEnvironment in interface RunLevelState<java.lang.Void>public java.lang.Integer getCurrentRunLevel()
RunLevelState
getCurrentRunLevel in interface RunLevelState<java.lang.Void>public java.lang.Integer getPlannedRunLevel()
RunLevelState
getPlannedRunLevel in interface RunLevelState<java.lang.Void>RunLevelService.proceedTo(int).
public boolean inhabitantChanged(InhabitantListener.EventType eventType,
Inhabitant<?> inhabitant)
InhabitantListener
inhabitantChanged in interface InhabitantListener
public boolean inhabitantChanged(HabitatListener.EventType eventType,
Habitat habitat,
Inhabitant<?> inhabitant)
HabitatListener
inhabitantChanged in interface HabitatListener
public boolean inhabitantIndexChanged(HabitatListener.EventType eventType,
Habitat habitat,
Inhabitant<?> inhabitant,
java.lang.String index,
java.lang.String name,
java.lang.Object service)
HabitatListener
inhabitantIndexChanged in interface HabitatListener
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||