com.thoughtworks.proxy.toys.hotswap
Class HotSwappingInvoker<T>

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

public class HotSwappingInvoker<T>
extends DelegatingInvoker<Object>

A DelegatingInvoker implementation that allows the exchange of the delegate.

Since:
0.1
Author:
Aslak Hellesøy, Dan North, 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<Object> delegateReference, DelegationMode 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.
 T 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<Object> delegateReference,
                          DelegationMode delegationMode)
Construct a HotSwappingInvoker.

Parameters:
types - the types of the proxy
proxyFactory - the ProxyFactory to use
delegateReference - the ObjectReference with the delegate
delegationMode - DelegationMode.DIRECT or DelegationMode.SIGNATURE
Since:
1.0
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<Object>
Parameters:
proxy - the proxy instance.
method - the method to invoke.
args - the arguments of the method.
Returns:
the result of the invoked 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<Object>
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 T 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


Copyright © 2005-2010 Codehaus. All Rights Reserved.