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, Controller, org.jboss.util.JBossInterface
Direct Known Subclasses:
ScopedController

public class AbstractController
extends org.jboss.util.JBossObject
implements Controller

Abstract controller.

Version:
$Revision: 64920 $
Author:
Adrian Brock

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)
           
 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
 void enableOnDemand(ControllerContext context)
          Enable an on demand context
protected  void enableOnDemand(ControllerContext context, boolean trace)
          Enable an on demand context
 Set<ControllerContext> getAllContexts()
           
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
 Set<ControllerContext> getContextsByState(ControllerState state)
          Get the contexts in certain state
 Set<AbstractController> getControllers()
           
protected  Set<CallbackItem<?>> getDependencyCallbacks(ControllerContext context, boolean isInstallPhase)
          Get calbacks from context.
 ControllerContext getInstalledContext(Object name)
          Get an installed context
 Set<ControllerContext> getNotInstalled()
          Get the contexts not installed
protected  AbstractController getParentController()
           
protected  ControllerContext getRegisteredControllerContext(Object name, boolean mustExist)
          Get a registered context
 List<ControllerState> getStates()
          Get the states.
protected  void handleInstallLifecycleCallbacks(ControllerContext context, ControllerState state)
           
protected  void handleLifecycleCallbacks(ControllerContext context, ControllerState state, boolean install)
           
protected  void handleUninstallLifecycleCallbacks(ControllerContext context, ControllerState state)
           
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
protected  boolean isAutowireCandidate(ControllerContext context)
          Can we use this context for autowiring.
 boolean isShutdown()
          Whether the controller is shutdown
protected  void lockRead()
          Lock for read
protected  void lockWrite()
          Lock for write
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)
           
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
protected  void setParentController(AbstractController parentController)
           
 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)
           
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

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

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

protected AbstractController getParentController()

setParentController

protected void setParentController(AbstractController parentController)

getControllers

public Set<AbstractController> getControllers()

addController

public boolean addController(AbstractController controller)

removeController

public boolean removeController(AbstractController controller)

isActive

public boolean isActive()
Whether the controller has contexts

Returns:
true when there are registered contexts

getAllContexts

public Set<ControllerContext> getAllContexts()

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 List<ControllerState> getStates()
Description copied from interface: Controller
Get the states.

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

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

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)

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

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
Throws:
Throwable

handleUninstallLifecycleCallbacks

protected void handleUninstallLifecycleCallbacks(ControllerContext context,
                                                 ControllerState state)
                                          throws Throwable
Throws:
Throwable

handleLifecycleCallbacks

protected void handleLifecycleCallbacks(ControllerContext context,
                                        ControllerState state,
                                        boolean install)
                                 throws Throwable
Throws:
Throwable

isAutowireCandidate

protected boolean isAutowireCandidate(ControllerContext context)
Can we use this context for autowiring.

Parameters:
context - the context
Returns:
true if context could be used for autowiring

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


Copyright © 2008 JBoss Inc.. All Rights Reserved.