org.apache.geronimo.gbean.runtime
Class GBeanInstance

java.lang.Object
  extended by org.apache.geronimo.gbean.runtime.GBeanInstance
All Implemented Interfaces:
StateManageable

public final class GBeanInstance
extends Object
implements StateManageable

A GBeanInstance is a J2EE Management Managed Object, and is standard base for Geronimo services.


Field Summary
static String RAW_INVOKER
          Attribute name used to retrieve the RawInvoker for the GBean
 
Constructor Summary
GBeanInstance(GBeanData gbeanData, Kernel kernel, DependencyManager dependencyManager, LifecycleBroadcaster lifecycleBroadcaster, ClassLoader classLoader)
          Construct a GBeanMBean using the supplied GBeanData and class loader
 
Method Summary
 void die()
           
 boolean equals(Object obj)
           
 AbstractName getAbstractName()
           
 Object getAttribute(int index)
          Gets the attribute value using the attribute index.
 Object getAttribute(String attributeName)
          Gets an attribute's value by name.
 Map getAttributeIndex()
          Gets an unmodifiable map from attribute names to index number (Integer).
 ClassLoader getClassLoader()
          The class loader used to build this gbean.
 GBeanData getGBeanData()
          Gets the gbean data for the gbean held by this gbean mbean.
 GBeanInfo getGBeanInfo()
          Gets the GBeanInfo used to build this gbean.
 String getName()
          Gets the name of the GBean as defined in the gbean info.
 String getObjectName()
           
 ObjectName getObjectNameObject()
           
 Map getOperationIndex()
          Gets an unmodifiable map from operation signature (GOperationSignature) to index number (Integer).
 long getStartTime()
          Gets the start time of this component
 int getState()
          Gets the state of this component as an int.
 State getStateInstance()
          Gets the state of this component as a State instance.
 String getStateReason()
          Gets the reason we are in the current state.
 Object getTarget()
           
 Class getType()
          The java type of the wrapped gbean instance
 int hashCode()
           
 Object invoke(int index, Object[] arguments)
          Invokes an opreation using the operation index.
 Object invoke(String operationName, Object[] arguments, String[] types)
          Invokes an operation on the target gbean by method signature.
 boolean isDead()
          Has this gbean instance been destroyed.
 void setAttribute(int index, Object value)
          Sets the attribute value using the attribute index.
 void setAttribute(String attributeName, Object value)
          Sets an attribute's value by name.
 void setAttribute(String attributeName, Object value, boolean manage)
           
 void setInstanceRegistry(InstanceRegistry instanceRegistry)
           
 void setStateReason(String reason)
          Sets the reason we are in the current state.
 void start()
          Moves this GBeanInstance to the starting state and then attempts to move this MBean immediately to the running state.
 void startRecursive()
          Starts this GBeanInstance and then attempts to start all of its start dependent children.
 void stop()
          Moves this GBeanInstance to the STOPPING state, calls stop on all start dependent children, and then attempt to move this MBean to the STOPPED state.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

RAW_INVOKER

public static final String RAW_INVOKER
Attribute name used to retrieve the RawInvoker for the GBean

See Also:
Constant Field Values
Constructor Detail

GBeanInstance

public GBeanInstance(GBeanData gbeanData,
                     Kernel kernel,
                     DependencyManager dependencyManager,
                     LifecycleBroadcaster lifecycleBroadcaster,
                     ClassLoader classLoader)
              throws InvalidConfigurationException
Construct a GBeanMBean using the supplied GBeanData and class loader

Parameters:
gbeanData - the data for the new GBean including GBeanInfo, intial attribute values, and reference patterns
classLoader - the class loader used to load the gbean instance and attribute/reference types
Throws:
InvalidConfigurationException - if the gbeanInfo is inconsistent with the actual java classes, such as mismatched attribute types or the intial data cannot be set
Method Detail

die

public void die()
         throws GBeanNotFoundException
Throws:
GBeanNotFoundException

setInstanceRegistry

public void setInstanceRegistry(InstanceRegistry instanceRegistry)

getName

public String getName()
Gets the name of the GBean as defined in the gbean info.

Returns:
the gbean name

getClassLoader

public ClassLoader getClassLoader()
The class loader used to build this gbean. This class loader is set into the thread context class loader before callint the target instace.

Returns:
the class loader used to build this gbean

isDead

public boolean isDead()
Has this gbean instance been destroyed. An destroyed gbean can no longer be used.

Returns:
true if the gbean has been destroyed

getStateReason

public String getStateReason()
Gets the reason we are in the current state.

Returns:
the reason we are in the current state

setStateReason

public void setStateReason(String reason)
Sets the reason we are in the current state.

Parameters:
reason - The reason we are in the current state

getType

public Class getType()
The java type of the wrapped gbean instance

Returns:
the java type of the gbean

getTarget

public Object getTarget()

getObjectName

public final String getObjectName()

getObjectNameObject

public final ObjectName getObjectNameObject()

getAbstractName

public final AbstractName getAbstractName()

getStartTime

public final long getStartTime()
Description copied from interface: StateManageable
Gets the start time of this component

Specified by:
getStartTime in interface StateManageable
Returns:
time in milliseonds since epoch that this component was started.

getState

public int getState()
Description copied from interface: StateManageable
Gets the state of this component as an int. The int return is required by the JSR77 specification.

Specified by:
getState in interface StateManageable
Returns:
the current state of this component
See Also:
to obtain the State instance

getStateInstance

public final State getStateInstance()
Description copied from interface: StateManageable
Gets the state of this component as a State instance.

Specified by:
getStateInstance in interface StateManageable
Returns:
the current state of this component

getAttributeIndex

public Map getAttributeIndex()
Gets an unmodifiable map from attribute names to index number (Integer). This index number can be used to efficiently set or retrieve an attribute value.

Returns:
an unmodifiable map of attribute indexes by name

getOperationIndex

public Map getOperationIndex()
Gets an unmodifiable map from operation signature (GOperationSignature) to index number (Integer). This index number can be used to efficciently invoke the operation.

Returns:
an unmodifiable map of operation indexec by signature

getGBeanInfo

public GBeanInfo getGBeanInfo()
Gets the GBeanInfo used to build this gbean.

Returns:
the GBeanInfo used to build this gbean

start

public final void start()
Moves this GBeanInstance to the starting state and then attempts to move this MBean immediately to the running state.

Specified by:
start in interface StateManageable
Throws:
IllegalStateException - If the gbean is disabled

startRecursive

public final void startRecursive()
Starts this GBeanInstance and then attempts to start all of its start dependent children.

Specified by:
startRecursive in interface StateManageable
Throws:
IllegalStateException - If the gbean is disabled

stop

public final void stop()
Moves this GBeanInstance to the STOPPING state, calls stop on all start dependent children, and then attempt to move this MBean to the STOPPED state.

Specified by:
stop in interface StateManageable

getGBeanData

public GBeanData getGBeanData()
Gets the gbean data for the gbean held by this gbean mbean.

Returns:
the gbean data

getAttribute

public Object getAttribute(int index)
                    throws Exception
Gets the attribute value using the attribute index. This is the most efficient way to get an attribute as it avoids a HashMap lookup.

Parameters:
index - the index of the attribute
Returns:
the attribute value
Throws:
Exception - if a target instance throws and exception
IndexOutOfBoundsException - if the index is invalid

getAttribute

public Object getAttribute(String attributeName)
                    throws NoSuchAttributeException,
                           Exception
Gets an attribute's value by name. This get style is less efficient becuse the attribute must first be looked up in a HashMap.

Parameters:
attributeName - the name of the attribute to retrieve
Returns:
the attribute value
Throws:
Exception - if a problem occurs while getting the value
NoSuchAttributeException - if the attribute name is not found in the map

setAttribute

public void setAttribute(int index,
                         Object value)
                  throws Exception,
                         IndexOutOfBoundsException
Sets the attribute value using the attribute index. This is the most efficient way to set an attribute as it avoids a HashMap lookup.

Parameters:
index - the index of the attribute
value - the new value of attribute value
Throws:
Exception - if a target instance throws and exception
IndexOutOfBoundsException - if the index is invalid

setAttribute

public void setAttribute(String attributeName,
                         Object value)
                  throws Exception,
                         NoSuchAttributeException
Sets an attribute's value by name. This set style is less efficient becuse the attribute must first be looked up in a HashMap.

Parameters:
attributeName - the name of the attribute to retrieve
value - the new attribute value
Throws:
Exception - if a target instance throws and exception
NoSuchAttributeException - if the attribute name is not found in the map

setAttribute

public void setAttribute(String attributeName,
                         Object value,
                         boolean manage)
                  throws Exception,
                         NoSuchAttributeException
Throws:
Exception
NoSuchAttributeException

invoke

public Object invoke(int index,
                     Object[] arguments)
              throws Exception
Invokes an opreation using the operation index. This is the most efficient way to invoke an operation as it avoids a HashMap lookup.

Parameters:
index - the index of the attribute
arguments - the arguments to the operation
Returns:
the result of the operation
Throws:
Exception - if a target instance throws and exception
IndexOutOfBoundsException - if the index is invalid
IllegalStateException - if the gbean instance has been destroyed

invoke

public Object invoke(String operationName,
                     Object[] arguments,
                     String[] types)
              throws Exception,
                     NoSuchOperationException
Invokes an operation on the target gbean by method signature. This style if invocation is inefficient, because the target method must be looked up in a hashmap using a freshly constructed GOperationSignature object.

Parameters:
operationName - the name of the operation to invoke
arguments - arguments to the operation
types - types of the operation arguemtns
Returns:
the result of the operation
Throws:
Exception - if a target instance throws and exception
NoSuchOperationException - if the operation signature is not found in the map
IllegalStateException - if the gbean instance has been destroyed

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2003-2007 Apache Software Foundation. All Rights Reserved.