org.jboss.mx.remoting
Class MoveableMBean

java.lang.Object
  extended by org.jboss.mx.remoting.MoveableMBean
All Implemented Interfaces:
Serializable, InvocationHandler

public class MoveableMBean
extends Object
implements InvocationHandler, Serializable

MoveableMBean is a Dynamic Proxy to an MBean that exists on a JMX Network. This object can be created an cast to the appropriate set of interfaces that the MBean implements and can be serialized and past across the network and serialization and remote invocation will be handled as if the Object was local to the JVM.

Example usage:

 

TestMBean mybean=(TestMBean)MoveableMBean.create(mbeanLocator,TestMBean.class);

// transport method mybean.myMethod();

// transport a method against a remote JMX server and pass the TestMBean object // it will be serialized and passed to the remote server .. on the other side, the // JVM will de-serialize, create a local DynamicProxy and then invocations against the // parameter, will be invoked remotely back to the mbeanLocator above remoteserver.transport(new ObjectName(":test=MyObject"),"myMethod",new Object[]{mybean},new String[]{TestMBean.class.getName()});

You can also cache attribute values in the local proxy, in the case where the values are fixed and you don't want to remote overhead associated with sending the invocation remotely. In this case, you can pass in a Map of attribute/value pairs which will be always returned in any getter method invocation against the attribute.

Version:
$Revision: 81023 $
Author:
Jeff Haynie
See Also:
Serialized Form

Field Summary
protected  Integer hashCode
           
protected  MBeanLocator locator
           
protected  Map staticAttributes
           
 
Constructor Summary
protected MoveableMBean(MBeanLocator locator, Map staticAttributes)
           
 
Method Summary
 void addStaticAttribute(String name, Object value)
          add a static attribute
 void addStaticAttributes(Map values)
          add a map of static attributes, with each key being the attributeName and the value being the value to return for every invocation to this attribute getter
static Object create(MBeanLocator locater, Class interfaceClass)
           
static Object create(MBeanLocator locator, Class[] interfaces)
           
static Object create(MBeanLocator locator, ClassLoader loader, Class interfaceClass)
           
static Object create(MBeanLocator locator, ClassLoader loader, Class[] interfaces, Map staticAttributes)
           
static Object create(MBeanLocator locator, ClassLoader loader, Class interfaceClass, Map staticAttributes)
           
 MBeanLocator getMBeanLocator()
          return the locator that the mbean references
protected  Object handleLocationMethods(Object proxy, Method method, Object[] args)
           
protected  Object handleObjectMethods(Object proxy, Method method, Object[] args)
           
 Object invoke(Object proxy, Method method, Object[] args)
          Processes a method invocation on a proxy instance and returns the result.
protected  String[] makeArgSignature(Method method, Object[] args)
          convert the method to a String array for the signature of the MBean invocation
protected  Boolean proxyEquals(Object proxy, Object other)
           
protected  Integer proxyHashCode(Object proxy)
           
protected  String proxyToString(Object proxy)
           
protected  Class resolveProxyClass(String[] interfaces)
          resolve the proxy interfaces
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

locator

protected MBeanLocator locator

hashCode

protected Integer hashCode

staticAttributes

protected Map staticAttributes
Constructor Detail

MoveableMBean

protected MoveableMBean(MBeanLocator locator,
                        Map staticAttributes)
Method Detail

getMBeanLocator

public final MBeanLocator getMBeanLocator()
return the locator that the mbean references

Returns:

create

public static Object create(MBeanLocator locator,
                            ClassLoader loader,
                            Class interfaceClass)

create

public static Object create(MBeanLocator locator,
                            ClassLoader loader,
                            Class interfaceClass,
                            Map staticAttributes)

create

public static Object create(MBeanLocator locater,
                            Class interfaceClass)

create

public static Object create(MBeanLocator locator,
                            Class[] interfaces)

create

public static Object create(MBeanLocator locator,
                            ClassLoader loader,
                            Class[] interfaces,
                            Map staticAttributes)

addStaticAttributes

public void addStaticAttributes(Map values)
add a map of static attributes, with each key being the attributeName and the value being the value to return for every invocation to this attribute getter

Parameters:
values -

addStaticAttribute

public void addStaticAttribute(String name,
                               Object value)
add a static attribute

Parameters:
name -
value -

handleLocationMethods

protected Object handleLocationMethods(Object proxy,
                                       Method method,
                                       Object[] args)
                                throws Throwable
Throws:
Throwable

invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.

Specified by:
invoke in interface InvocationHandler
Parameters:
proxy - the proxy instance that the method was invoked on
method - the Method instance corresponding to the interface method invoked on the proxy instance. The declaring class of the Method object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
args - an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
Returns:
the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.
Throws:
Throwable - the exception to throw from the method invocation on the proxy instance. The exception's type must be assignable either to any of the exception types declared in the throws clause of the interface method or to the unchecked exception types java.lang.RuntimeException or java.lang.Error. If a checked exception is thrown by this method that is not assignable to any of the exception types declared in the throws clause of the interface method, then an UndeclaredThrowableException containing the exception that was thrown by this method will be thrown by the method invocation on the proxy instance.
See Also:
UndeclaredThrowableException

proxyEquals

protected Boolean proxyEquals(Object proxy,
                              Object other)

proxyToString

protected String proxyToString(Object proxy)

proxyHashCode

protected Integer proxyHashCode(Object proxy)

handleObjectMethods

protected Object handleObjectMethods(Object proxy,
                                     Method method,
                                     Object[] args)
                              throws Exception
Throws:
Exception

makeArgSignature

protected String[] makeArgSignature(Method method,
                                    Object[] args)
convert the method to a String array for the signature of the MBean invocation

Parameters:
method -
args -
Returns:

resolveProxyClass

protected Class resolveProxyClass(String[] interfaces)
                           throws IOException,
                                  ClassNotFoundException
resolve the proxy interfaces

Parameters:
interfaces -
Returns:
Throws:
IOException
ClassNotFoundException


Copyright © 2009 JBoss, a division of Red Hat, Inc.. All Rights Reserved.