FileDocCategorySizeDatePackage
BaseConfigMBean.javaAPI DocGlassfish v2 API31726Fri May 04 22:25:34 BST 2007com.sun.enterprise.admin.config

BaseConfigMBean

public class BaseConfigMBean 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
public static final boolean
OVERWRITE
FIXME: This is temporary. Ideally when we add a node controller or flush changes, we would like not to overwrite changes made on disk; however, all of the other flush() calls in the PE code, etc. implicitly pass overwrite as true. When I try to pass false, I run into the problem when multiple consecutive writes (e.g two calls to addNodeAgent) throw a "file has been modified" exception. So there is a bug somewhare.
private ManagedConfigBean
mcb
protected com.sun.enterprise.admin.meta.MBeanRegistry
m_registry
Constructors Summary
public BaseConfigMBean()
Construct a ModelMBean with default ModelMBeanInfo information.

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

    
    
                                   
      
        super();
        m_registry = MBeanRegistryFactory.getAdminMBeanRegistry();
    
Methods Summary
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);
    
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);
    
public booleandestroyConfigElement()

        if(mcb==null) 
        {//FIXME: should be exception if null
            return false;
        }
        mcb.deleteSelf();
        //now unregister MBean
        ObjectName objectName = ConfigMBeanHelper.getOwnObjectName(m_registry, info);
        if(objectName!=null)
        {
            try{
                MBeanServer server = (MBeanServer)(MBeanServerFactory.findMBeanServer(null)).get(0);
                server.unregisterMBean(objectName);
                } 
            catch (Throwable t)
                {
                    _sLogger.fine("!!!!!!!!!!!!!! Can not unregister MBean: "+objectName);
                }
            return true;
    }

        return false;
        //FIXME handle exceptions
        //return 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

                name = MBeanMetaHelper.mapToMBeanAttributeName(name);
                ModelMBeanAttributeInfo attrInfo = (ModelMBeanAttributeInfo)MBeanHelper.findMatchingAttributeInfo((MBeanInfo)info, name);
                if(attrInfo==null)
                    throw new AttributeNotFoundException(name);
                //FIXME add check "is readable"
                Object o = null;
                try {
                    o = super.getAttribute(name);
                } catch (Exception e) {
//                    try {
//                        if(mcb!=null)
                            o=mcb.getAttribute(attrInfo, name);
//                    } catch(Exception e1) {e1.printStackTrace();}
                }
                return o;
    
public javax.management.AttributeListgetAttributes(java.lang.String[] attributeNames)

        ArrayList names = mcb.getSimpleAttributeNames(attributeNames);
        AttributeList attrs = new AttributeList();
        for(int i=0; i<names.size(); i++) {
            try {
                String name = MBeanMetaHelper.mapToMBeanAttributeName((String)names.get(i));
                Object value  = getAttribute(name);
                attrs.add(new Attribute(name, value));
            } catch (Exception e) {
//                 attrs.add(new Attribute((String)names.get(i), null));
            }
        }
        return attrs;
    
public com.sun.enterprise.config.ConfigBeangetBaseConfigBean()
Get base node Config Bean;

return
ConfigBean related to the MBean's related ConfigNode .

        if(mcb!=null) {
           return mcb.getBaseConfigBean();
        }
        return null;
    
protected javax.management.ObjectNamegetChildObjectName(java.lang.String childMBeanType, java.lang.String name)

        if(m_registry==null)
            return null;
        String[] parentLocation =  MBeanHelper.getLocation((ModelMBeanInfo)getMBeanInfo());
        if(parentLocation==null || parentLocation.length==0)
            return null;
        if(name==null)
            return m_registry.getMbeanObjectName(childMBeanType, parentLocation);
        String[] childLocation = new String[parentLocation.length+1];
        for(int i=0; i<parentLocation.length; i++)
            childLocation[i] = parentLocation[i];
        childLocation[parentLocation.length] = name;
        return m_registry.getMbeanObjectName(childMBeanType, childLocation);
    
protected javax.management.ObjectNamegetClusterObjectName(java.lang.String name)

        return m_registry.getMbeanObjectName("cluster", new String[]{
            getDomainName(), name});
    
public javax.management.ObjectNamegetConfigBeanObjectName(com.sun.enterprise.config.ConfigBean configBean)

        return ConfigMBeanHelper.getConfigBeanObjectName(
                m_registry, getDomainName(), configBean);
    
protected com.sun.enterprise.config.ConfigContextgetConfigContext()

        if(mcb!=null) {
            return mcb.getConfigContext();        
        }
        return null;
    
protected javax.management.ObjectNamegetConfigurationObjectName(java.lang.String name)

       
        return m_registry.getMbeanObjectName("config", new String[]{
            getDomainName(), name});
    
protected java.lang.StringgetDomainName()

        final ModelMBeanInfo info = (ModelMBeanInfo)getMBeanInfo();
        if (info != null) {
            String[] location =  MBeanHelper.getLocation(info);
            if(location!=null && location.length>0) {
                return location[0];
            }
        }
        return null;
    
protected javax.management.MBeanServergetMBeanServer()

        return (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);
    
protected ManagedConfigBeangetManagedConfigBean(com.sun.enterprise.config.ConfigBean cb)

        return new ManagedConfigBean(cb, m_registry, getDomainName());
    
protected javax.management.ObjectNamegetNodeAgentObjectName(java.lang.String name)

        return m_registry.getMbeanObjectName("node-agent", new String[]{
            getDomainName(), name});
    
protected javax.management.ObjectNamegetServerObjectName(java.lang.String server)

        return m_registry.getMbeanObjectName("server", new String[]{
            getDomainName(), server});
    
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);
            }
            Descriptor descr = opInfo.getDescriptor();
            
            Object ret; 
            //try MBean self
            try 
            {
                ret = MBeanHelper.invokeOperationInBean(opInfo, this, params);
                if(ret!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT)
                {
                    return ret;
                }
                //invoke in config bean
                if(mcb!=null && 
                   (ret=mcb.invokeOperation(opInfo, params, signature))!=MBeanHelper.INVOKE_ERROR_SIGNAL_OBJECT)
                {
                    return ret;
                }
                return super.invoke(name, params, signature);
            } 
            catch (MBeanException mbe)
            {
                _sLogger.log(Level.FINE, "mbean.baseconfig.invoke_exception",mbe);
                throw mbe;
            }
            catch (Exception e)
            {
                _sLogger.log(Level.FINE, "mbean.baseconfig.invoke_exception",e);
                String msg = _localStrings.getString( "admin.server.core.mbean.config.base.invoke_error", mbeanType, name);
                throw MBeanHelper.extractAndWrapTargetException(e, msg);
            }
    
public voidpostDeregister()

/*
        ObjectName oName=null;
        try
        {
            oName = ConfigMBeanHelper.getOwnObjectName(m_registry, info);
            m_registry.notifyUnregisterMBean(oName, getConfigContext());
        }
        catch(Exception e)
        {
        }
*/
    
public voidpostRegister(java.lang.Boolean registrationDone)

    
public voidpreDeregister()

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

/*        try
        {
            m_registry.notifyRegisterMBean(name, getConfigContext());
        }
        catch(Exception e)
        {
        }
 */
        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

                attribute = new Attribute(MBeanMetaHelper.mapToMBeanAttributeName(attribute.getName()), attribute.getValue());
                ModelMBeanAttributeInfo attrInfo = (ModelMBeanAttributeInfo)MBeanHelper.findMatchingAttributeInfo((MBeanInfo)info, attribute.getName());
                if(attrInfo==null)
                    throw new AttributeNotFoundException();
                //FIXME add check "is writable"
                
                try {
                    super.setAttribute(attribute);
                } catch (Exception e) {
                    
//                    try {
                        //no toString(). remove it. FIXME
                        if(mcb!=null)
                            mcb.setAttribute(attrInfo, attribute);
//                    } catch(Exception e1) {e1.printStackTrace();}
                }
        
    
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.

            try {
                return super.setAttributes(list);
            } catch (Exception e) {

//                try {
                    //no toString(). remove it. FIXME
                    if(mcb!=null)
                        return mcb.setAttributes(list);
//                } catch(Exception e1) {e1.printStackTrace();}
            }
            return null;
    
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)
        {
            String msg = _localStrings.getString( "admin.server.core.mbean.config.base.managed_resource_is_null", mbeanType);
            throw new RuntimeOperationsException(new IllegalArgumentException(msg), msg);
        }
        if (MBeanMetaConstants.CONFIG_BEAN_REF.equalsIgnoreCase(type)) {
            if(! (resource instanceof ConfigBean)) 
            {
                String msg = _localStrings.getString( "admin.server.core.mbean.config.base.managed_resource_is_not_configbean", mbeanType);
                throw new RuntimeOperationsException(new ClassCastException(msg), msg);
            }
            this.mcb = new ManagedConfigBean(this, (ConfigBean) resource, m_registry);
            //Also add all attributes (and methods) to model mbean info
//            mcb.addResourceInfo();
            
        } else {
//            super.setManagedResource(resource, type);
        }
    
protected javax.management.ObjectName[]toClusterONArray(java.lang.String[] ca)

        int num = ca.length;
        final ObjectName[] result = new ObjectName[num];        
        for (int i = 0; i < num; i++)
        {
            result[i] = getClusterObjectName(ca[i]);
        }
        return result;
    
protected javax.management.ObjectName[]toConfigurationONArray(java.lang.String[] ca)

        int num = ca.length;
        final ObjectName[] result = new ObjectName[num];
        for (int i = 0; i < num; i++)
        {
            result[i] = getConfigurationObjectName(ca[i]);
        }
        return result;
    
protected javax.management.ObjectName[]toNodeAgentONArray(java.lang.String[] names)

        int numNames = names.length;
        final ObjectName[] result = new ObjectName[numNames];        
        for (int i = 0; i < numNames; i++) {
            result[i] = getNodeAgentObjectName(names[i]);
        }
        return result;
    
protected javax.management.ObjectName[]toServerONArray(java.lang.String[] ca)

        int num = ca.length;
        final ObjectName[] result = new ObjectName[num];
        
        for (int i = 0; i < num; i++)
        {
            result[i] = getServerObjectName(ca[i]);
        }
        return result;