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);
}
Aggregations