Top Description Fields Constructors Methods
org.springframework.jmx.export

public Class SpringModelMBean

extends RequiredModelMBean
Class Inheritance
Imports
javax.management.Attribute, .AttributeList, .AttributeNotFoundException, .InstanceNotFoundException, .InvalidAttributeValueException, .MBeanException, .ReflectionException, .RuntimeOperationsException, javax.management.modelmbean.InvalidTargetObjectTypeException, .ModelMBeanInfo, .RequiredModelMBean

Extension of the RequiredModelMBean class that ensures the thread context ClassLoader is switched for the managed resource's ClassLoader before any invocations occur.
Author
Rob Harrop
Since
2.0
See Also
RequiredModelMBean

Field Summary

Modifier and TypeField and Description
private ClassLoader
managedResourceClassLoader

Stores the ClassLoader to use for invocations.

Constructor Summary

AccessConstructor and Description
public
SpringModelMBean()

Construct a new SpringModelMBean instance with an empty ModelMBeanInfo.

public
SpringModelMBean(ModelMBeanInfo mbi)

Construct a new SpringModelMBean instance with the given ModelMBeanInfo.

Method Summary

Modifier and TypeMethod and Description
public Object
getAttribute(String
A String specifying the name of the attribute to be retrieved. It must match the name of a ModelMBeanAttributeInfo.
attrName
)

Overrides javax.management.modelmbean.RequiredModelMBean.getAttribute.

Implements javax.management.DynamicMBean.getAttribute.

Switches the context ClassLoader for the managed resources ClassLoader before allowing the invocation to occur.
public AttributeList
getAttributes(String[]
A String array of names of the attributes to be retrieved.
attrNames
)

Overrides javax.management.modelmbean.RequiredModelMBean.getAttributes.

Implements javax.management.DynamicMBean.getAttributes.

Switches the context ClassLoader for the managed resources ClassLoader before allowing the invocation to occur.
public Object
invoke(String
The name of the method to be invoked. The name can be the fully qualified method name including the classname, or just the method name if the classname is defined in the 'class' field of the operation descriptor.
opName
,
Object[]
An array containing the parameters to be set when the operation is invoked
opArgs
,
String[]
An array containing the signature of the operation. The class objects will be loaded using the same class loader as the one used for loading the MBean on which the operation was invoked.
sig
)

Overrides javax.management.modelmbean.RequiredModelMBean.invoke.

Implements javax.management.DynamicMBean.invoke.

Switches the context ClassLoader for the managed resources ClassLoader before allowing the invocation to occur.
public void
setAttribute(Attribute
The Attribute instance containing the name of the attribute to be set and the value it is to be set to.
attribute
)

Overrides javax.management.modelmbean.RequiredModelMBean.setAttribute.

Implements javax.management.DynamicMBean.setAttribute.

Switches the context ClassLoader for the managed resources ClassLoader before allowing the invocation to occur.
public AttributeList
setAttributes(AttributeList
A list of attributes: The identification of the attributes to be set and the values they are to be set to.
attributes
)

Overrides javax.management.modelmbean.RequiredModelMBean.setAttributes.

Implements javax.management.DynamicMBean.setAttributes.

Switches the context ClassLoader for the managed resources ClassLoader before allowing the invocation to occur.
public void
setManagedResource(Object
Object that is the managed resource
managedResource
,
String
The type of reference for the managed resource.
Can be: "ObjectReference", "Handle", "IOR", "EJBHandle", or "RMIReference".
In this implementation only "ObjectReference" is supported.
managedResourceType
)

Overrides javax.management.modelmbean.RequiredModelMBean.setManagedResource.

Implements javax.management.modelmbean.ModelMBean.setManagedResource.

Sets managed resource to expose and stores its ClassLoader.
Inherited from javax.management.modelmbean.RequiredModelMBean:
addAttributeChangeNotificationListeneraddNotificationListenergetClassLoaderRepositorygetMBeanInfogetNotificationInfoloadpostDeregisterpostRegisterpreDeregisterpreRegisterremoveAttributeChangeNotificationListenerremoveNotificationListenerremoveNotificationListenersendAttributeChangeNotificationsendAttributeChangeNotificationsendNotificationsendNotificationsetModelMBeanInfostore

Field Detail

managedResourceClassLoaderback to summary
private ClassLoader managedResourceClassLoader

Stores the ClassLoader to use for invocations. Defaults to the current thread ClassLoader.

Constructor Detail

SpringModelMBeanback to summary
public SpringModelMBean() throws MBeanException, RuntimeOperationsException

Construct a new SpringModelMBean instance with an empty ModelMBeanInfo.

See Also
javax.management.modelmbean.RequiredModelMBean#RequiredModelMBean()
SpringModelMBeanback to summary
public SpringModelMBean(ModelMBeanInfo mbi) throws MBeanException, RuntimeOperationsException

Construct a new SpringModelMBean instance with the given ModelMBeanInfo.

See Also
javax.management.modelmbean.RequiredModelMBean#RequiredModelMBean(ModelMBeanInfo)

Method Detail

getAttributeback to summary
public Object getAttribute(String attrName) throws AttributeNotFoundException, MBeanException, ReflectionException

Overrides javax.management.modelmbean.RequiredModelMBean.getAttribute.

Implements javax.management.DynamicMBean.getAttribute.

Switches the context ClassLoader for the managed resources ClassLoader before allowing the invocation to occur.

Parameters
attrName:String

Doc from javax.management.modelmbean.RequiredModelMBean.getAttribute.

A String specifying the name of the attribute to be retrieved. It must match the name of a ModelMBeanAttributeInfo.

Returns:Object

Doc from javax.management.modelmbean.RequiredModelMBean.getAttribute.

The value of the retrieved attribute from the descriptor 'value' field or from the invocation of the operation in the 'getMethod' field of the descriptor.

Annotations
@Override
Exceptions
AttributeNotFoundException:

Doc from javax.management.modelmbean.RequiredModelMBean.getAttribute.

The specified attribute is not accessible in the MBean. The following cases may result in an AttributeNotFoundException:

  • No ModelMBeanInfo was found for the Model MBean.
  • No ModelMBeanAttributeInfo was found for the specified attribute name.
  • The ModelMBeanAttributeInfo isReadable method returns 'false'.
MBeanException:

Doc from javax.management.modelmbean.RequiredModelMBean.getAttribute.

Wraps one of the following Exceptions:

  • InvalidAttributeValueException: A wrong value type was received from the attribute's getter method or no 'getMethod' field defined in the descriptor for the attribute and no default value exists.
  • ServiceNotFoundException: No ModelMBeanOperationInfo defined for the attribute's getter method or no descriptor associated with the ModelMBeanOperationInfo or the managed resource is null.
  • InvalidTargetObjectTypeException The 'targetType' field value is not 'objectReference'.
  • An Exception thrown by the managed object's getter.
ReflectionException:

Doc from javax.management.modelmbean.RequiredModelMBean.getAttribute.

Wraps an java.lang.Exception thrown while trying to invoke the getter.

See Also
javax.management.modelmbean.ModelMBean#getAttribute
getAttributesback to summary
public AttributeList getAttributes(String[] attrNames)

Overrides javax.management.modelmbean.RequiredModelMBean.getAttributes.

Implements javax.management.DynamicMBean.getAttributes.

Switches the context ClassLoader for the managed resources ClassLoader before allowing the invocation to occur.

Parameters
attrNames:String[]

Doc from javax.management.modelmbean.RequiredModelMBean.getAttributes.

A String array of names of the attributes to be retrieved.

Returns:AttributeList

Doc from javax.management.modelmbean.RequiredModelMBean.getAttributes.

The array of the retrieved attributes.

Annotations
@Override
See Also
javax.management.modelmbean.ModelMBean#getAttributes
invokeback to summary
public Object invoke(String opName, Object[] opArgs, String[] sig) throws MBeanException, ReflectionException

Overrides javax.management.modelmbean.RequiredModelMBean.invoke.

Implements javax.management.DynamicMBean.invoke.

Switches the context ClassLoader for the managed resources ClassLoader before allowing the invocation to occur.

Parameters
opName:String

Doc from javax.management.modelmbean.RequiredModelMBean.invoke.

The name of the method to be invoked. The name can be the fully qualified method name including the classname, or just the method name if the classname is defined in the 'class' field of the operation descriptor.

opArgs:Object[]

Doc from javax.management.modelmbean.RequiredModelMBean.invoke.

An array containing the parameters to be set when the operation is invoked

sig:String[]

Doc from javax.management.modelmbean.RequiredModelMBean.invoke.

An array containing the signature of the operation. The class objects will be loaded using the same class loader as the one used for loading the MBean on which the operation was invoked.

Returns:Object

Doc from javax.management.modelmbean.RequiredModelMBean.invoke.

The object returned by the method, which represents the result of invoking the method on the specified managed resource.

Annotations
@Override
Exceptions
MBeanException:

Doc from javax.management.modelmbean.RequiredModelMBean.invoke.

Wraps one of the following Exceptions:

  • An Exception thrown by the managed object's invoked method.
  • ServiceNotFoundException: No ModelMBeanOperationInfo or no descriptor defined for the specified operation or the managed resource is null.
  • InvalidTargetObjectTypeException: The 'targetType' field value is not 'objectReference'.
ReflectionException:

Doc from javax.management.modelmbean.RequiredModelMBean.invoke.

Wraps an java.lang.Exception thrown while trying to invoke the method.

See Also
javax.management.modelmbean.ModelMBean#invoke
setAttributeback to summary
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException

Overrides javax.management.modelmbean.RequiredModelMBean.setAttribute.

Implements javax.management.DynamicMBean.setAttribute.

Switches the context ClassLoader for the managed resources ClassLoader before allowing the invocation to occur.

Parameters
attribute:Attribute

Doc from javax.management.modelmbean.RequiredModelMBean.setAttribute.

The Attribute instance containing the name of the attribute to be set and the value it is to be set to.

Annotations
@Override
Exceptions
AttributeNotFoundException:

Doc from javax.management.modelmbean.RequiredModelMBean.setAttribute.

The specified attribute is not accessible in the MBean.
The following cases may result in an AttributeNotFoundException:

  • No ModelMBeanAttributeInfo is found for the specified attribute.
  • The ModelMBeanAttributeInfo's isWritable method returns 'false'.
InvalidAttributeValueException:

Doc from javax.management.modelmbean.RequiredModelMBean.setAttribute.

No descriptor is defined for the specified attribute.

MBeanException:

Doc from javax.management.modelmbean.RequiredModelMBean.setAttribute.

Wraps one of the following Exceptions:

  • An Exception thrown by the managed object's setter.
  • A ServiceNotFoundException if a setMethod field is defined in the descriptor for the attribute and the managed resource is null; or if no setMethod field is defined and caching is not enabled for the attribute. Note that if there is no getMethod field either, then caching is automatically enabled.
  • InvalidTargetObjectTypeException The 'targetType' field value is not 'objectReference'.
  • An Exception thrown by the managed object's getter.
ReflectionException:

Doc from javax.management.modelmbean.RequiredModelMBean.setAttribute.

Wraps an java.lang.Exception thrown while trying to invoke the setter.

See Also
javax.management.modelmbean.ModelMBean#setAttribute
setAttributesback to summary
public AttributeList setAttributes(AttributeList attributes)

Overrides javax.management.modelmbean.RequiredModelMBean.setAttributes.

Implements javax.management.DynamicMBean.setAttributes.

Switches the context ClassLoader for the managed resources ClassLoader before allowing the invocation to occur.

Parameters
attributes:AttributeList

Doc from javax.management.modelmbean.RequiredModelMBean.setAttributes.

A list of attributes: The identification of the attributes to be set and the values they are to be set to.

Returns:AttributeList

Doc from javax.management.modelmbean.RequiredModelMBean.setAttributes.

The array of attributes that were set, with their new values in Attribute instances.

Annotations
@Override
See Also
javax.management.modelmbean.ModelMBean#setAttributes
setManagedResourceback to summary
public void setManagedResource(Object managedResource, String managedResourceType) throws MBeanException, InstanceNotFoundException, InvalidTargetObjectTypeException

Overrides javax.management.modelmbean.RequiredModelMBean.setManagedResource.

Implements javax.management.modelmbean.ModelMBean.setManagedResource.

Sets managed resource to expose and stores its ClassLoader.

Parameters
managedResource:Object

Doc from javax.management.modelmbean.RequiredModelMBean.setManagedResource.

Object that is the managed resource

managedResourceType:String

Doc from javax.management.modelmbean.RequiredModelMBean.setManagedResource.

The type of reference for the managed resource.
Can be: "ObjectReference", "Handle", "IOR", "EJBHandle", or "RMIReference".
In this implementation only "ObjectReference" is supported.

Annotations
@Override
Exceptions
MBeanException:

Doc from javax.management.modelmbean.RequiredModelMBean.setManagedResource.

The initializer of the object has thrown an exception.

InstanceNotFoundException:

Doc from javax.management.modelmbean.RequiredModelMBean.setManagedResource.

The managed resource object could not be found

InvalidTargetObjectTypeException:

Doc from javax.management.modelmbean.RequiredModelMBean.setManagedResource.

The managed resource type should be "ObjectReference".