use of org.eclipse.scout.rt.platform.context.RunWithRunContext in project scout.rt by eclipse.
the class PortProducer method proxyHandler.
/**
* Proxies the given {@link Handler} to run on behalf of a {@link RunContext}, if the handler is annotated with
* {@link RunWithRunContext}.
*/
protected Handler<? extends MessageContext> proxyHandler(final Handler<? extends MessageContext> handler) {
final RunWithRunContext handleWithRunContext = handler.getClass().getAnnotation(RunWithRunContext.class);
if (handleWithRunContext == null) {
return handler;
}
final RunContextProducer runContextProducer = BEANS.get(handleWithRunContext.value());
return (Handler<?>) Proxy.newProxyInstance(handler.getClass().getClassLoader(), handler.getClass().getInterfaces(), new InvocationHandler() {
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
if (PROXIED_HANDLER_METHODS.contains(method)) {
return runContextProducer.produce(Subject.getSubject(AccessController.getContext())).call(new Callable<Object>() {
@Override
public Object call() throws Exception {
return method.invoke(handler, args);
}
}, DefaultExceptionTranslator.class);
} else {
return method.invoke(handler, args);
}
}
});
}
use of org.eclipse.scout.rt.platform.context.RunWithRunContext in project scout.rt by eclipse.
the class ServicePool method proxyHandler.
/**
* Proxies the given {@link Handler} to run on behalf of a {@link RunContext}, if the handler is annotated with
* {@link RunWithRunContext}.
*/
protected Handler<? extends MessageContext> proxyHandler(final Handler<? extends MessageContext> handler) {
final RunWithRunContext handleWithRunContext = handler.getClass().getAnnotation(RunWithRunContext.class);
if (handleWithRunContext == null) {
return handler;
}
final RunContextProducer runContextProducer = BEANS.get(handleWithRunContext.value());
return (Handler<?>) Proxy.newProxyInstance(handler.getClass().getClassLoader(), handler.getClass().getInterfaces(), new InvocationHandler() {
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
if (PROXIED_HANDLER_METHODS.contains(method)) {
return runContextProducer.produce(Subject.getSubject(AccessController.getContext())).call(new Callable<Object>() {
@Override
public Object call() throws Exception {
return method.invoke(handler, args);
}
}, DefaultExceptionTranslator.class);
} else {
return method.invoke(handler, args);
}
}
});
}
Aggregations