org.inxar.hotswap
Class ProxyInvocationHandler

java.lang.Object
  |
  +--org.inxar.hotswap.ProxyInvocationHandler
All Implemented Interfaces:
InvocationHandler

public class ProxyInvocationHandler
extends Object
implements InvocationHandler

The standard InvocationHandler implementation. Subclasses can override the preInvoke, postInvoke, or invoke methods to provide custom behavior. The current implementation looks like:

Implementation of ProxyInvocationHandler.invoke method.
  public void preInvoke(Object src, Method method, Object[] args)
  {
      proxy.hotswap();
  }

  public Object invoke(Object src, Method method, Object[] args) throws Throwable
  {
      preInvoke(src, method, args);

      Object result = method.getName().startsWith("hotswap") 
          ? method.invoke(proxy,                       args)
          : method.invoke(proxy.hotswap_getInstance(), args);

      postInvoke(src, method, args, result);

      return result;
  }

  public void postInvoke(Object src, Method method, Object[] args, Object result)
  {
  }

  // Set within the setProxy method.
  protected Proxy proxy;
 

To use your custom ProxyInvocationHandler implementation, pass it as the first argument to one of the ProxyClass.newInstanceH factory methods:

Custom ProxyInvocationHandler Usage
 MyProxyInvocationHandler h = new MyProxyInvocationHandler();

 MyObject obj = (MyObject)compiler.load("org.myname.myproject.MyObject").newInstanceH(h);
 


Constructor Summary
ProxyInvocationHandler()
           
 
Method Summary
 Proxy getProxy()
          Returns the internal Proxy instance.
 Object invoke(Object src, Method method, Object[] args)
          Implements InvocationHandler.
 void postInvoke(Object src, Method method, Object[] args, Object result)
          Called after method dispatch to the internal proxy.
 void preInvoke(Object src, Method method, Object[] args)
          Called before method dispatch to the internal proxy.
 void setProxy(Proxy proxy)
          Sets the internal Proxy to the given instance.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProxyInvocationHandler

public ProxyInvocationHandler()
Method Detail

invoke

public Object invoke(Object src,
                     Method method,
                     Object[] args)
              throws Throwable
Implements InvocationHandler.
Specified by:
invoke in interface InvocationHandler

setProxy

public void setProxy(Proxy proxy)
Sets the internal Proxy to the given instance.

getProxy

public Proxy getProxy()
Returns the internal Proxy instance.

preInvoke

public void preInvoke(Object src,
                      Method method,
                      Object[] args)
Called before method dispatch to the internal proxy.

postInvoke

public void postInvoke(Object src,
                       Method method,
                       Object[] args,
                       Object result)
Called after method dispatch to the internal proxy.