org.araneaframework.core
Class BaseComponent

java.lang.Object
  extended by org.araneaframework.core.BaseComponent
All Implemented Interfaces:
Serializable, Component
Direct Known Subclasses:
BaseApplicationComponent, BaseService, StandardServletServiceAdapterComponent

public class BaseComponent
extends Object
implements Component

The base class for all Aranea components. Base entities do not make a Composite pattern and only provide some very basic services (mainly syncronization and messaging service)

Author:
"Toomas Römer" , Jevgeni Kabanov (ekabanov at araneaframework dot org)
See Also:
Serialized Form

Nested Class Summary
protected  class BaseComponent.ComponentImpl
           
 
Nested classes/interfaces inherited from interface org.araneaframework.Component
Component.Interface
 
Constructor Summary
BaseComponent()
           
 
Method Summary
protected  void _addComponent(Object key, Component component, Environment env)
          Adds a child component to this component with the key and initilizes it with the specified Environment env.
protected  void _addComponent(Object key, Component component, Scope scope, Environment env)
          Adds a child component to this component with the key and initilizes it with the specified Environment env.
protected  void _checkCall()
          Checks if this component was initialized.
protected  void _disableComponent(Object key)
          Disables the child component with the specified key.
protected  void _enableComponent(Object key)
          Enables a disabled child component with the specified key.
protected  void _endCall()
          Decrements the call count.
protected  void _endWaitingCall()
          Decrements internal callcount counter.
protected  Map _getChildren()
          Returns the children of this component.
 Component.Interface _getComponent()
          The factory method returning the implementation of the Component.
protected  Map _getDisabledChildren()
          Returns the children of this component.
protected  void _propagate(Message message)
          Forwards the message to the component and to all of its children components.
protected  void _relocateComponent(Composite parent, Environment newEnv, Object keyFrom, Object keyTo)
          Relocates parent's child with keyFrom to this BaseComponent with a new key keyTo.
protected  void _removeComponent(Object key)
          Removes the child component with the specified key from the children and calls destroy on it.
protected  void _setEnvironment(Environment env)
          Sets the environment of this component to env.
protected  void _setScope(Scope scope)
          Sets the scope for this component.
protected  void _startCall()
          Checks if a call is valid (component is in the required state), increments the call count.
protected  void _startWaitingCall()
          Used for starting a call that is a re-entrant call.
protected  void _strictCheckCall()
          Checks if this component is currently alive.
protected  void _strictStartCall()
           
protected  void _waitNoCall()
          Waits until no call is made to the component.
protected  void destroy()
          Destroy callback.
protected  void disable()
          Disables the component.
protected  void enable()
          Enables the component.
 Environment getEnvironment()
          Provides access to the Environment of this Component.
 Scope getScope()
          Provides the scope of this Component.
protected  void handleException(Exception e)
          Handles any given exception.
protected  void init()
          Init callback.
 boolean isAlive()
          Specifies whether this Component is alive.
 boolean isDead()
          Specifies whether the component is dead.
 boolean isInitialized()
          Gets whether the component has been initialized.
protected  void propagate(Message message)
          Forwards the message to the component and to all of its children components.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseComponent

public BaseComponent()
Method Detail

_getComponent

public Component.Interface _getComponent()
Description copied from interface: Component
The factory method returning the implementation of the Component.

Specified by:
_getComponent in interface Component
Returns:
the implementation of the Component.

init

protected void init()
             throws Exception
Init callback. Gets called when the component is initilized.

Throws:
Exception - Any runtime exception that may occur.

destroy

protected void destroy()
                throws Exception
Destroy callback. Gets called when the component is destroyed.

Throws:
Exception - Any runtime exception that may occur.

disable

protected void disable()
                throws Exception
Disables the component.

Throws:
Exception - Any runtime exception that may occur.

enable

protected void enable()
               throws Exception
Enables the component.

Throws:
Exception - Any runtime exception that may occur.

propagate

protected void propagate(Message message)
                  throws Exception
Forwards the message to the component and to all of its children components.

Parameters:
message - A message to forward.
Throws:
Exception - Any runtime exception that may occur.

handleException

protected void handleException(Exception e)
                        throws Exception
Handles any given exception.

Parameters:
e - The exception that occured.
Throws:
Exception - Any runtime exception that may occur during error handling.

getEnvironment

public Environment getEnvironment()
Description copied from interface: Component
Provides access to the Environment of this Component.

Specified by:
getEnvironment in interface Component
Returns:
the Environment of the Component.

getScope

public Scope getScope()
Description copied from interface: Component
Provides the scope of this Component. The Scope is related to Path and the idea behind it is quite similar.

Specified by:
getScope in interface Component
Returns:
the scope of the Component

isInitialized

public boolean isInitialized()
Gets whether the component has been initialized. "Initialized" means that the init() method has been called.

Returns:
true, if the component has been initialized.

isAlive

public boolean isAlive()
Description copied from interface: Component
Specifies whether this Component is alive. If it is alive then it means that the Component has been initialized and is not destroyed yet.

Specified by:
isAlive in interface Component
Returns:
true, if this component has been initialized and is not destroyed. Otherwise, false.

isDead

public boolean isDead()
Specifies whether the component is dead. It means that the destroy() method has been called.

Returns:
true, if the component has been destroyed.

_setEnvironment

protected void _setEnvironment(Environment env)
Sets the environment of this component to env.

Parameters:
env - The new Envrionment for this component.

_setScope

protected void _setScope(Scope scope)
Sets the scope for this component.

Parameters:
scope - the new scope to identify this component.
Since:
1.1

_waitNoCall

protected void _waitNoCall()
                    throws InterruptedException
Waits until no call is made to the component. Used to synchronize calls to the component.

Throws:
InterruptedException

_startCall

protected void _startCall()
                   throws IllegalStateException
Checks if a call is valid (component is in the required state), increments the call count.

Throws:
IllegalStateException

_strictStartCall

protected void _strictStartCall()
                         throws IllegalStateException
Throws:
IllegalStateException
Since:
1.1

_endCall

protected void _endCall()
Decrements the call count. Wakes up all threads that are waiting on this object's monitor


_startWaitingCall

protected void _startWaitingCall()
Used for starting a call that is a re-entrant call. Meaning a call of this component is doing the calling


_endWaitingCall

protected void _endWaitingCall()
Decrements internal callcount counter.


_checkCall

protected void _checkCall()
                   throws IllegalStateException
Checks if this component was initialized. If not, throws IllegalStateException. This is relatively loose check, allowing leftover calls to dead components.

Throws:
IllegalStateException - when component has never been initialized

_strictCheckCall

protected void _strictCheckCall()
                         throws IllegalStateException
Checks if this component is currently alive. This is strict check that disallows leftover calls to dead components.

Throws:
IllegalStateException - when component is unborn or dead
Since:
1.1

_getChildren

protected Map _getChildren()
Returns the children of this component.


_getDisabledChildren

protected Map _getDisabledChildren()
Returns the children of this component.


_addComponent

protected void _addComponent(Object key,
                             Component component,
                             Environment env)
Adds a child component to this component with the key and initilizes it with the specified Environment env.


_addComponent

protected void _addComponent(Object key,
                             Component component,
                             Scope scope,
                             Environment env)
Adds a child component to this component with the key and initilizes it with the specified Environment env.

Since:
1.1

_removeComponent

protected void _removeComponent(Object key)
Removes the child component with the specified key from the children and calls destroy on it.

Parameters:
key - The ID of the component to remove.

_disableComponent

protected void _disableComponent(Object key)
Disables the child component with the specified key. A disabled child is a child that is removed from the standard set of children

Parameters:
key - The ID of the child component to disable.

_enableComponent

protected void _enableComponent(Object key)
Enables a disabled child component with the specified key. If the key does not correspond to anything, a runtime exception will occur.

Parameters:
key - The ID of the child component to enable.

_relocateComponent

protected void _relocateComponent(Composite parent,
                                  Environment newEnv,
                                  Object keyFrom,
                                  Object keyTo)
Relocates parent's child with keyFrom to this BaseComponent with a new key keyTo. The child will get the Environment specified by newEnv.

Parameters:
parent - is the current parent of the child to be relocated.
newEnv - the new Environment of the child.
keyFrom - is the key of the child to be relocated.
keyTo - is the the key, with which the child will be added to this StandardService.

_propagate

protected void _propagate(Message message)
Forwards the message to the component and to all of its children components.

Note: this is the component propagation logic that should not be modified by applications (they should use just the propagate(Message)).

Parameters:
message - A message to forward.
Throws:
Exception - Any runtime exception that may occur.