com.thoughtworks.proxy.toys.hotswap
Class HotSwappingInvoker

java.lang.Object
  extended by com.thoughtworks.proxy.toys.delegate.DelegatingInvoker
      extended by com.thoughtworks.proxy.toys.hotswap.HotSwappingInvoker
All Implemented Interfaces:
Invoker, Serializable
Direct Known Subclasses:
FailoverInvoker

public class HotSwappingInvoker
extends DelegatingInvoker

A DelegatingInvoker implementation that allows the exchange of the delegate.

Since:
0.1
Author:
Aslak Hellesøy, Paul Hammant, Jörg Schaible
See Also:
Serialized Form

Nested Class Summary
protected static interface HotSwappingInvoker.CycleCheck
          Internal interface used to detect cyclic swapping activity.
 
Constructor Summary
HotSwappingInvoker(Class[] types, ProxyFactory proxyFactory, ObjectReference delegateReference, boolean staticTyping)
          Deprecated. since 0.2, use HotSwappingInvoker(Class[], ProxyFactory, ObjectReference, int)
HotSwappingInvoker(Class[] types, ProxyFactory proxyFactory, ObjectReference delegateReference, int delegationMode)
          Construct a HotSwappingInvoker.
 
Method Summary
protected  Object delegate()
          Retrieve the delegated object in derived classes.
protected  Object hotswap(Object newDelegate)
          Exchange the current delegate.
 Object invoke(Object proxy, Method method, Object[] args)
          Invocation of a method of the proxied object.
 Object proxy()
          Create a proxy for this Invoker.
 
Methods inherited from class com.thoughtworks.proxy.toys.delegate.DelegatingInvoker
equals, getDelegateReference, getMethodToInvoke, getProxyFactory, hashCode, invokeOnDelegate
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HotSwappingInvoker

public HotSwappingInvoker(Class[] types,
                          ProxyFactory proxyFactory,
                          ObjectReference delegateReference,
                          int delegationMode)
Construct a HotSwappingInvoker.

Parameters:
types - the types of the proxy
proxyFactory - the ProxyFactory to use
delegateReference - the ObjectReference with the delegate
delegationMode - MODE_DIRECT or MODE_SIGNATURE
Since:
0.2

HotSwappingInvoker

public HotSwappingInvoker(Class[] types,
                          ProxyFactory proxyFactory,
                          ObjectReference delegateReference,
                          boolean staticTyping)
Deprecated. since 0.2, use HotSwappingInvoker(Class[], ProxyFactory, ObjectReference, int)

Construct a HotSwappingInvoker.

Parameters:
types - the types of the proxy
proxyFactory - the ProxyFactory to use
delegateReference - the ObjectReference with the delegate
staticTyping - STATIC_TYPING or DYNAMIC_TYPING
Since:
0.1
Method Detail

invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
Description copied from interface: Invoker
Invocation of a method of the proxied object.

Specified by:
invoke in interface Invoker
Overrides:
invoke in class DelegatingInvoker
Parameters:
proxy - the proxy instance.
method - the method to invoke.
args - the arguments of the mothod.
Returns:
the result of the onvoked method.
Throws:
Throwable - if the invoked method has thrown.

delegate

protected Object delegate()
Description copied from class: DelegatingInvoker
Retrieve the delegated object in derived classes.

Overrides:
delegate in class DelegatingInvoker
Returns:
the delegated object

hotswap

protected Object hotswap(Object newDelegate)
Exchange the current delegate.

Parameters:
newDelegate - the new delegate
Returns:
the old delegate
Throws:
IllegalStateException - if cyclic swapping action is detected
Since:
0.1

proxy

public Object proxy()
Create a proxy for this Invoker. The proxy implements all the types given as parameter to the constructor and implements additionally the Swappable interface.

Returns:
the new proxy
Since:
0.1