org.jclouds.lifecycle
Class BaseLifeCycle
java.lang.Object
org.jclouds.lifecycle.BaseLifeCycle
- All Implemented Interfaces:
- Runnable, LifeCycle
public abstract class BaseLifeCycle
- extends Object
- implements Runnable, LifeCycle
// TODO: Adrian: Document this!
- Author:
- Adrian Cole
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
logger
protected Logger logger
executorService
protected final ExecutorService executorService
dependencies
protected final List<LifeCycle> dependencies
statusLock
protected final Object statusLock
status
protected volatile LifeCycle.Status status
exception
protected AtomicReference<Exception> exception
BaseLifeCycle
public BaseLifeCycle(ExecutorService executor,
LifeCycle... dependencies)
addDependency
public void addDependency(LifeCycle lifeCycle)
getStatus
public LifeCycle.Status getStatus()
- Specified by:
getStatus
in interface LifeCycle
- Returns:
- the current state of the component;
run
public void run()
- Specified by:
run
in interface Runnable
doWork
protected abstract void doWork()
throws Exception
- Throws:
Exception
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
- Specified by:
start
in interface LifeCycle
exceptionIfDepedenciesNotActive
protected void exceptionIfDepedenciesNotActive()
getExceptionFromDependenciesOrNull
protected Exception getExceptionFromDependenciesOrNull()
getException
public Exception getException()
- Specified by:
getException
in interface LifeCycle
- 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.
- Specified by:
shutdown
in interface LifeCycle
shutdown
public void shutdown(long waitMs)
- Description copied from interface:
LifeCycle
- Requests shutdown, but will only wait @link waitms milliseconds
- Specified by:
shutdown
in interface LifeCycle
- Parameters:
waitMs
- maximum time to wait in milliseconds
exceptionIfNotActive
protected void exceptionIfNotActive()
Copyright © 2009-2012 jclouds. All Rights Reserved.