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 classOptionalDependency.DependencyStateOne 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 booleandemandedByDependentIndicates if this dependency has been demanded by the dependentprivate booleandependencyFailedIndicates if optionalDependency notified a dependency failure.private OptionalDependency.DependencyStatedependencyStateTheoptionalDependencystate, based on notifications thatoptionalDependencymade to this dependent.private DependentdependentThe dependent on this optional dependencyprivate booleandependentStartedNotifiedKeeps track of whether optionalDependency has been notified of a dependent started.(package private) booleanforwardNotificationsIndicates if notification should take placeprivate DependencyoptionalDependencyThe actual dependency.private booleantransitiveDependencyUnavailableIndicates 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 voidaddDemand()Notify that adependententeredactive mode.voidaddDependent(Dependent dependent)Add a dependent to this dependency, establishing the dependency relation between this dependency and its dependent.voiddependencyFailed()Notify this dependent that one of its dependencies (immediate or transitive) failed to start.voiddependencyFailureCleared()Notify this dependent that all dependency failures previouslynotifiedare now cleared.voiddependentStarted()Notify that adependentis starting.voiddependentStopped()Notify that adependentis stopping.ServiceControllerImpl<?>getController()Get the controller of this dependent.ServiceControllerImpl<?>getDependencyController()Get the controller for this dependency, ornullif there is none currently.ServiceNamegetName()Get the name of this dependency.java.lang.ObjectgetValue()Get the installed instance value, if any exists.voidimmediateDependencyAvailable(ServiceName dependencyName)Notify this dependent that one of its immediate dependencies is available, i.e., it is installed and, if notstarted, should start shortly.voidimmediateDependencyDown()Notify this dependent that one of its immediate dependencies is leaving theUPstate.voidimmediateDependencyUnavailable(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 inNEVERmode.voidimmediateDependencyUp()Notify this dependent that one of its immediate dependencies enteredUPstate.voidremoveDemand()Notify that adependentleftactive mode.voidremoveDependent(Dependent dependent)Remove a dependent from this dependency, breaking the dependency relation between this dependency and its dependent.voidtransitiveDependencyAvailable()Notify this dependent that allunavailabletransitive dependencies are now available (i.e., they are installed and will perform an attempt to start shortly).voidtransitiveDependencyUnavailable()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
TheoptionalDependencystate, based on notifications thatoptionalDependencymade 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:DependencyAdd 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:
addDependentin interfaceDependency- Parameters:
dependent- the dependent to add
-
removeDependent
public void removeDependent(Dependent dependent)
Description copied from interface:DependencyRemove 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:
removeDependentin interfaceDependency- Parameters:
dependent- the dependent to remove
-
addDemand
public void addDemand()
Description copied from interface:DependencyNotify that adependententeredactive mode. This method must not be called under a lock.- Specified by:
addDemandin interfaceDependency
-
removeDemand
public void removeDemand()
Description copied from interface:DependencyNotify that adependentleftactive mode. This method must not be called under a lock.- Specified by:
removeDemandin interfaceDependency
-
dependentStarted
public void dependentStarted()
Description copied from interface:DependencyNotify that adependentis starting. This method must not be called under a lock.- Specified by:
dependentStartedin interfaceDependency
-
dependentStopped
public void dependentStopped()
Description copied from interface:DependencyNotify that adependentis stopping. This method must not be called under a lock.- Specified by:
dependentStoppedin interfaceDependency
-
getValue
public java.lang.Object getValue() throws java.lang.IllegalStateExceptionDescription copied from interface:DependencyGet the installed instance value, if any exists.- Specified by:
getValuein interfaceDependency- Specified by:
getValuein 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:DependencyGet the name of this dependency.- Specified by:
getNamein interfaceDependency- Returns:
- the name
-
getDependencyController
public ServiceControllerImpl<?> getDependencyController()
Description copied from interface:DependencyGet the controller for this dependency, ornullif there is none currently.- Specified by:
getDependencyControllerin interfaceDependency- Returns:
- the controller, or
nullfor none
-
immediateDependencyAvailable
public void immediateDependencyAvailable(ServiceName dependencyName)
Description copied from interface:DependentNotify 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:
immediateDependencyAvailablein interfaceDependent- Parameters:
dependencyName- the name of the immediate dependency that is now available
-
immediateDependencyUnavailable
public void immediateDependencyUnavailable(ServiceName dependencyName)
Description copied from interface:DependentNotify this dependent that one of its immediate dependencies is unavailable.
A dependency is unavailable when it is not installed or when it is inNEVERmode.This method must not be called under a lock.
- Specified by:
immediateDependencyUnavailablein interfaceDependent- Parameters:
dependencyName- the name of the immediate dependency that is now unavailable
-
immediateDependencyUp
public void immediateDependencyUp()
Description copied from interface:DependentNotify this dependent that one of its immediate dependencies enteredUPstate.This method must not be called under a lock.
- Specified by:
immediateDependencyUpin interfaceDependent
-
immediateDependencyDown
public void immediateDependencyDown()
Description copied from interface:DependentNotify this dependent that one of its immediate dependencies is leaving theUPstate.This method must not be called under a lock.
- Specified by:
immediateDependencyDownin interfaceDependent
-
dependencyFailed
public void dependencyFailed()
Description copied from interface:DependentNotify this dependent that one of its dependencies (immediate or transitive) failed to start. This method is called after the dependency state transitions fromSTARTINGtoSTART_FAILED.Dependency failures that occur after the notified failure do not result in new
dependencyFailednotifications, as the dependent will never receive two or more dependencyFailed calls in a row. AdependencyFailednotification 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:
dependencyFailedin interfaceDependent
-
dependencyFailureCleared
public void dependencyFailureCleared()
Description copied from interface:DependentNotify this dependent that all dependency failures previouslynotifiedare now cleared. This method is called only after all affected dependencies leftSTART_FAILEDstate.This method must not be called under a lock.
- Specified by:
dependencyFailureClearedin interfaceDependent
-
transitiveDependencyAvailable
public void transitiveDependencyAvailable()
Description copied from interface:DependentNotify this dependent that allunavailabletransitive 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:
transitiveDependencyAvailablein interfaceDependent
-
getController
public ServiceControllerImpl<?> getController()
Description copied from interface:DependentGet the controller of this dependent.- Specified by:
getControllerin interfaceDependent- Returns:
- the controller
-
transitiveDependencyUnavailable
public void transitiveDependencyUnavailable()
Description copied from interface:DependentNotify 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
dependencyUnavailablenotifications, as the dependent will never receive two or more dependencyUnavailable calls in a row. AdependencyUnavailablenotification 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:
transitiveDependencyUnavailablein interfaceDependent
-
-