Search in sources :

Example 1 with WrappedInvocationHandler

use of games.strategy.triplea.util.WrappedInvocationHandler in project triplea by triplea-game.

the class DelegateExecutionManager method createInboundImplementation.

/**
 * Use to create an object that begins delegate execution.
 *
 * <p>
 * Objects on this method will increment the thread lock count when called, and will decrement it again when execution
 * is finished.
 * </p>
 */
public Object createInboundImplementation(final Object implementor, final Class<?>[] interfaces) {
    assertGameNotOver();
    final InvocationHandler ih = new WrappedInvocationHandler(implementor) {

        @Override
        public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
            if (super.shouldHandle(method, args)) {
                return super.handle(method, args);
            }
            assertGameNotOver();
            enterDelegateExecution();
            try {
                return method.invoke(implementor, args);
            } catch (final InvocationTargetException ite) {
                assertGameNotOver();
                throw ite.getCause();
            } catch (final RuntimeException re) {
                assertGameNotOver();
                throw re;
            } finally {
                leaveDelegateExecution();
            }
        }
    };
    return Proxy.newProxyInstance(implementor.getClass().getClassLoader(), interfaces, ih);
}
Also used : WrappedInvocationHandler(games.strategy.triplea.util.WrappedInvocationHandler) Method(java.lang.reflect.Method) WrappedInvocationHandler(games.strategy.triplea.util.WrappedInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

WrappedInvocationHandler (games.strategy.triplea.util.WrappedInvocationHandler)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1