org.jboss.dependency.plugins
Class AbstractController

java.lang.Object
  extended by org.jboss.util.JBossObject
      extended by org.jboss.dependency.plugins.AbstractController
All Implemented Interfaces:
Cloneable, Iterable<ControllerState>, AbstractControllerMBean, Controller, ControllerStateModel, GraphController, org.jboss.util.JBossInterface
Direct Known Subclasses:
ScopedController

public class AbstractController
extends org.jboss.util.JBossObject
implements Controller, ControllerStateModel, GraphController, AbstractControllerMBean

Abstract controller.

Version:
$Revision: 90317 $
Author:
Adrian Brock, Ales Justin

Field Summary
 
Fields inherited from class org.jboss.util.JBossObject
hashCode, log, toString
 
Constructor Summary
AbstractController()
          Create an abstract controller
 
Method Summary
 void addAlias(Object alias, Object original)
          Add alias.
protected
<T> void
addCallback(Object name, boolean isInstallPhase, CallbackItem<T> callback)
          Add callback item under demand name.
 boolean addController(AbstractController controller)
          Add child controller.
 void addState(ControllerState state, ControllerState before)
          Add a state.
protected  boolean advance(ControllerContext context)
          Whether we should advance the context
 void change(ControllerContext context, ControllerState state)
          Change a context to the given state
protected  void change(ControllerContext context, ControllerState state, boolean trace)
          Change a context's state
 void checkShutdown()
          Check whether the controller is shutdown
protected  Map<ControllerState,ControllerContextAction> createAliasActions()
          Create alias controller context actions.
 void enableOnDemand(ControllerContext context)
          Enable an on demand context
protected  void enableOnDemand(ControllerContext context, boolean trace)
          Enable an on demand context
 Set<ControllerContext> getAllContexts()
          Get all the contexts.
protected  Set<CallbackItem<?>> getCallbacks(Object name, boolean isInstallPhase)
          Get the matching callbacks.
protected  Collection<Class<?>> getClassesImplemented(Object target)
          Get implemented classes.
 ControllerContext getContext(Object name, ControllerState state)
          Get a context
 ControllerContext getContext(Object name, ControllerState state, SearchInfo info)
          Get the context.
protected  void getContexts(Object name, Set<ControllerContext> contexts)
          Get all contexts by name, check child controllers as well.
 Set<ControllerContext> getContextsByState(ControllerState state)
          Get the contexts in certain state
 Set<AbstractController> getControllers()
          Get child controllers.
protected  Set<CallbackItem<?>> getDependencyCallbacks(ControllerContext context, boolean isInstallPhase)
          Get calbacks from context.
protected  Executor getExecutionEnvironment()
          Get the executor internal w/o security check.
 Executor getExecutor()
          Get the executor.
protected  String getId()
          Get controller id - impl detail.
 ControllerContext getInstalledContext(Object name)
          Get an installed context
 ControllerState getNextState(ControllerState state)
          Get next state from state param or null if state param is the last.
 Set<ControllerContext> getNotInstalled()
          Get the contexts not installed
 AbstractController getParentController()
          Get the parent controller.
 ControllerState getPreviousState(ControllerState state)
          Get previous state from state param or null if state param is the first.
protected  ControllerContext getRegisteredControllerContext(Object name, boolean mustExist)
          Get a registered context
protected  ControllerState getState(int index)
          Get the controller state form index.
protected  int getStateIndex(ControllerState state)
          Get the state index.
protected  int getStateIndex(ControllerState state, boolean allowNotFound)
          Get the state index.
 ControllerStateModel getStates()
          Get the states model.
protected  void handleInstallLifecycleCallbacks(ControllerContext context, ControllerState state)
          Handle install lifecycle callbacks.
protected  void handleLifecycleCallbacks(ControllerContext context, ControllerState state, boolean install)
          Handle lifecycle callbacks.
protected  void handleUninstallLifecycleCallbacks(ControllerContext context, ControllerState state)
          Handle uninstall lifecycle callbacks.
protected  boolean incrementState(ControllerContext context, boolean trace)
          Increment state
 void install(ControllerContext context)
          Install a context
protected  void install(ControllerContext context, boolean trace)
          Install a context
protected  void install(ControllerContext context, ControllerState fromState, ControllerState toState)
          Install a context
 boolean isActive()
          Whether the controller has contexts
 boolean isAfterState(ControllerState state, ControllerState reference)
          Is state param after reference state param.
 boolean isBeforeState(ControllerState state, ControllerState reference)
          Is state param before reference state param.
 boolean isCollectStats()
          Get the collectStats.
 boolean isShutdown()
          Whether the controller is shutdown
 Iterator<ControllerState> iterator()
           
 ListIterator<ControllerState> listIteraror()
          Get the list iterator.
 String listStateTimes(boolean details)
          List the state times
protected  void lockRead()
          Lock for read
protected  void lockWrite()
          Lock for write
protected  void preAliasInstall(ControllerContext aliasContext)
          Apply pre install - e.g.
protected  void registerControllerContext(ControllerContext context)
          Register a context and all its aliases
protected  void registerControllerContext(Object name, ControllerContext context)
          Register a context
 void removeAlias(Object alias)
          Remove alias.
protected
<T> void
removeCallback(Object name, boolean isInstallPhase, CallbackItem<T> callback)
          Remove callback item under demand name.
 boolean removeController(AbstractController controller)
          Remove child controller.
protected  void resolveCallbacks(ControllerContext context, ControllerState state, boolean isInstallPhase)
          Resolve callback items.
protected  void resolveCallbacks(Set<CallbackItem<?>> callbacks, ControllerState state, boolean execute, boolean isInstallPhase, boolean type)
          Resolve callbacks.
protected  void resolveContexts(boolean trace)
          Resolve unresolved contexts
protected  boolean resolveContexts(ControllerState fromState, ControllerState toState, boolean trace)
          Resolve contexts
protected  Set<ControllerContext> resolveContexts(Set<ControllerContext> contexts, ControllerState state, boolean trace)
          Resolve contexts
 void setCollectStats(boolean collectStats)
          Set the collectStats.
 void setExecutor(Executor executor)
          Set the executor.
protected  void setParentController(AbstractController parentController)
          Set the parent controller.
 void shutdown()
          Shutdown the controller
protected  void traverseClass(Class<?> clazz, Set<Class<?>> classes)
          Recurse over classes.
protected  void uninstall(ControllerContext context, ControllerState fromState, ControllerState toState)
          Uninstall a context
 ControllerContext uninstall(Object name)
          Uninstall a context
protected  ControllerContext uninstall(Object name, int level)
          Uninstall the context.
protected  void uninstallContext(ControllerContext context, boolean trace)
          Uninstall a context
protected  void uninstallContext(ControllerContext context, ControllerState toState, boolean trace)
          Uninstall a context

This method must be invoked with the write lock taken

protected  void unlockRead()
          Unlock for read
protected  void unlockWrite()
          Unlock for write
protected  void unregisterControllerContext(ControllerContext context)
          Unregister a context and all its aliases
protected  void unregisterControllerContext(Object name)
          Unregister a context
 
Methods inherited from class org.jboss.util.JBossObject
cacheGetHashCode, cacheToString, clone, equals, flushJBossObjectCache, getClassShortName, getHashCode, hashCode, list, notEqual, toShortString, toShortString, toString, toString, toStringImplementation
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jboss.util.JBossInterface
clone, toShortString, toShortString
 

Constructor Detail

AbstractController

public AbstractController()
Create an abstract controller

Method Detail

setExecutor

public void setExecutor(Executor executor)
Set the executor.

Parameters:
executor - the executor

getExecutor

public Executor getExecutor()
Get the executor.

Returns:
the executor

getExecutionEnvironment

protected Executor getExecutionEnvironment()
Get the executor internal w/o security check.

Returns:
the executor

isShutdown

public boolean isShutdown()
Description copied from interface: Controller
Whether the controller is shutdown

Specified by:
isShutdown in interface Controller
Returns:
true when shutdown

checkShutdown

public void checkShutdown()
Check whether the controller is shutdown

Throws:
IllegalStateException - when already shutdown

shutdown

public void shutdown()
Description copied from interface: Controller
Shutdown the controller

Specified by:
shutdown in interface Controller

isCollectStats

public boolean isCollectStats()
Get the collectStats.

Returns:
the collectStats.

setCollectStats

public void setCollectStats(boolean collectStats)
Set the collectStats.

Parameters:
collectStats - the collectStats.

listStateTimes

public String listStateTimes(boolean details)
Description copied from interface: AbstractControllerMBean
List the state times

Specified by:
listStateTimes in interface AbstractControllerMBean
Parameters:
details - whether to show details
Returns:
the deployer times

addState

public void addState(ControllerState state,
                     ControllerState before)
Description copied from interface: Controller
Add a state.

Specified by:
addState in interface Controller
Parameters:
state - the state to add
before - the state to add before or null to add to the end

getParentController

public AbstractController getParentController()
Get the parent controller.

Returns:
the parent controller

setParentController

protected void setParentController(AbstractController parentController)
Set the parent controller.

Parameters:
parentController - the parent controller

getControllers

public Set<AbstractController> getControllers()
Get child controllers.

Returns:
the child controllers

addController

public boolean addController(AbstractController controller)
Add child controller.

Parameters:
controller - the child controller
Returns:
true if equal controller has been already added, see Set.add usage

removeController

public boolean removeController(AbstractController controller)
Remove child controller.

Parameters:
controller - the child controller
Returns:
true if equal controller was present, see Set.remove usage

isActive

public boolean isActive()
Whether the controller has contexts

Returns:
true when there are registered contexts

getContext

public ControllerContext getContext(Object name,
                                    ControllerState state,
                                    SearchInfo info)
Description copied from interface: GraphController
Get the context.

Specified by:
getContext in interface GraphController
Parameters:
name - the context name
state - the required state
info - the seatch info
Returns:
found context or null if not available

getAllContexts

public Set<ControllerContext> getAllContexts()
Get all the contexts. In state decending order.

Returns:
all contexts

getContext

public ControllerContext getContext(Object name,
                                    ControllerState state)
Description copied from interface: Controller
Get a context

Specified by:
getContext in interface Controller
Parameters:
name - the name of the component
state - the state (pass null for any state)
Returns:
the context

getInstalledContext

public ControllerContext getInstalledContext(Object name)
Description copied from interface: Controller
Get an installed context

Specified by:
getInstalledContext in interface Controller
Parameters:
name - the name of the component
Returns:
the context

getNotInstalled

public Set<ControllerContext> getNotInstalled()
Description copied from interface: Controller
Get the contexts not installed

Specified by:
getNotInstalled in interface Controller
Returns:
Set

getStates

public ControllerStateModel getStates()
Description copied from interface: Controller
Get the states model.

Specified by:
getStates in interface Controller
Returns:
the states in order

getContextsByState

public Set<ControllerContext> getContextsByState(ControllerState state)
Description copied from interface: Controller
Get the contexts in certain state

Specified by:
getContextsByState in interface Controller
Parameters:
state - controller state to get contexts for
Returns:
set of contexts in certain state

install

public void install(ControllerContext context)
             throws Throwable
Description copied from interface: Controller
Install a context

Specified by:
install in interface Controller
Parameters:
context - the context
Throws:
Throwable - for any error

change

public void change(ControllerContext context,
                   ControllerState state)
            throws Throwable
Description copied from interface: Controller
Change a context to the given state

Specified by:
change in interface Controller
Parameters:
context - the context
state - the state
Throws:
Throwable - for any error

enableOnDemand

public void enableOnDemand(ControllerContext context)
                    throws Throwable
Description copied from interface: Controller
Enable an on demand context

Specified by:
enableOnDemand in interface Controller
Parameters:
context - the context
Throws:
Throwable - for any error

uninstall

public ControllerContext uninstall(Object name)
Description copied from interface: Controller
Uninstall a context

Specified by:
uninstall in interface Controller
Parameters:
name - the name of the component
Returns:
the context

getId

protected String getId()
Get controller id - impl detail. It should be unique.

Returns:
controller's id

addAlias

public void addAlias(Object alias,
                     Object original)
              throws Throwable
Description copied from interface: Controller
Add alias.

Specified by:
addAlias in interface Controller
Parameters:
alias - the alias to add
original - original name
Throws:
Throwable - for any error

createAliasActions

protected Map<ControllerState,ControllerContextAction> createAliasActions()
Create alias controller context actions.

Returns:
the alias controller context actions

preAliasInstall

protected void preAliasInstall(ControllerContext aliasContext)
Apply pre install - e.g. scope key in scoped controller.

Parameters:
aliasContext - the new alias context

removeAlias

public void removeAlias(Object alias)
Description copied from interface: Controller
Remove alias.

Specified by:
removeAlias in interface Controller
Parameters:
alias - alias to remove

uninstall

protected ControllerContext uninstall(Object name,
                                      int level)
Uninstall the context.

Parameters:
name - the context name
level - the controller level
Returns:
uninstalled controller context

install

protected void install(ControllerContext context,
                       boolean trace)
                throws Throwable
Install a context

Parameters:
context - the context
trace - whether trace is enabled
Throws:
Throwable - for any error

change

protected void change(ControllerContext context,
                      ControllerState state,
                      boolean trace)
               throws Throwable
Change a context's state

Parameters:
context - the context
state - the required state
trace - whether trace is enabled
Throws:
Throwable - for any error

enableOnDemand

protected void enableOnDemand(ControllerContext context,
                              boolean trace)
                       throws Throwable
Enable an on demand context

Parameters:
context - the context
trace - whether trace is enabled
Throws:
Throwable - for any error

incrementState

protected boolean incrementState(ControllerContext context,
                                 boolean trace)
Increment state

This method must be invoked with the write lock taken.

Parameters:
context - the context
trace - whether trace is enabled
Returns:
whether the suceeded

resolveContexts

protected void resolveContexts(boolean trace)
Resolve unresolved contexts

This method must be invoked with the write lock taken

Parameters:
trace - whether trace is enabled

resolveContexts

protected boolean resolveContexts(ControllerState fromState,
                                  ControllerState toState,
                                  boolean trace)
Resolve contexts

This method must be invoked with the write lock taken

Parameters:
fromState - the from state
toState - the to state
trace - whether trace is enabled
Returns:
true when there were resolutions

resolveContexts

protected Set<ControllerContext> resolveContexts(Set<ControllerContext> contexts,
                                                 ControllerState state,
                                                 boolean trace)
Resolve contexts

This method must be invoked with the write lock taken

Parameters:
contexts - the contexts
state - the state
trace - whether trace is enabled
Returns:
the set of resolved contexts

uninstallContext

protected void uninstallContext(ControllerContext context,
                                ControllerState toState,
                                boolean trace)
Uninstall a context

This method must be invoked with the write lock taken

Parameters:
context - the context to uninstall
toState - the target state
trace - whether trace is enabled

uninstallContext

protected void uninstallContext(ControllerContext context,
                                boolean trace)
Uninstall a context

This method must be invoked with the write lock taken

Parameters:
context - the context to uninstall
trace - whether trace is enabled

getContexts

protected void getContexts(Object name,
                           Set<ControllerContext> contexts)
Get all contexts by name, check child controllers as well.

Parameters:
name - the name of the context
contexts - found contexts

addCallback

protected <T> void addCallback(Object name,
                               boolean isInstallPhase,
                               CallbackItem<T> callback)
Add callback item under demand name.

Type Parameters:
T - the callback item type
Parameters:
name - demand name
isInstallPhase - install or uninstall phase
callback - callback item

removeCallback

protected <T> void removeCallback(Object name,
                                  boolean isInstallPhase,
                                  CallbackItem<T> callback)
Remove callback item under demand name.

Type Parameters:
T - the callback item type
Parameters:
name - demand name
isInstallPhase - install or uninstall phase
callback - callback item

getDependencyCallbacks

protected Set<CallbackItem<?>> getDependencyCallbacks(ControllerContext context,
                                                      boolean isInstallPhase)
Get calbacks from context.

Parameters:
context - current context
isInstallPhase - install or uninstall phase
Returns:
callback items from dependency info

getCallbacks

protected Set<CallbackItem<?>> getCallbacks(Object name,
                                            boolean isInstallPhase)
Get the matching callbacks.

Parameters:
name - demand name
isInstallPhase - install or uninstall phase
Returns:
all matching registered callbacks or empty set if no such item

resolveCallbacks

protected void resolveCallbacks(Set<CallbackItem<?>> callbacks,
                                ControllerState state,
                                boolean execute,
                                boolean isInstallPhase,
                                boolean type)
Resolve callbacks.

Parameters:
callbacks - the callbacks
state - current context state
execute - do execute callback
isInstallPhase - install or uninstall phase
type - install or uninstall type

resolveCallbacks

protected void resolveCallbacks(ControllerContext context,
                                ControllerState state,
                                boolean isInstallPhase)
Resolve callback items.

Parameters:
context - current context
state - current context state
isInstallPhase - install or uninstall phase

handleInstallLifecycleCallbacks

protected void handleInstallLifecycleCallbacks(ControllerContext context,
                                               ControllerState state)
                                        throws Throwable
Handle install lifecycle callbacks.

Parameters:
context - the context
state - the state
Throws:
Throwable - for any error

handleUninstallLifecycleCallbacks

protected void handleUninstallLifecycleCallbacks(ControllerContext context,
                                                 ControllerState state)
                                          throws Throwable
Handle uninstall lifecycle callbacks.

Parameters:
context - the context
state - the state
Throws:
Throwable - for any error

handleLifecycleCallbacks

protected void handleLifecycleCallbacks(ControllerContext context,
                                        ControllerState state,
                                        boolean install)
                                 throws Throwable
Handle lifecycle callbacks.

Parameters:
context - the context
state - the state
install - is it install or uninstall
Throws:
Throwable - for any error

getClassesImplemented

protected Collection<Class<?>> getClassesImplemented(Object target)
Get implemented classes.

Parameters:
target - target value / bean
Returns:
collection of implementing classes by target

traverseClass

protected void traverseClass(Class<?> clazz,
                             Set<Class<?>> classes)
Recurse over classes.

Parameters:
clazz - current class
classes - classes holder set

install

protected void install(ControllerContext context,
                       ControllerState fromState,
                       ControllerState toState)
                throws Throwable
Install a context

This method must be invoked with NO locks taken

Parameters:
context - the context
fromState - the from state
toState - the toState
Throws:
Throwable - for any error

uninstall

protected void uninstall(ControllerContext context,
                         ControllerState fromState,
                         ControllerState toState)
Uninstall a context

This method must be invoked with NO locks taken

Parameters:
context - the context
fromState - the from state
toState - the to state

advance

protected boolean advance(ControllerContext context)
Whether we should advance the context

This method must be invoked with the write lock taken

Parameters:
context - the context
Returns:
true when we should advance the context

lockRead

protected void lockRead()
Lock for read


unlockRead

protected void unlockRead()
Unlock for read


lockWrite

protected void lockWrite()
Lock for write


unlockWrite

protected void unlockWrite()
Unlock for write


getRegisteredControllerContext

protected ControllerContext getRegisteredControllerContext(Object name,
                                                           boolean mustExist)
Get a registered context

This method should be invoked with at least the read lock taken

Parameters:
name - the name with which to register it
mustExist - whether to throw an error when the context does not exist
Returns:
context the registered context
Throws:
IllegalArgumentException - for null parameters
IllegalStateException - if the context if must exist is true and the context does not exist

registerControllerContext

protected void registerControllerContext(ControllerContext context)
Register a context and all its aliases

This method must be invoked with the write lock taken

Parameters:
context - the context to register
Throws:
IllegalArgumentException - for null parameters
IllegalStateException - if the context is already registered with that name or alias

unregisterControllerContext

protected void unregisterControllerContext(ControllerContext context)
Unregister a context and all its aliases

This method must be invoked with the write lock taken

Parameters:
context - the context
Throws:
IllegalArgumentException - for null parameters
IllegalStateException - if the context is not registered

registerControllerContext

protected void registerControllerContext(Object name,
                                         ControllerContext context)
Register a context

This method must be invoked with the write lock taken

NOTE: You probably want to use the registerControllerContext(ControllerContext)

Parameters:
name - the name with which to register it
context - the context to register
Throws:
IllegalArgumentException - for null parameters
IllegalStateException - if the context is already registered with that name

unregisterControllerContext

protected void unregisterControllerContext(Object name)
Unregister a context

This method must be invoked with the write lock taken

NOTE: You probably want to use the unregisterControllerContext(ControllerContext)

Parameters:
name - the name it was registered with
Throws:
IllegalArgumentException - for null parameters

listIteraror

public ListIterator<ControllerState> listIteraror()
Description copied from interface: ControllerStateModel
Get the list iterator. The list iterator cursor should be pointing to the last state. Since the usage of this list iterator is mostly to iterate over the states in reverted order.

Specified by:
listIteraror in interface ControllerStateModel
Returns:
list iterator

getPreviousState

public ControllerState getPreviousState(ControllerState state)
Description copied from interface: ControllerStateModel
Get previous state from state param or null if state param is the first. Throw exception if state is not recognized.

Specified by:
getPreviousState in interface ControllerStateModel
Parameters:
state - the current state
Returns:
previous state

getNextState

public ControllerState getNextState(ControllerState state)
Description copied from interface: ControllerStateModel
Get next state from state param or null if state param is the last. Throw exception if state is not recognized.

Specified by:
getNextState in interface ControllerStateModel
Parameters:
state - the current state
Returns:
next state

isBeforeState

public boolean isBeforeState(ControllerState state,
                             ControllerState reference)
Description copied from interface: ControllerStateModel
Is state param before reference state param.

Specified by:
isBeforeState in interface ControllerStateModel
Parameters:
state - the state we are checking
reference - the state we are checking against
Returns:
true if state is before reference

isAfterState

public boolean isAfterState(ControllerState state,
                            ControllerState reference)
Description copied from interface: ControllerStateModel
Is state param after reference state param.

Specified by:
isAfterState in interface ControllerStateModel
Parameters:
state - the state we are checking
reference - the state we are checking against
Returns:
true if state is after reference

iterator

public Iterator<ControllerState> iterator()
Specified by:
iterator in interface Iterable<ControllerState>

getStateIndex

protected int getStateIndex(ControllerState state)
Get the state index.

Parameters:
state - the state
Returns:
state index

getStateIndex

protected int getStateIndex(ControllerState state,
                            boolean allowNotFound)
Get the state index. You have allow not found flag in case error state is passed in, which is legal.

Parameters:
state - the state
allowNotFound - allow not found state
Returns:
state index

getState

protected ControllerState getState(int index)
Get the controller state form index.

Parameters:
index - the state index
Returns:
controller state


Copyright © 2009 JBoss, a division of Red Hat, Inc.. All Rights Reserved.