org.jvnet.hk2.component
Class AbstractRunLevelService<T>

java.lang.Object
  extended by org.jvnet.hk2.component.AbstractRunLevelService<T>
All Implemented Interfaces:
InhabitantListener, RunLevelService<T>

public abstract class AbstractRunLevelService<T>
extends Object
implements RunLevelService<T>, InhabitantListener

A default implementation for the RunLevelService that component provides can derive from to provide their own component-related lifecycle.

The targetScope is a placeholder type to represent a sub-component set of RunLevel-gated services. It can be anything of the caller's choosing as long as it is kept unique and does not clash with the default internal run level service.

Author:
Jeff Trent

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jvnet.hk2.component.InhabitantListener
InhabitantListener.EventType
 
Constructor Summary
protected AbstractRunLevelService(Class<?> targetScope)
           
 
Method Summary
protected  DefaultRunLevelService getDefault()
           
protected  RunLevelService<T> getDelegate()
           
 RunLevelState<T> getState()
          Returns the current state of this RunLevelService instance.
 boolean inhabitantChanged(InhabitantListener.EventType eventType, Inhabitant<?> inhabitant)
          Called when the inhabitant has changed.
 void interrupt()
          Causes this RunLevelService to attempt to stop any in-flight proceedTo() operation.
 void interrupt(int runLevel)
          Same as RunLevelService.interrupt(), with the option to immediately perform a RunLevelService.proceedTo(int) following the interrupt.
 void proceedTo(int runLevel)
          Causes this RunLevelService to move to the specified run level for all RunLevel instances (identified by scope), orchestrating the appropriate lifecycle events based on the given implementation strategy.
 void setInhabitantActivator(InhabitantActivator activator)
          Overrides the default behavior of getting the inhabitant activator from the habitat to use a stand-in activator instead.
 void setInhabitantSorter(InhabitantSorter sorter)
          Overrides the default behavior of getting the inhabitant sorter from the habitat to use a stand-in sorter instead.
 void setListener(RunLevelListener listener)
          Overrides the default behavior of getting all listeners from the habitat to use a stand-in listener instead.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractRunLevelService

protected AbstractRunLevelService(Class<?> targetScope)
Method Detail

toString

public String toString()
Overrides:
toString in class Object

getDelegate

protected RunLevelService<T> getDelegate()

getDefault

protected DefaultRunLevelService getDefault()

setListener

public void setListener(RunLevelListener listener)
Overrides the default behavior of getting all listeners from the habitat to use a stand-in listener instead. If set to null, the default behavior will be restored.

Parameters:
listener - the alternative, stand-in listener

setInhabitantSorter

public void setInhabitantSorter(InhabitantSorter sorter)
Overrides the default behavior of getting the inhabitant sorter from the habitat to use a stand-in sorter instead. If set to null, the default behavior will be restored.

Parameters:
sorter - the alternative, stand-in sorter

setInhabitantActivator

public void setInhabitantActivator(InhabitantActivator activator)
Overrides the default behavior of getting the inhabitant activator from the habitat to use a stand-in activator instead. If set to null, the default behavior will be restored.

Parameters:
activator - the alternative, stand-in activator

getState

public RunLevelState<T> getState()
Description copied from interface: RunLevelService
Returns the current state of this RunLevelService instance.

Specified by:
getState in interface RunLevelService<T>

proceedTo

public void proceedTo(int runLevel)
Description copied from interface: RunLevelService
Causes this RunLevelService to move to the specified run level for all RunLevel instances (identified by scope), orchestrating the appropriate lifecycle events based on the given implementation strategy. See the javadoc for each implementation for specific details.

If the RunLevel specified is the same as the current RunLevel then the RunLevelService may return immediately.

Note that the underlying implementation may perform this operation asynchronously. Implementors who choose the asynchronous approach are expected to treat a subsequent proceedTo(newRunLevel) call as an implicit cancellation of any currently running proceedTo() that is running on one or more managed threads. Again, see the javadoc for each implementation for details.

Specified by:
proceedTo in interface RunLevelService<T>
Parameters:
runLevel - the run level to move to.

interrupt

public void interrupt()
Description copied from interface: RunLevelService
Causes this RunLevelService to attempt to stop any in-flight proceedTo() operation. This call will not have any any affect if there is no current proceedTo() operation in progress.

See the javadoc for each implementation for specific details

Specified by:
interrupt in interface RunLevelService<T>

interrupt

public void interrupt(int runLevel)
Description copied from interface: RunLevelService
Same as RunLevelService.interrupt(), with the option to immediately perform a RunLevelService.proceedTo(int) following the interrupt.

Specified by:
interrupt in interface RunLevelService<T>
Parameters:
runLevel - the run level to move to following the interrupt

inhabitantChanged

public boolean inhabitantChanged(InhabitantListener.EventType eventType,
                                 Inhabitant<?> inhabitant)
Description copied from interface: InhabitantListener
Called when the inhabitant has changed.

Specified by:
inhabitantChanged in interface InhabitantListener
Returns:
callee should return true to continue receiving notification, false otherwise


Copyright © 2011 Oracle Corporation. All Rights Reserved.