org.jboss.mx.remoting
Class MoveableMBean

java.lang.Object
  extended byorg.jboss.mx.remoting.MoveableMBean
All Implemented Interfaces:
java.lang.reflect.InvocationHandler, java.io.Serializable

public class MoveableMBean
extends java.lang.Object
implements java.lang.reflect.InvocationHandler, java.io.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.

See Also:
Serialized Form

Field Summary
protected  java.lang.Integer hashCode
           
protected  MBeanLocator (src) locator
           
protected  java.util.Map staticAttributes
           
 
Constructor Summary
protected MoveableMBean(MBeanLocator (src)  locator, java.util.Map staticAttributes)
           
 
Method Summary
 void addStaticAttribute(java.lang.String name, java.lang.Object value)
          add a static attribute
 void addStaticAttributes(java.util.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 java.lang.Object create(MBeanLocator (src)  locater, java.lang.Class interfaceClass)
           
static java.lang.Object create(MBeanLocator (src)  locator, java.lang.Class[] interfaces)
           
static java.lang.Object create(MBeanLocator (src)  locator, java.lang.ClassLoader loader, java.lang.Class interfaceClass)
           
static java.lang.Object create(MBeanLocator (src)  locator, java.lang.ClassLoader loader, java.lang.Class[] interfaces, java.util.Map staticAttributes)
           
static java.lang.Object create(MBeanLocator (src)  locator, java.lang.ClassLoader loader, java.lang.Class interfaceClass, java.util.Map staticAttributes)
           
 MBeanLocator (src) getMBeanLocator()
          return the locator that the mbean references
protected  java.lang.Object handleLocationMethods(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
           
protected  java.lang.Object handleObjectMethods(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
           
 java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
          Processes a method invocation on a proxy instance and returns the result.
protected  java.lang.String[] makeArgSignature(java.lang.reflect.Method method, java.lang.Object[] args)
          convert the method to a String array for the signature of the MBean invocation
protected  java.lang.Boolean proxyEquals(java.lang.Object proxy, java.lang.Object other)
           
protected  java.lang.Integer proxyHashCode(java.lang.Object proxy)
           
protected  java.lang.String proxyToString(java.lang.Object proxy)
           
protected  java.lang.Class resolveProxyClass(java.lang.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 (src)  locator

hashCode

protected java.lang.Integer hashCode

staticAttributes

protected java.util.Map staticAttributes
Constructor Detail

MoveableMBean

protected MoveableMBean(MBeanLocator (src)  locator,
                        java.util.Map staticAttributes)
Method Detail

getMBeanLocator

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

Returns:

create

public static java.lang.Object create(MBeanLocator (src)  locator,
                                      java.lang.ClassLoader loader,
                                      java.lang.Class interfaceClass)

create

public static java.lang.Object create(MBeanLocator (src)  locator,
                                      java.lang.ClassLoader loader,
                                      java.lang.Class interfaceClass,
                                      java.util.Map staticAttributes)

create

public static java.lang.Object create(MBeanLocator (src)  locater,
                                      java.lang.Class interfaceClass)

create

public static java.lang.Object create(MBeanLocator (src)  locator,
                                      java.lang.Class[] interfaces)

create

public static java.lang.Object create(MBeanLocator (src)  locator,
                                      java.lang.ClassLoader loader,
                                      java.lang.Class[] interfaces,
                                      java.util.Map staticAttributes)

addStaticAttributes

public void addStaticAttributes(java.util.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(java.lang.String name,
                               java.lang.Object value)
add a static attribute

Parameters:
name -
value -

handleLocationMethods

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

invoke

public java.lang.Object invoke(java.lang.Object proxy,
                               java.lang.reflect.Method method,
                               java.lang.Object[] args)
                        throws java.lang.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 java.lang.reflect.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:
java.lang.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 java.lang.Boolean proxyEquals(java.lang.Object proxy,
                                        java.lang.Object other)

proxyToString

protected java.lang.String proxyToString(java.lang.Object proxy)

proxyHashCode

protected java.lang.Integer proxyHashCode(java.lang.Object proxy)

handleObjectMethods

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

makeArgSignature

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

Parameters:
method -
args -
Returns:

resolveProxyClass

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

Parameters:
interfaces -
Returns:
Throws:
java.io.IOException
java.lang.ClassNotFoundException