JDK-6624232 : Add GetResource interface to control MBeanServer.getClassLoaderFor and .isInstanceOf
  • Type: Enhancement
  • Component: core-svc
  • Sub-Component: javax.management
  • Affected Version: 6,7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-10-31
  • Updated: 2017-05-19
  • Resolved: 2011-04-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b30Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Description
It is often desirable to have getClassLoaderFor and isInstanceOf return values based on some object other than the actual MBean object.  The classic example is javax.management.StandardMBean, where getClassLoaderFor is utterly uninteresting.  We know that some users have resorted to writing
    Object mbean = new StandardMBean(...) {}
to create an anonymous subclass of StandardMBean that is defined by that code's ClassLoader.  That is clunky, and not always an option.

An example of when you might want to do this is if you want to access resources from the MBean's ClassLoader, for example to control localization or permission checking.  If the MBean is an instance of StandardMBean, then what you really want to see is the ClassLoader of the wrapped object, because that's where the resources will live.

The proposal is to define a new interface javax.management.GetResource with just one method:
    public Object getResource();
If an MBean is an instance of GetResource, then MBeanServer.getClassLoaderFor and .isInstanceOf will operate on the object returned by getResource() rather than the MBean object itself.

The classes StandardMBean and RequiredModelMBean will implement GetResource.  To avoid changing the behavior of existing code, the default getResource() will return the StandardMBean or RequiredModelMBean object itself, but an option will allow the MBean to be configured to return the wrapped object instead.

Comments
EVALUATION We're now proposing to define an interface DynamicWrapperMBean that extends DynamicMBean and adds two methods: package javax.management; public interface DynamicWrapperMBean extends DynamicMBean { Object getWrappedObject(); ClassLoader getWrappedClassLoader(); } We don't currently see a need to add a way to define the result of isInstanceOf, and it will in general be hard for implementors to know the correct logic to put there.
24-01-2008

EVALUATION Simple but powerful change.
31-10-2007