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!
  • Field Details

    • logger

      protected Logger logger
    • userExecutor

      protected final com.google.common.util.concurrent.ListeningExecutorService userExecutor
    • dependencies

      protected final List<LifeCycle> dependencies
    • statusLock

      protected final Object statusLock
    • status

      protected volatile LifeCycle.Status status
    • exception

      protected AtomicReference<Exception> exception
  • Constructor Details

    • BaseLifeCycle

      public BaseLifeCycle(com.google.common.util.concurrent.ListeningExecutorService userExecutor, LifeCycle... dependencies)
  • Method Details

    • 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
    • exceptionIfDependenciesNotActive

      protected void exceptionIfDependenciesNotActive()
    • 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()