Package org.jclouds.lifecycle
Class BaseLifeCycle
- java.lang.Object
-
- org.jclouds.lifecycle.BaseLifeCycle
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jclouds.lifecycle.LifeCycle
LifeCycle.Status
-
-
Field Summary
Fields Modifier and Type Field Description protected List<LifeCycle>dependenciesprotected AtomicReference<Exception>exceptionprotected Loggerloggerprotected LifeCycle.Statusstatusprotected ObjectstatusLockprotected com.google.common.util.concurrent.ListeningExecutorServiceuserExecutor
-
Constructor Summary
Constructors Constructor Description BaseLifeCycle(com.google.common.util.concurrent.ListeningExecutorService userExecutor, LifeCycle... dependencies)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddDependency(LifeCycle lifeCycle)protected voidawaitShutdown(long timeout)protected voidawaitStatus(LifeCycle.Status intended, long timeout)protected abstract voiddoShutdown()protected abstract voiddoWork()protected voidexceptionIfDependenciesNotActive()protected voidexceptionIfNotActive()ExceptiongetException()protected ExceptiongetExceptionFromDependenciesOrNull()LifeCycle.StatusgetStatus()voidrun()protected booleanshouldDoWork()voidshutdown()Requests shutdown of the component.voidshutdown(long waitMs)Requests shutdown, but will only wait @link waitms millisecondsvoidstart()Asynchronously starts the component
-
-
-
Field Detail
-
logger
protected Logger logger
-
userExecutor
protected final com.google.common.util.concurrent.ListeningExecutorService userExecutor
-
statusLock
protected final Object statusLock
-
status
protected volatile LifeCycle.Status status
-
exception
protected AtomicReference<Exception> exception
-
-
Constructor Detail
-
BaseLifeCycle
public BaseLifeCycle(com.google.common.util.concurrent.ListeningExecutorService userExecutor, LifeCycle... dependencies)
-
-
Method Detail
-
addDependency
public void addDependency(LifeCycle lifeCycle)
-
getStatus
public LifeCycle.Status getStatus()
-
doShutdown
protected abstract void doShutdown()
-
shouldDoWork
protected boolean shouldDoWork()
- Returns:
- false if any dependencies are inactive, or we are inactive, or we have a global exception.
-
start
@PostConstruct public void start()
Description copied from interface:LifeCycleAsynchronously starts the component
-
exceptionIfDependenciesNotActive
protected void exceptionIfDependenciesNotActive()
-
getExceptionFromDependenciesOrNull
protected Exception getExceptionFromDependenciesOrNull()
-
getException
public Exception getException()
- Specified by:
getExceptionin interfaceLifeCycle- Returns:
- Exception or null, if there are no fatal Exceptions encountered in the lifecycle of this component.
-
awaitShutdown
protected void awaitShutdown(long timeout) throws InterruptedException- Throws:
InterruptedException
-
awaitStatus
protected void awaitStatus(LifeCycle.Status intended, long timeout) throws InterruptedException
- Throws:
InterruptedException
-
shutdown
@PreDestroy public void shutdown()
Description copied from interface:LifeCycleRequests shutdown of the component.
-
shutdown
public void shutdown(long waitMs)
Description copied from interface:LifeCycleRequests shutdown, but will only wait @link waitms milliseconds
-
exceptionIfNotActive
protected void exceptionIfNotActive()
-
-