org.javasimon.callback.async
Class AsyncCallbackProxyFactory

java.lang.Object
  extended by org.javasimon.proxy.DelegatingProxyFactory<T>
      extended by org.javasimon.callback.async.ExecutorProxyFactory<Callback>
          extended by org.javasimon.callback.async.AsyncCallbackProxyFactory
All Implemented Interfaces:
InvocationHandler, Delegating<Callback>

public final class AsyncCallbackProxyFactory
extends ExecutorProxyFactory<Callback>

Callback factory, produces a callback wrapper to make any callback asynchronous. Example: Callback myAsyncCallback=new AsyncCallbackProxy(myCallback).newProxy(); The purpose of this wrapping callback is to prevent the wrapped callback from being executed on the main thread. This can be useful when a concrete callback is time consuming, to reduce the impact on application performances. It can be used to disable/enable, at runtime, a callback without removing it from the SimonManager: asyncCallbackProxy.setExecutor(Executors.disabled());

Author:
gerald

Field Summary
private  Method getDelegateMethod
           
private static Class[] PROXY_INTERFACES
          Interfaces implemented by callback proxy
 
Constructor Summary
AsyncCallbackProxyFactory(Callback delegate)
          Constructor
AsyncCallbackProxyFactory(Callback delegate, Executor executor)
          Constructor
 
Method Summary
private  Method findGetDelegateMethod()
          Find Delegating.getDelegate() method
protected  Object invoke(DelegatingMethodInvocation<Callback> delegatingMethodInvocation)
          Method to override in child classes
 Callback newProxy()
          Creates a callback proxy.
 Callback newProxy(ClassLoader classLoader)
          Creates a callback proxy.
 
Methods inherited from class org.javasimon.callback.async.ExecutorProxyFactory
getExecutor, setExecutor
 
Methods inherited from class org.javasimon.proxy.DelegatingProxyFactory
getDelegate, invoke, newProxy, newProxy, newProxy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROXY_INTERFACES

private static final Class[] PROXY_INTERFACES
Interfaces implemented by callback proxy


getDelegateMethod

private final Method getDelegateMethod
Constructor Detail

AsyncCallbackProxyFactory

public AsyncCallbackProxyFactory(Callback delegate)
Constructor

Parameters:
delegate - Wrapped object

AsyncCallbackProxyFactory

public AsyncCallbackProxyFactory(Callback delegate,
                                 Executor executor)
Constructor

Parameters:
delegate - Wrapped object
executor - Executor used to run callback method, see Executors
Method Detail

findGetDelegateMethod

private Method findGetDelegateMethod()
Find Delegating.getDelegate() method

Returns:
Get delegate method

newProxy

public Callback newProxy(ClassLoader classLoader)
Creates a callback proxy.

Parameters:
classLoader - Class loader
Returns:
Callback proxy.

newProxy

public Callback newProxy()
Creates a callback proxy. The class loader for current thread is used as default class loader.

Parameters:
classLoader - Class loader
Returns:
Callback proxy.

invoke

protected Object invoke(DelegatingMethodInvocation<Callback> delegatingMethodInvocation)
                 throws Throwable
Description copied from class: DelegatingProxyFactory
Method to override in child classes

Overrides:
invoke in class ExecutorProxyFactory<Callback>
Parameters:
delegatingMethodInvocation - Method invocation (arguments, method name, etc.)
Returns:
Method invocation results
Throws:
Throwable - Method invocation raised exception


Copyright © 2013. All Rights Reserved.