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>
dependencies
protected AtomicReference<Exception>
exception
protected Logger
logger
protected LifeCycle.Status
status
protected Object
statusLock
protected com.google.common.util.concurrent.ListeningExecutorService
userExecutor
-
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 void
addDependency(LifeCycle lifeCycle)
protected void
awaitShutdown(long timeout)
protected void
awaitStatus(LifeCycle.Status intended, long timeout)
protected abstract void
doShutdown()
protected abstract void
doWork()
protected void
exceptionIfDependenciesNotActive()
protected void
exceptionIfNotActive()
Exception
getException()
protected Exception
getExceptionFromDependenciesOrNull()
LifeCycle.Status
getStatus()
void
run()
protected boolean
shouldDoWork()
void
shutdown()
Requests shutdown of the component.void
shutdown(long waitMs)
Requests shutdown, but will only wait @link waitms millisecondsvoid
start()
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:LifeCycle
Asynchronously starts the component
-
exceptionIfDependenciesNotActive
protected void exceptionIfDependenciesNotActive()
-
getExceptionFromDependenciesOrNull
protected Exception getExceptionFromDependenciesOrNull()
-
getException
public Exception getException()
- Specified by:
getException
in 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:LifeCycle
Requests shutdown of the component.
-
shutdown
public void shutdown(long waitMs)
Description copied from interface:LifeCycle
Requests shutdown, but will only wait @link waitms milliseconds
-
exceptionIfNotActive
protected void exceptionIfNotActive()
-
-