Class OptionalDependency
- java.lang.Object
-
- org.jboss.msc.service.OptionalDependency
-
- All Implemented Interfaces:
Dependency
,Dependent
,Value<java.lang.Object>
class OptionalDependency extends java.lang.Object implements Dependency, Dependent
An OptionalDependency.
This class establishes a transitive dependency relationship between the dependent and the real dependency. The intermediation performed by this class adds the required optional behavior to the dependency relation, by:- notifies the dependent that it is in the UP state when the real dependency is unresolved or unavailable
- once the real dependency is available, if there is a demand previously added by the dependent, this dependency does not start forwarding the notifications to the dependent, meaning that the dependent won't even be aware that the dependency is down
- waits for the dependency to be available and the dependent to be inactive, so it can finally start forwarding notifications in both directions (from dependency to dependent and vice-versa)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
OptionalDependency.DependencyState
One of the states of a dependency from the dependent point of view (i.e., based on notifications made by the dependency).
-
Field Summary
Fields Modifier and Type Field Description private boolean
demandedByDependent
Indicates if this dependency has been demanded by the dependentprivate boolean
dependencyFailed
Indicates if optionalDependency notified a dependency failure.private OptionalDependency.DependencyState
dependencyState
TheoptionalDependency
state, based on notifications thatoptionalDependency
made to this dependent.private Dependent
dependent
The dependent on this optional dependencyprivate boolean
dependentStartedNotified
Keeps track of whether optionalDependency has been notified of a dependent started.(package private) boolean
forwardNotifications
Indicates if notification should take placeprivate Dependency
optionalDependency
The actual dependency.private boolean
transitiveDependencyUnavailable
Indicates if optional dependency has a transitive dependency unavailable.
-
Constructor Summary
Constructors Constructor Description OptionalDependency(Dependency optionalDependency)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDemand()
Notify that adependent
enteredactive mode
.void
addDependent(Dependent dependent)
Add a dependent to this dependency, establishing the dependency relation between this dependency and its dependent.void
dependencyFailed()
Notify this dependent that one of its dependencies (immediate or transitive) failed to start.void
dependencyFailureCleared()
Notify this dependent that all dependency failures previouslynotified
are now cleared.void
dependentStarted()
Notify that adependent
is starting.void
dependentStopped()
Notify that adependent
is stopping.ServiceControllerImpl<?>
getController()
Get the controller of this dependent.ServiceControllerImpl<?>
getDependencyController()
Get the controller for this dependency, ornull
if there is none currently.ServiceName
getName()
Get the name of this dependency.java.lang.Object
getValue()
Get the installed instance value, if any exists.void
immediateDependencyAvailable(ServiceName dependencyName)
Notify this dependent that one of its immediate dependencies is available, i.e., it is installed and, if notstarted
, should start shortly.void
immediateDependencyDown()
Notify this dependent that one of its immediate dependencies is leaving theUP
state.void
immediateDependencyUnavailable(ServiceName dependencyName)
Notify this dependent that one of its immediate dependencies is unavailable.
A dependency is unavailable when it is not installed or when it is inNEVER
mode.void
immediateDependencyUp()
Notify this dependent that one of its immediate dependencies enteredUP
state.void
removeDemand()
Notify that adependent
leftactive mode
.void
removeDependent(Dependent dependent)
Remove a dependent from this dependency, breaking the dependency relation between this dependency and its dependent.void
transitiveDependencyAvailable()
Notify this dependent that allunavailable
transitive dependencies are now available (i.e., they are installed and will perform an attempt to start shortly).void
transitiveDependencyUnavailable()
Notify this dependent that one of its transitive dependencies is unavailable (either uninstalled, or inNEVER mode
).
-
-
-
Field Detail
-
optionalDependency
private final Dependency optionalDependency
The actual dependency.
-
dependencyState
private OptionalDependency.DependencyState dependencyState
TheoptionalDependency
state, based on notifications thatoptionalDependency
made to this dependent.
-
transitiveDependencyUnavailable
private boolean transitiveDependencyUnavailable
Indicates if optional dependency has a transitive dependency unavailable.
-
dependencyFailed
private boolean dependencyFailed
Indicates if optionalDependency notified a dependency failure.
-
dependent
private Dependent dependent
The dependent on this optional dependency
-
demandedByDependent
private boolean demandedByDependent
Indicates if this dependency has been demanded by the dependent
-
forwardNotifications
boolean forwardNotifications
Indicates if notification should take place
-
dependentStartedNotified
private boolean dependentStartedNotified
Keeps track of whether optionalDependency has been notified of a dependent started. This field is useful for avoiding dependentStopped notifications that don't have a corresponding previous dependentStarted notification.
-
-
Constructor Detail
-
OptionalDependency
OptionalDependency(Dependency optionalDependency)
-
-
Method Detail
-
addDependent
public void addDependent(Dependent dependent)
Description copied from interface:Dependency
Add a dependent to this dependency, establishing the dependency relation between this dependency and its dependent. This method must not be called under a lock.- Specified by:
addDependent
in interfaceDependency
- Parameters:
dependent
- the dependent to add
-
removeDependent
public void removeDependent(Dependent dependent)
Description copied from interface:Dependency
Remove a dependent from this dependency, breaking the dependency relation between this dependency and its dependent. This method must not be called under a lock.- Specified by:
removeDependent
in interfaceDependency
- Parameters:
dependent
- the dependent to remove
-
addDemand
public void addDemand()
Description copied from interface:Dependency
Notify that adependent
enteredactive mode
. This method must not be called under a lock.- Specified by:
addDemand
in interfaceDependency
-
removeDemand
public void removeDemand()
Description copied from interface:Dependency
Notify that adependent
leftactive mode
. This method must not be called under a lock.- Specified by:
removeDemand
in interfaceDependency
-
dependentStarted
public void dependentStarted()
Description copied from interface:Dependency
Notify that adependent
is starting. This method must not be called under a lock.- Specified by:
dependentStarted
in interfaceDependency
-
dependentStopped
public void dependentStopped()
Description copied from interface:Dependency
Notify that adependent
is stopping. This method must not be called under a lock.- Specified by:
dependentStopped
in interfaceDependency
-
getValue
public java.lang.Object getValue() throws java.lang.IllegalStateException
Description copied from interface:Dependency
Get the installed instance value, if any exists.- Specified by:
getValue
in interfaceDependency
- Specified by:
getValue
in interfaceValue<java.lang.Object>
- Returns:
- the installed service value
- Throws:
java.lang.IllegalStateException
- if an error occurs
-
getName
public ServiceName getName()
Description copied from interface:Dependency
Get the name of this dependency.- Specified by:
getName
in interfaceDependency
- Returns:
- the name
-
getDependencyController
public ServiceControllerImpl<?> getDependencyController()
Description copied from interface:Dependency
Get the controller for this dependency, ornull
if there is none currently.- Specified by:
getDependencyController
in interfaceDependency
- Returns:
- the controller, or
null
for none
-
immediateDependencyAvailable
public void immediateDependencyAvailable(ServiceName dependencyName)
Description copied from interface:Dependent
Notify this dependent that one of its immediate dependencies is available, i.e., it is installed and, if notstarted
, should start shortly.This method must not be called under a lock.
- Specified by:
immediateDependencyAvailable
in interfaceDependent
- Parameters:
dependencyName
- the name of the immediate dependency that is now available
-
immediateDependencyUnavailable
public void immediateDependencyUnavailable(ServiceName dependencyName)
Description copied from interface:Dependent
Notify this dependent that one of its immediate dependencies is unavailable.
A dependency is unavailable when it is not installed or when it is inNEVER
mode.This method must not be called under a lock.
- Specified by:
immediateDependencyUnavailable
in interfaceDependent
- Parameters:
dependencyName
- the name of the immediate dependency that is now unavailable
-
immediateDependencyUp
public void immediateDependencyUp()
Description copied from interface:Dependent
Notify this dependent that one of its immediate dependencies enteredUP
state.This method must not be called under a lock.
- Specified by:
immediateDependencyUp
in interfaceDependent
-
immediateDependencyDown
public void immediateDependencyDown()
Description copied from interface:Dependent
Notify this dependent that one of its immediate dependencies is leaving theUP
state.This method must not be called under a lock.
- Specified by:
immediateDependencyDown
in interfaceDependent
-
dependencyFailed
public void dependencyFailed()
Description copied from interface:Dependent
Notify this dependent that one of its dependencies (immediate or transitive) failed to start. This method is called after the dependency state transitions fromSTARTING
toSTART_FAILED
.Dependency failures that occur after the notified failure do not result in new
dependencyFailed
notifications, as the dependent will never receive two or more dependencyFailed calls in a row. AdependencyFailed
notification is only invoked again to notify of new failures if the previous failures have beencleared
.This method must not be called under a lock.
- Specified by:
dependencyFailed
in interfaceDependent
-
dependencyFailureCleared
public void dependencyFailureCleared()
Description copied from interface:Dependent
Notify this dependent that all dependency failures previouslynotified
are now cleared. This method is called only after all affected dependencies leftSTART_FAILED
state.This method must not be called under a lock.
- Specified by:
dependencyFailureCleared
in interfaceDependent
-
transitiveDependencyAvailable
public void transitiveDependencyAvailable()
Description copied from interface:Dependent
Notify this dependent that allunavailable
transitive dependencies are now available (i.e., they are installed and will perform an attempt to start shortly).This method must not be called under a lock.
- Specified by:
transitiveDependencyAvailable
in interfaceDependent
-
getController
public ServiceControllerImpl<?> getController()
Description copied from interface:Dependent
Get the controller of this dependent.- Specified by:
getController
in interfaceDependent
- Returns:
- the controller
-
transitiveDependencyUnavailable
public void transitiveDependencyUnavailable()
Description copied from interface:Dependent
Notify this dependent that one of its transitive dependencies is unavailable (either uninstalled, or inNEVER mode
).New transitive dependencies that become unavailable after the notified one do not result in new
dependencyUnavailable
notifications, as the dependent will never receive two or more dependencyUnavailable calls in a row. AdependencyUnavailable
notification is only invoked again to notify of newly found unavailable dependencies if all the previously unavailable dependencies have becomeavailable
.This method must not be called under a lock.
- Specified by:
transitiveDependencyUnavailable
in interfaceDependent
-
-