com.iparelan.util
Class ConcurrencyTools.ThreadPoolProxyInvocationHandler<T>

java.lang.Object
  extended by com.iparelan.util.ConcurrencyTools.ThreadPoolProxyInvocationHandler<T>
Type Parameters:
T - The type of the proxied object.
All Implemented Interfaces:
InvocationHandler
Enclosing class:
ConcurrencyTools

private static final class ConcurrencyTools.ThreadPoolProxyInvocationHandler<T>
extends Object
implements InvocationHandler

Dispatches proxied method invocations through a thread pool.

To Do:

Field Summary
private  ThreadPoolExecutor executorService
          The ExecutorService on which method invocations are dispatched.
private  T proxied
          The object proxied by the dynamic proxy.
 
Constructor Summary
ConcurrencyTools.ThreadPoolProxyInvocationHandler(String poolName, T proxied)
          Creates a ThreadPoolProxyInvocationHandler.
 
Method Summary
private  Method getMethod(Class<?> proxiedType, String methodName, Class<?>... parameterTypes)
          Produced the named Method on the specified type or null if the type has no such Method.
 Object invoke(Object proxy, Method method, Object[] args)
          Invokes method on the proxied object with args.
private  Object invokeNonShutdownable(Method method, Object[] args)
           
private  Object invokeShutdownable(Method method, Object[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

proxied

private final T proxied
The object proxied by the dynamic proxy.


executorService

private final ThreadPoolExecutor executorService
The ExecutorService on which method invocations are dispatched.

Constructor Detail

ConcurrencyTools.ThreadPoolProxyInvocationHandler

ConcurrencyTools.ThreadPoolProxyInvocationHandler(String poolName,
                                                  T proxied)
Creates a ThreadPoolProxyInvocationHandler.

Parameters:
poolName - The name of the thread pool. May be neither null nor the empty string.
proxied - The object on which to invoke proxied methods. May not be null.
Throws:
IllegalArgumentException - Iff proxied is null.
See Also:
newThreadPoolProxy(String, T, Class...)
To Do:
  • Add a parameter like this:

    param exceptionType (final Class exceptionType)

    The type of exception to throw if there is an error during reflective proxy method invocation. May be null in which case a ProxyException is thrown.

  • Magic numbers: corePoolSize, maximumPoolSize, keepAliveTime.
Method Detail

invoke

@UnknownNullness
public Object invoke(Object proxy,
                                     Method method,
                                     Object[] args)
Invokes method on the proxied object with args. If method is a method of the ConcurrencyTools.Shutdownable interface, then the method is dispatched to the ExecutorService associated to this InvocationHandler first, then to the proxied object as appropriate.

For example, ConcurrencyTools.Shutdownable.isShutdown() is dispatched to the ExecutorService and if the result is true, then it is dispatched to the proxied object and that value is produced.

Specified by:
invoke in interface InvocationHandler
Parameters:
proxy -
method -
args -
Throws:
ProxyException - Iff method cannot be invoked on the proxied object with args.

invokeNonShutdownable

@UnknownNullness
private Object invokeNonShutdownable(Method method,
                                                     Object[] args)

invokeShutdownable

@UnknownNullness
private Object invokeShutdownable(Method method,
                                                  Object[] args)

getMethod

@Nullable
private Method getMethod(Class<?> proxiedType,
                                  String methodName,
                                  Class<?>... parameterTypes)
Produced the named Method on the specified type or null if the type has no such Method.

Parameters:
proxiedType - The type from which to retrieve the named Method. May not be null.
methodName - The name of the Method to get from proxiedType. May be neither null nor the empty string.
parameterTypes - The method parameter types. May be null or an empty array to express a method.
Returns:
The named Method of proxiedType or null if proxiedType does not have a Method named methodName with parameter types of parameterTypes.


Copyright © 2008 Iparelan Solutions, LLC. All rights reserved.