FileDocCategorySizeDatePackage
BaseRuntimeMBean.javaAPI DocGlassfish v2 API21601Fri May 04 22:25:38 BST 2007com.sun.enterprise.admin.runtime

BaseRuntimeMBean

public class BaseRuntimeMBean extends com.sun.enterprise.admin.BaseAdminMBean implements MBeanRegistration

Base class for Config MBeans which implements basic config activity according to ModelMBeanInfo provided by MBeanRegistry

Fields Summary
private com.sun.enterprise.admin.config.ManagedConfigBean
mcb
private ManagedJsr77MdlBean
mrb
protected com.sun.enterprise.admin.meta.MBeanRegistry
m_registry
ObjectName
mSelfObjectName
Constructors Summary
public BaseRuntimeMBean()
Construct a ModelMBean with default ModelMBeanInfo information.

exception
MBeanException if the initializer of an object throws an exception
exception
RuntimeOperationsException if an IllegalArgumentException occurs


    // ----------------------------------------------------------- Constructors
                                   
      

        super();
        m_registry = MBeanRegistryFactory.getRuntimeMBeanRegistry();
    
Methods Summary
protected javax.management.ObjectNamecreateChildElementByType(java.lang.String childElementName, javax.management.Attribute[] attrs, boolean bSkipNullValued, boolean bOnlyOne)

        AttributeList list = new AttributeList();
        for(int i=0; i<attrs.length; i++)
        {
            if(!bSkipNullValued || attrs[i].getValue()!=null)
                list.add(attrs[i]);
        }
        ConfigBean bean = mcb.createChildByType(childElementName, list, null, bOnlyOne);
        return ConfigMBeanHelper.getChildObjectName(m_registry, info, bean);
    
protected javax.management.ObjectNamecreateChildElementByType(java.lang.String childElementName, javax.management.Attribute[] attrs)

        return createChildElementByType(childElementName, attrs, true, false);
    
protected javax.management.ObjectNamecreateChildElementByType(java.lang.String childElementName, javax.management.Attribute[] attrs, boolean bSkipNullValued)

        return createChildElementByType(childElementName, attrs, bSkipNullValued, false);
    
public java.lang.ObjectgetAttribute(java.lang.String name)
Obtain and return the value of a specific attribute of this MBean.

param
name Name of the requested attribute
exception
AttributeNotFoundException if this attribute is not supported by this MBean
exception
MBeanException if the initializer of an object throws an exception
exception
ReflectionException if a Java reflection exception occurs when invoking the getter

        ModelMBeanAttributeInfo attrInfo = (ModelMBeanAttributeInfo)MBeanHelper.findMatchingAttributeInfo((MBeanInfo)info, name);
        if(attrInfo==null)
            throw new AttributeNotFoundException();
        //FIXME add check "is readable"
        //1. MBean 
        try 
        {
            return super.getAttribute(name);
        } catch (Exception e) {}

        //2. runtime managed bean
        if(mrb!=null)
        {
            // our delegate is not an MBean and won't have its ObjectName
            if ( "objectName".equals( name ) )
            {
                // use of JMXUtil produces a consistently-ordered String for all ObjectNames
                return JMXUtil.toString( mSelfObjectName );
            }
            else
            {
                try
                {
                    return mrb.getAttribute(attrInfo, name);
                }
                catch (Exception e)
                {
                    // yuck, this whole method stinks, but this is the way it was
                }
            }
        }

        //3. config managed bean
        if(mcb!=null)
        {
            try {
                return mcb.getAttribute(attrInfo, name);
            } catch (Exception e) {}
        }
        throw new AttributeNotFoundException(); //?????
    
public javax.management.AttributeListgetAttributes(java.lang.String[] attributeNames)

        AttributeList list = new AttributeList();
        if(attributeNames!=null)
            for(int i=0; i<attributeNames.length; i++)
            {
                try {
                    Object value = getAttribute(attributeNames[i]);
                    list.add(new Attribute(attributeNames[i], value));
                } catch (Exception e) {}
            }
        return list;
    
public java.lang.Objectinvoke(java.lang.String name, java.lang.Object[] params, java.lang.String[] signature)
Invoke a particular method on this MBean, and return any returned value.

IMPLEMENTATION NOTE - This implementation will attempt to invoke this method on the MBean itself, or (if not available) on the managed resource object associated with this MBean.

param
name Name of the operation to be invoked
param
params Array containing the method parameters of this operation
param
signature Array containing the class names representing the signature of this operation
exception
MBeanException if the initializer of an object throws an exception
exception
ReflectioNException if a Java reflection exception occurs when invoking a method

            ModelMBeanOperationInfo opInfo = (ModelMBeanOperationInfo)MBeanHelper.findMatchingOperationInfo((MBeanInfo)info, name, signature);
            if (opInfo == null)
            {
                String msg = _localStrings.getString( "admin.server.core.mbean.config.base.operation_is_not_found", mbeanType, name);
                throw new MBeanException
                    (new ServiceNotFoundException(msg), msg);
            }

            //Generic Config invoker
            Object ret;
            try 
            {
                ret = MBeanHelper.invokeOperationInBean(opInfo, this, params);
                if(ret!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT)
                    return ret;

                if(mrb!=null)
                {
                    ret = mrb.invokeOperation(opInfo, params, signature);
                    if(ret!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT)
                        return ret;
                }

                if(mcb!=null)
                {
                    ret = mcb.invokeOperation(opInfo, params, signature);
                    if(ret!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT)
                        return ret;
                }

            } 
            catch (MBeanException mbe)
            {
                throw mbe;
            }
            catch (Exception e)
            {
                String msg = _localStrings.getString( "admin.server.core.mbean.runtime.base.invoke_error", mbeanType, name);
                throw MBeanHelper.extractAndWrapTargetException(e, msg);
            }

            //TBD FIXME
            //value = ConfigBeanHandler.invoke(this.cb, name, params, signature);
            return super.invoke(name, params, signature);
    
public voidpostDeregister()

        mSelfObjectName = null;
    
public voidpostRegister(java.lang.Boolean registrationDone)

    
public voidpreDeregister()

    
public javax.management.ObjectNamepreRegister(javax.management.MBeanServer server, javax.management.ObjectName name)

        mSelfObjectName = name;
        return name;
    
public voidsetAttribute(javax.management.Attribute attribute)
Set the value of a specific attribute of this MBean.

param
attribute The identification of the attribute to be set and the new value
exception
AttributeNotFoundException if this attribute is not supported by this MBean
exception
MBeanException if the initializer of an object throws an exception
exception
ReflectionException if a Java reflection exception occurs when invoking the getter

        ModelMBeanAttributeInfo attrInfo = (ModelMBeanAttributeInfo)MBeanHelper.findMatchingAttributeInfo((MBeanInfo)info, attribute.getName());
        if(attrInfo==null)
            throw new AttributeNotFoundException();
        //FIXME add check "is writable"

        //1. MBean 
        try 
        {
            super.setAttribute(attribute);
            return;
        } catch (Exception e) {}

        //2. runtime managed bean
        if(mrb!=null)
        {
            try {
                mrb.setAttribute(attrInfo, attribute);
                return;
            } catch (Exception e) {}
        }

        //3. config managed bean
        if(mcb!=null)
        {
            try {
                mcb.setAttribute(attrInfo, attribute);
                return;
            } catch (Exception e) {}
        }

    
public javax.management.AttributeListsetAttributes(javax.management.AttributeList list)
Sets the values of several MBean's attributes.

param
attrList A list of attributes: The identification of the attributes to be set and the values they are to be set to.
return
The list of attributes that were set, with their new values.

        if(list==null || list.size()<=0)
            return null;
        AttributeList listRes = new AttributeList();
        for(int i=0; i<list.size(); i++)
        {
            try {
                Attribute attr = (Attribute)list.get(i);
                setAttribute(attr);
                listRes.add(attr);
            } catch (Exception e) {}
        }
        return listRes;
    
public voidsetManagedResource(java.lang.Object resource, java.lang.String type)
Set the instance handle of the object against which we will execute all methods in this ModelMBean management interface.

param
resource The resource object to be managed
param
type The type of reference for the managed resource ("ObjectReference", "Handle", "IOR", "EJBHandle", or "RMIReference" OR "ConfigBeanReference" or "Jsr77ModelBeanReference" )
exception
InstanceNotFoundException if the managed resource object cannot be found
exception
InvalidTargetObjectTypeException if this ModelMBean is asked to handle a reference type it cannot deal with
exception
MBeanException if the initializer of the object throws an exception
exception
RuntimeOperationsException if the managed resource or the resource type is null or invalid


        if (resource == null)
            throw new RuntimeOperationsException
                (new IllegalArgumentException("Managed resource is null"),
                 "Managed resource is null");
        
        if (MBeanMetaConstants.CONFIG_BEAN_REF.equalsIgnoreCase(type)) {
            if(! (resource instanceof ConfigBean)) {
                throw new RuntimeOperationsException
                 (new ClassCastException("Managed resource is not a ConfigBean"),
                 "Managed resource is not a ConfigBean");
            }
            this.mcb = new ManagedConfigBean(this, (ConfigBean) resource, m_registry);
            
        } else {
            if (MBeanMetaConstants.JSR77_MODEL_BEAN_REF.equalsIgnoreCase(type)) 
            {
/*                if(! (resource instanceof J2EEManagedObjectMdl)) {
                    throw new RuntimeOperationsException
                     (new ClassCastException("Managed resource is not a Jsr77ModelBean :"+resource.getClass().getName()),
                     "Managed resource is not a Jsr77ModelBean: "+resource.getClass().getName());
                }
 */
                this.mrb = new ManagedJsr77MdlBean(this, /*(J2EEManagedObjectMdl)*/ resource);
            } else 
            {
                super.setManagedResource(resource, type);
            }
        }