javax.management
Class MBeanServerInvocationHandler
- 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.
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
MBeanServerInvocationHandler
public MBeanServerInvocationHandler(MBeanServerConnection conn,
ObjectName name)
Constructs a new
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.
MBeanServerInvocationHandler
public MBeanServerInvocationHandler(MBeanServerConnection conn,
ObjectName name,
boolean mxBean)
Constructs a new
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
.
getObjectName
public ObjectName getObjectName()
Returns the name of the bean to which method calls are made.
- the bean which provides the actual method calls.
invoke
public Object invoke(Object proxy,
Method method,
Object[] args)
throws Throwable
Called by the proxy class whenever a method is called. The method
is emulated by retrieving an attribute from, setting an attribute on
or invoking a method on the server connection as required. Translation
between the Java data types supplied as arguments to the open types used
by the bean is provided, as well as translation of the return value back
in to the appropriate Java type if the bean is an
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.
- the return value from the method.
Throwable
- if an exception is thrown in performing the
method emulation.
isMXBean
public 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.
- true if this is a proxy for an
MXBean
.
MBeanServerInvocationHandler.java -- Provides a proxy for a bean.
Copyright (C) 2007 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.