org.jclouds.lifecycle
Class BaseLifeCycle

java.lang.Object
  extended by 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

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jclouds.lifecycle.LifeCycle
LifeCycle.Status
 
Field Summary
protected  List<LifeCycle> dependencies
           
protected  AtomicReference<Exception> exception
           
protected  ExecutorService executorService
           
protected  Logger logger
           
protected  LifeCycle.Status status
           
protected  Object statusLock
           
 
Constructor Summary
BaseLifeCycle(ExecutorService executor, LifeCycle... dependencies)
           
 
Method Summary
 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 exceptionIfDepedenciesNotActive()
           
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 milliseconds
 void start()
          Asynchronously starts the component
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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
Constructor Detail

BaseLifeCycle

public BaseLifeCycle(ExecutorService executor,
                     LifeCycle... dependencies)
Method Detail

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.