org.neo4j.kernel.lifecycle
Class LifeSupport

java.lang.Object
  extended by org.neo4j.kernel.lifecycle.LifeSupport
All Implemented Interfaces:
Lifecycle

public class LifeSupport
extends Object
implements Lifecycle

Support class for handling collections of Lifecycle instances. Manages the transitions from one state to another.

To use this, first add instances to it that implement the Lifecycle interface. When lifecycle methods on this class are called it will try to invoke the same methods on the registered instances.

Components that internally owns other components that has a lifecycle can use this to control them as well.


Constructor Summary
LifeSupport()
           
 
Method Summary
<T> T
add(T instance)
          Add a new Lifecycle instance.
 void addLifecycleListener(LifecycleListener listener)
           
 void clear()
          Shutdown and throw away all the current instances.
 void dump(org.neo4j.kernel.impl.util.StringLogger logger)
           
 Iterable<Lifecycle> getLifecycleInstances()
           
 LifecycleStatus getStatus()
           
 void init()
          Initialize all registered instances, transitioning from status NONE to STOPPED.
 boolean remove(Object instance)
           
 void removeLifecycleListener(LifecycleListener listener)
           
 void restart(Lifecycle instance)
          Restart an individual instance.
 void shutdown()
          Shutdown all registered instances, transitioning from either STARTED or STOPPED to SHUTDOWN.
 void start()
          Start all registered instances, transitioning from STOPPED to STARTED.
 void stop()
          Stop all registered instances, transitioning from STARTED to STOPPED.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LifeSupport

public LifeSupport()
Method Detail

init

public void init()
          throws LifecycleException
Initialize all registered instances, transitioning from status NONE to STOPPED.

If transition fails, then it goes to STOPPED and then SHUTDOWN, so it cannot be restarted again.

Specified by:
init in interface Lifecycle
Throws:
LifecycleException

start

public void start()
           throws LifecycleException
Start all registered instances, transitioning from STOPPED to STARTED.

If it was previously not initialized, it will be initialized first.

If any instance fails to start, the already started instances will be stopped, so that the overall status is STOPPED.

Specified by:
start in interface Lifecycle
Throws:
LifecycleException

stop

public void stop()
          throws LifecycleException
Stop all registered instances, transitioning from STARTED to STOPPED.

If any instance fails to stop, the rest of the instances will still be stopped, so that the overall status is STOPPED.

Specified by:
stop in interface Lifecycle
Throws:
Exception
LifecycleException

shutdown

public void shutdown()
              throws LifecycleException
Shutdown all registered instances, transitioning from either STARTED or STOPPED to SHUTDOWN.

If any instance fails to shutdown, the rest of the instances will still be shut down, so that the overall status is SHUTDOWN.

Specified by:
shutdown in interface Lifecycle
Throws:
Exception
LifecycleException

restart

public void restart(Lifecycle instance)
             throws LifecycleException,
                    IllegalArgumentException
Restart an individual instance. All instances "after" the instance will be stopped first, so that they don't try to use it during the restart. A restart is effectively a stop followed by a start.

Parameters:
instance -
Throws:
Throwable - if any start or stop fails
IllegalArgumentException - if instance is not registered
LifecycleException

add

public <T> T add(T instance)
      throws LifecycleException
Add a new Lifecycle instance. It will immediately be transitioned to the state of this LifeSupport.

Type Parameters:
T - type of the instance
Parameters:
instance - the Lifecycle instance to add
Returns:
the instance itself
Throws:
LifecycleException - if the instance could not be transitioned properly

remove

public boolean remove(Object instance)

getLifecycleInstances

public Iterable<Lifecycle> getLifecycleInstances()

clear

public void clear()
Shutdown and throw away all the current instances. After this you can add new instances. This method does not change the status of the LifeSupport (i.e. if it was started it will remain started)


getStatus

public LifecycleStatus getStatus()

addLifecycleListener

public void addLifecycleListener(LifecycleListener listener)

removeLifecycleListener

public void removeLifecycleListener(LifecycleListener listener)

dump

public void dump(org.neo4j.kernel.impl.util.StringLogger logger)


Copyright © 2002-2013 The Neo4j Graph Database Project. All Rights Reserved.