Package uk.ac.starlink.util
Class MultiplexInvocationHandler<T>
- java.lang.Object
-
- uk.ac.starlink.util.MultiplexInvocationHandler<T>
-
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler
public class MultiplexInvocationHandler<T> extends java.lang.Object implements java.lang.reflect.InvocationHandler
Used to generate a proxy instance which implements a given interface and delegates its calls to each of a given list of target implementations. The content of the list of targets may be changed during the lifetime of this object, but it's not a good idea to do it while a method is being invoked.- Since:
- 6 Jul 2011
- Author:
- Mark Taylor
-
-
Constructor Summary
Constructors Constructor Description MultiplexInvocationHandler(T[] targets)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
createMultiplexer(java.lang.Class<T> clazz)
Returns a new proxy instance which implements the given interface type, and which uses this handler to execute its methods.T[]
getTargets()
Returns the list of delegate implementations.java.lang.Object
invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
Invokes a method by invoking the same method on each of this handler's target instances.void
setTargets(T[] targets)
Sets the list of delegate implementations.
-
-
-
Constructor Detail
-
MultiplexInvocationHandler
public MultiplexInvocationHandler(T[] targets)
Constructor.- Parameters:
targets
- target instances
-
-
Method Detail
-
setTargets
public void setTargets(T[] targets)
Sets the list of delegate implementations.
-
getTargets
public T[] getTargets()
Returns the list of delegate implementations.- Returns:
- target instances
-
invoke
public java.lang.Object invoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args) throws java.lang.Throwable
Invokes a method by invoking the same method on each of this handler's target instances. If any invocation throws an exception, it is thrown from this method and the method is not invoked on later targets. If the method terminates normally, the return value is the return value of the invocation from the first target.- Specified by:
invoke
in interfacejava.lang.reflect.InvocationHandler
- Throws:
java.lang.Throwable
-
-