S - the service typefinal class ServiceControllerImpl<S> extends java.lang.Object implements ServiceController<S>, Dependent
ServiceController.Mode, ServiceController.State, ServiceController.Substate, ServiceController.Transition| Modifier and Type | Field and Description |
|---|---|
private ServiceRegistrationImpl[] |
aliasRegistrations
The alias registrations of this service.
|
private int |
asyncTasks
The number of asynchronous tasks that are currently running.
|
private IdentityHashSet<ServiceControllerImpl<?>> |
children
The children of this service (only valid during
State#UP). |
private ServiceControllerImpl.ChildServiceTarget |
childTarget
The service target for adding child services (can be
null if none
were added). |
private int |
demandedByCount
The number of registrations which place a demand-to-start on this
instance.
|
private Dependency[] |
dependencies
The dependencies of this service.
|
private boolean |
dependenciesDemanded
Indicates whether dependencies have been demanded.
|
private int |
failCount
Count for failure notification.
|
private static java.lang.String |
ILLEGAL_CONTROLLER_STATE |
private IdentityHashSet<ServiceName> |
immediateUnavailableDependencies
The immediate unavailable dependencies of this service.
|
private ValueInjection<?>[] |
injections
The injections of this service.
|
private long |
lifecycleTime
The system nanotime of the moment in which the last lifecycle change was
initiated.
|
private IdentityHashSet<ServiceListener<? super S>> |
listeners
The set of registered service listeners.
|
(package private) static int |
MAX_DEPENDENCIES |
private ServiceController.Mode |
mode
The controller mode.
|
private IdentityHashSet<StabilityMonitor> |
monitors
The set of registered stability monitors.
|
private static ServiceControllerImpl<?>[] |
NO_CONTROLLERS |
private static Dependent[] |
NO_DEPENDENTS |
private static ServiceName[] |
NO_NAMES |
private static java.lang.String[] |
NO_STRINGS |
private ValueInjection<?>[] |
outInjections
The out injections of this service.
|
private ServiceControllerImpl<?> |
parent
The parent of this service.
|
private ServiceRegistrationImpl |
primaryRegistration
The primary registration of this service.
|
private int |
runningDependents
The number of dependents that are currently running.
|
private Value<? extends Service<S>> |
serviceValue
The service itself.
|
private StartException |
startException
The start exception.
|
private ServiceController.Substate |
state
The controller state.
|
private int |
stoppingDependencies
Count for dependencies that are trying to stop.
|
private int |
transitiveUnavailableDepCount
Indicates if this service has one or more transitive dependencies that
are not available.
|
private int |
unstartedDependencies
The number of dependencies which are not yet started.
|
| Constructor and Description |
|---|
ServiceControllerImpl(Value<? extends Service<S>> serviceValue,
Dependency[] dependencies,
ValueInjection<?>[] injections,
ValueInjection<?>[] outInjections,
ServiceRegistrationImpl primaryRegistration,
ServiceRegistrationImpl[] aliasRegistrations,
java.util.Set<StabilityMonitor> monitors,
java.util.Set<? extends ServiceListener<? super S>> listeners,
ServiceControllerImpl<?> parent) |
| Modifier and Type | Method and Description |
|---|---|
(package private) void |
addAsyncTasks(int size) |
(package private) void |
addChild(ServiceControllerImpl<?> child) |
(package private) void |
addDemand() |
(package private) void |
addDemands(int demandedByCount) |
private void |
addDependentsByName(ServiceRegistrationImpl registration,
java.util.Map<ServiceName,Dependent[]> dependentsByName) |
void |
addListener(ServiceListener<? super S> listener)
Add a service listener.
|
(package private) void |
addMonitor(StabilityMonitor stabilityMonitor) |
S |
awaitValue()
Wait for a service to come up, and then return its value.
|
S |
awaitValue(long time,
java.util.concurrent.TimeUnit unit)
Wait for a service to come up for a certain amount of time, and then return its value.
|
(package private) void |
commitInstallation(ServiceController.Mode initialMode)
Commit the service install, kicking off the mode set and listener execution.
|
boolean |
compareAndSetMode(ServiceController.Mode expectedMode,
ServiceController.Mode newMode)
Compare the current mode against
expected; if it matches, change it to newMode. |
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 previously
notified are now
cleared. |
(package private) void |
dependentStarted() |
(package private) void |
dependentStopped() |
private void |
doDemandDependencies() |
(package private) void |
doExecute(java.util.ArrayList<java.lang.Runnable> tasks) |
private static <T> void |
doInject(ValueInjection<T> injection) |
private void |
doUndemandDependencies() |
(package private) java.lang.String |
dumpServiceDetails() |
ServiceName[] |
getAliases()
Get other names this service is known as.
|
(package private) ServiceRegistrationImpl[] |
getAliasRegistrations() |
(package private) IdentityHashSet<ServiceControllerImpl<?>> |
getChildren() |
ServiceControllerImpl<?> |
getController()
Get the controller of this dependent.
|
private Dependent[][] |
getDependents()
Returns a compiled array of all dependents of this service instance.
|
private java.util.Map<ServiceName,Dependent[]> |
getDependentsByDependencyName()
Returns a compiled map of all dependents of this service mapped by the dependency name.
|
java.util.Set<ServiceName> |
getImmediateUnavailableDependencies()
Get the complete list of immediate dependencies that are unavailable.
|
private void |
getListenerTasks(ServiceController.Transition transition,
java.util.ArrayList<java.lang.Runnable> tasks) |
private void |
getListenerTasks(ServiceControllerImpl.ListenerNotification notification,
java.util.ArrayList<java.lang.Runnable> tasks) |
ServiceController.Mode |
getMode()
Get the service controller's current mode.
|
(package private) java.util.Set<StabilityMonitor> |
getMonitors() |
ServiceName |
getName()
Get the name of this service, if any.
|
ServiceControllerImpl<?> |
getParent()
Get this service's parent service, or
null if there is none. |
(package private) ServiceRegistrationImpl |
getPrimaryRegistration() |
Service<S> |
getService()
Get the service.
|
ServiceContainerImpl |
getServiceContainer()
Get the service container associated with this controller.
|
StartException |
getStartException()
Get the reason why the last start failed.
|
ServiceController.State |
getState()
Get the current service controller state.
|
(package private) ServiceStatus |
getStatus() |
ServiceController.Substate |
getSubstate()
Get the current service controller substate.
|
(package private) ServiceController.Substate |
getSubstateLocked() |
private ServiceController.Transition |
getTransition()
Identify the transition to take.
|
S |
getValue()
Get the service value.
|
void |
immediateDependencyAvailable(ServiceName dependencyName)
Notify this dependent that one of its immediate dependencies is available, i.e., it is installed and, if not
started, should start shortly. |
void |
immediateDependencyDown()
Notify this dependent that one of its immediate dependencies is leaving the
UP 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 in NEVER
mode. |
void |
immediateDependencyUp()
Notify this dependent that one of its immediate dependencies entered
UP
state. |
private void |
internalSetMode(ServiceController.Mode newMode,
java.util.ArrayList<java.lang.Runnable> taskList) |
private boolean |
internalSetMode(ServiceController.Mode expectedMode,
ServiceController.Mode newMode) |
private void |
invokeListener(ServiceListener<? super S> listener,
ServiceControllerImpl.ListenerNotification notification,
ServiceController.Transition transition)
Invokes the listener, performing the notification specified.
|
(package private) boolean |
isInstallationCommitted()
Return
true only if this service controller installation is committed. |
(package private) boolean |
isStableRestState()
Returns true if controller is in rest state and no async tasks are running, false otherwise.
|
(package private) void |
newDependent(ServiceName dependencyName,
Dependent dependent) |
private void |
propagateTransitiveAvailability() |
private void |
propagateTransitiveUnavailability() |
(package private) void |
removeAsyncTask() |
(package private) void |
removeChild(ServiceControllerImpl<?> child) |
(package private) void |
removeDemand() |
void |
removeListener(ServiceListener<? super S> listener)
Remove a service listener.
|
(package private) void |
removeMonitor(StabilityMonitor stabilityMonitor) |
(package private) void |
removeMonitorNoCallback(StabilityMonitor stabilityMonitor) |
void |
retry()
Retry a failed service.
|
(package private) void |
rollbackInstallation()
Roll back the service install.
|
void |
setMode(ServiceController.Mode newMode)
Change the service controller's current mode.
|
private static java.lang.ClassLoader |
setTCCL(java.lang.ClassLoader newTCCL) |
private boolean |
shouldStart()
Determine whether a stopped controller should start.
|
private boolean |
shouldStop()
Determine whether a running controller should stop.
|
(package private) void |
startInstallation()
Start this service installation, connecting it to its parent and dependencies.
|
java.lang.String |
toString() |
(package private) void |
transition(java.util.ArrayList<java.lang.Runnable> tasks)
Run the locked portion of a transition.
|
void |
transitiveDependencyAvailable()
Notify this dependent that all
unavailable 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 in
NEVER mode). |
(package private) void |
updateStabilityState(boolean leavingStableRestState) |
private void |
writeProfileInfo(char statusChar,
long startNanos,
long endNanos) |
private static final java.lang.String ILLEGAL_CONTROLLER_STATE
private final Dependency[] dependencies
private final ValueInjection<?>[] injections
private final ValueInjection<?>[] outInjections
private final IdentityHashSet<ServiceListener<? super S>> listeners
private final IdentityHashSet<StabilityMonitor> monitors
private final ServiceRegistrationImpl primaryRegistration
private final ServiceRegistrationImpl[] aliasRegistrations
private final ServiceControllerImpl<?> parent
private final IdentityHashSet<ServiceControllerImpl<?>> children
State#UP).private final IdentityHashSet<ServiceName> immediateUnavailableDependencies
private StartException startException
private ServiceController.Mode mode
private ServiceController.Substate state
private int demandedByCount
private int unstartedDependencies
private int stoppingDependencies
private int runningDependents
stop() method (and subsequently leave the
ServiceController.State.STOPPING state)
until all running dependents (and listeners) are stopped.private int failCount
private int transitiveUnavailableDepCount
private boolean dependenciesDemanded
private int asyncTasks
private volatile ServiceControllerImpl.ChildServiceTarget childTarget
null if none
were added).private volatile long lifecycleTime
private static final Dependent[] NO_DEPENDENTS
private static final ServiceControllerImpl<?>[] NO_CONTROLLERS
private static final java.lang.String[] NO_STRINGS
static final int MAX_DEPENDENCIES
private static final ServiceName[] NO_NAMES
ServiceControllerImpl(Value<? extends Service<S>> serviceValue, Dependency[] dependencies, ValueInjection<?>[] injections, ValueInjection<?>[] outInjections, ServiceRegistrationImpl primaryRegistration, ServiceRegistrationImpl[] aliasRegistrations, java.util.Set<StabilityMonitor> monitors, java.util.Set<? extends ServiceListener<? super S>> listeners, ServiceControllerImpl<?> parent)
ServiceController.Substate getSubstateLocked()
void addAsyncTasks(int size)
void removeAsyncTask()
void startInstallation()
All notifications from dependencies, parents, and registrations will be ignored until the
installation is committed.
void commitInstallation(ServiceController.Mode initialMode)
initialMode - the initial service modevoid rollbackInstallation()
boolean isInstallationCommitted()
true only if this service controller installation is committed.private boolean shouldStart()
true if soprivate boolean shouldStop()
true if soboolean isStableRestState()
void updateStabilityState(boolean leavingStableRestState)
private ServiceController.Transition getTransition()
null if none is needed at this timevoid transition(java.util.ArrayList<java.lang.Runnable> tasks)
tasks - the list to which async tasks should be appendedprivate void getListenerTasks(ServiceController.Transition transition, java.util.ArrayList<java.lang.Runnable> tasks)
private void getListenerTasks(ServiceControllerImpl.ListenerNotification notification, java.util.ArrayList<java.lang.Runnable> tasks)
void doExecute(java.util.ArrayList<java.lang.Runnable> tasks)
public void setMode(ServiceController.Mode newMode)
ServiceControllerServiceController.Mode.REMOVE. Calling this method with the controller's
current mode has no effect and is always allowed.setMode in interface ServiceController<S>newMode - the new controller modeprivate boolean internalSetMode(ServiceController.Mode expectedMode, ServiceController.Mode newMode)
private void internalSetMode(ServiceController.Mode newMode, java.util.ArrayList<java.lang.Runnable> taskList)
public void immediateDependencyAvailable(ServiceName dependencyName)
Dependentstarted, should start shortly.
This method must not be called under a lock.
immediateDependencyAvailable in interface DependentdependencyName - the name of the immediate dependency that is now availablepublic void immediateDependencyUnavailable(ServiceName dependencyName)
DependentNEVER
mode.
This method must not be called under a lock.
immediateDependencyUnavailable in interface DependentdependencyName - the name of the immediate dependency that is now unavailableprivate void propagateTransitiveUnavailability()
private void propagateTransitiveAvailability()
public void transitiveDependencyAvailable()
Dependentunavailable 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.
transitiveDependencyAvailable in interface Dependentpublic void transitiveDependencyUnavailable()
DependentNEVER 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. A dependencyUnavailable notification is only invoked again to notify of newly found unavailable
dependencies if all the previously unavailable dependencies have become available.
This method must not be called under a lock.
transitiveDependencyUnavailable in interface Dependentpublic ServiceControllerImpl<?> getController()
getController in interface Dependentpublic void immediateDependencyUp()
DependentUP
state.
This method must not be called under a lock.
immediateDependencyUp in interface Dependentpublic void immediateDependencyDown()
DependentUP state.
This method must not be called under a lock.
immediateDependencyDown in interface Dependentpublic void dependencyFailed()
DependentSTARTING to START_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. A dependencyFailed notification is only invoked again to notify of new failures if the previous failures have been
cleared.
This method must not be called under a lock.
dependencyFailed in interface Dependentpublic void dependencyFailureCleared()
Dependentnotified are now
cleared. This method is called only after all affected dependencies left START_FAILED state.
This method must not be called under a lock.
dependencyFailureCleared in interface Dependentvoid dependentStarted()
void dependentStopped()
void newDependent(ServiceName dependencyName, Dependent dependent)
private void doDemandDependencies()
private void doUndemandDependencies()
void addDemand()
void addDemands(int demandedByCount)
void removeDemand()
void addChild(ServiceControllerImpl<?> child)
void removeChild(ServiceControllerImpl<?> child)
IdentityHashSet<ServiceControllerImpl<?>> getChildren()
public ServiceControllerImpl<?> getParent()
ServiceControllernull if there is none.getParent in interface ServiceController<S>null if this service has no parentpublic ServiceContainerImpl getServiceContainer()
ServiceControllergetServiceContainer in interface ServiceController<S>public ServiceController.State getState()
ServiceControllergetState in interface ServiceController<S>public S getValue() throws java.lang.IllegalStateException
ServiceControllerpublic S awaitValue() throws java.lang.IllegalStateException, java.lang.InterruptedException
ServiceControllerawaitValue in interface ServiceController<S>java.lang.IllegalStateException - if the service is not available (i.e. it was removed or failed)java.lang.InterruptedException - if the wait operation was interruptedpublic S awaitValue(long time, java.util.concurrent.TimeUnit unit) throws java.lang.IllegalStateException, java.lang.InterruptedException, java.util.concurrent.TimeoutException
ServiceControllerawaitValue in interface ServiceController<S>time - the amount of time to waitunit - the unit of time to waitjava.lang.IllegalStateException - if the service is not available (i.e. it was removed or failed)java.lang.InterruptedException - if the wait operation was interruptedjava.util.concurrent.TimeoutExceptionpublic Service<S> getService() throws java.lang.IllegalStateException
ServiceControllergetService in interface ServiceController<S>java.lang.IllegalStateException - if the service is not available (i.e. it is not up)public ServiceName getName()
ServiceControllergetName in interface ServiceController<S>null if none was specified.public ServiceName[] getAliases()
ServiceControllergetAliases in interface ServiceController<S>public void addListener(ServiceListener<? super S> listener)
ServiceControlleraddListener in interface ServiceController<S>listener - the service listenerpublic void removeListener(ServiceListener<? super S> listener)
ServiceControllerremoveListener in interface ServiceController<S>listener - the service listener to removepublic StartException getStartException()
ServiceControllergetStartException in interface ServiceController<S>null if the last start succeeded or the service has not yet startedpublic void retry()
ServiceControllerServiceController.State.START_FAILED.retry in interface ServiceController<S>public java.util.Set<ServiceName> getImmediateUnavailableDependencies()
ServiceControllergetImmediateUnavailableDependencies in interface ServiceController<S>public ServiceController.Mode getMode()
ServiceControllergetMode in interface ServiceController<S>public boolean compareAndSetMode(ServiceController.Mode expectedMode, ServiceController.Mode newMode)
ServiceControllerexpected; if it matches, change it to newMode. The
return value is true when the mode was matched and changed.compareAndSetMode in interface ServiceController<S>expectedMode - the expected modenewMode - the new modetrue if the mode was changedServiceStatus getStatus()
java.lang.String dumpServiceDetails()
void addMonitor(StabilityMonitor stabilityMonitor)
void removeMonitor(StabilityMonitor stabilityMonitor)
void removeMonitorNoCallback(StabilityMonitor stabilityMonitor)
java.util.Set<StabilityMonitor> getMonitors()
private void invokeListener(ServiceListener<? super S> listener, ServiceControllerImpl.ListenerNotification notification, ServiceController.Transition transition)
listener - listener to be invokednotification - specified notificationtransition - the transition to be notified, only relevant if notification is
ServiceControllerImpl.ListenerNotification.TRANSITIONpublic ServiceController.Substate getSubstate()
ServiceControllergetSubstate in interface ServiceController<S>ServiceRegistrationImpl getPrimaryRegistration()
ServiceRegistrationImpl[] getAliasRegistrations()
private Dependent[][] getDependents()
private java.util.Map<ServiceName,Dependent[]> getDependentsByDependencyName()
private void addDependentsByName(ServiceRegistrationImpl registration, java.util.Map<ServiceName,Dependent[]> dependentsByName)
private static <T> void doInject(ValueInjection<T> injection)
private static java.lang.ClassLoader setTCCL(java.lang.ClassLoader newTCCL)
public java.lang.String toString()
toString in class java.lang.Objectprivate void writeProfileInfo(char statusChar,
long startNanos,
long endNanos)