javax.management
public class MBeanServerInvocationHandler extends Object implements InvocationHandler
Provides a proxy for a management bean. The methods
of the given interface are fulfilled by redirecting the
calls over an MBeanServerConnection
to the bean
specified by the supplied ObjectName
.
The InvocationHandler
also makes
provision for MXBean
s by providing type conversion
according to the rules defined for these beans. The input
parameters are converted to their equivalent open type before
calling the method, and then the return value is converted
back from its open type to the appropriate Java type. For
example, a method that takes an Enum
as input and
returns a List
will have the input value
converted from an Enum
to a String
, while
the return value will be converted from its return type
(an appropriately typed array) to a List
.
The proxy has special cases for the Object.equals(Object)
,
Object.hashCode()
and Object.toString()
methods.
Unless they are specified explictly by the interface, the
following behaviour is provided for these methods by the proxy:
equals(Object)
returns true if the other object
is an MBeanServerInvocationHandler
with the same
MBeanServerConnection
and ObjectName
. If an
interface class was specified on construction for one of the
proxies, then the same class must have also been specified
for the other.hashCode()
returns the same value for
equivalent proxies.toString()
returns a textual representation
of the proxy.Constructor and Description |
---|
MBeanServerInvocationHandler(MBeanServerConnection conn,
ObjectName name)
Constructs a new
MBeanServerInvocationHandler
which forwards methods to the supplied bean via the
given MBeanServerConnection . |
MBeanServerInvocationHandler(MBeanServerConnection conn,
ObjectName name,
boolean mxBean)
Constructs a new
MBeanServerInvocationHandler
which forwards methods to the supplied bean via the
given MBeanServerConnection . |
Modifier and Type | Method and Description |
---|---|
MBeanServerConnection |
getMBeanServerConnection()
Returns the connection through which the calls to the bean
will be made.
|
ObjectName |
getObjectName()
Returns the name of the bean to which method calls are made.
|
Object |
invoke(Object proxy,
Method method,
Object[] args)
Called by the proxy class whenever a method is called.
|
boolean |
isMXBean()
Returns true if this is a proxy for an
MXBean
and conversions must be applied to input parameters
and return types, according to the rules for such beans. |
static <T> T |
newProxyInstance(MBeanServerConnection conn,
ObjectName name,
Class<T> iface,
boolean broadcaster)
Returns a proxy for the specified bean.
|
public MBeanServerInvocationHandler(MBeanServerConnection conn, ObjectName name)
MBeanServerInvocationHandler
which forwards methods to the supplied bean via the
given MBeanServerConnection
. This constructor
is used in preference to
JMX#newMBeanProxy(MBeanServerConnection, ObjectName,
Class)
if you wish to make your own call to
java.lang.reflect.Proxy#newInstance(ClassLoader,
Class[], java.lang.reflect.InvocationHandler)
with
a different ClassLoader
. Calling this constructor
is equivalent to MBeanServerInvocationHandler(conn,
name, false)
. The other constructor should be used
instead if the bean being proxied is an MXBean
.conn
- the connection through which methods will
be forwarded to the bean.name
- the name of the bean to use to provide the
actual calls.public MBeanServerInvocationHandler(MBeanServerConnection conn, ObjectName name, boolean mxBean)
MBeanServerInvocationHandler
which forwards methods to the supplied bean via the
given MBeanServerConnection
. This constructor
is used in preference to
JMX#newMBeanProxy(MBeanServerConnection, ObjectName,
Class)
if you wish to make your own call to
java.lang.reflect.Proxy#newInstance(ClassLoader,
Class[], java.lang.reflect.InvocationHandler)
with
a different ClassLoader
.conn
- the connection through which methods will
be forwarded to the bean.name
- the name of the bean to use to provide the
actual calls.mxBean
- true if the bean being proxied is an
MXBean
.public MBeanServerConnection getMBeanServerConnection()
public ObjectName getObjectName()
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
MXBean
.invoke
in interface InvocationHandler
proxy
- the proxy on which the method was called.method
- the method which was called.args
- the arguments supplied to the method.Throwable
- if an exception is thrown in performing the
method emulation.Proxy
,
UndeclaredThrowableException
public boolean isMXBean()
MXBean
and conversions must be applied to input parameters
and return types, according to the rules for such beans.MXBean
.public static <T> T newProxyInstance(MBeanServerConnection conn, ObjectName name, Class<T> iface, boolean broadcaster)
Returns a proxy for the specified bean. A proxy object is created
using Proxy.newProxyInstance(iface.getClassLoader(),
new Class[] { iface }, handler)
. The
NotificationEmitter
class is included as the
second element of the array if broadcaster
is true.
handler
refers to the invocation handler which forwards
calls to the connection, which is created by a call to
new MBeanServerInvocationHandler(conn, name)
.
Note: use of the proxy may result in
IOException
s from the underlying
MBeanServerConnection
.
As of 1.6, the use of JMX.newMBeanProxy(MBeanServerConnection,
ObjectName,Class)
and JMX.newMBeanProxy(MBeanServerConnection,
ObjectName,Class,boolean)
is preferred.
conn
- the server connection to use to access the bean.name
- the ObjectName
of the
bean to provide a proxy for.iface
- the interface for the bean being proxied.broadcaster
- true if the proxy should implement
NotificationEmitter
.JMX.newMBeanProxy(MBeanServerConnection,ObjectName,Class)