This content has been marked as final.
Show 2 replies
-
1. Re: hack @asynchronous implementation
alesj Oct 21, 2012 4:54 PM (in response to matlach)A quick idea from the top of my head ... might not work.
(1) Make sure this interceptor is the first, ignore async logic if ThreadLocal from (3) is set.
(2) Then gather target information from existing InvocationContext - target, method, params, ...
(3) In Callable::call setup a ThreadLocal, invoke target with method, params, reset ThreadLocal.
Let me know if it works. :-)
-
2. Re: hack @asynchronous implementation
matlach Oct 21, 2012 5:44 PM (in response to alesj)you're a genius Ales !
this works flawlessy :
@Asynchronous @Interceptor public class AsynchronousInterceptor { private static ThreadLocal<Object> hack = new ThreadLocal<Object>(); @Inject private AsynchronousService asynchronousService; @AroundInvoke public Object runAsync(final InvocationContext ctx) throws Exception { // we assume AsynchronousInterceptor is the first in chain if (hack.get() == null) { asynchronousService.submit(new Callable<Void>(){ @Override public Void call() throws Exception { hack.set(new Object()); try { ctx.getMethod().invoke(ctx.getTarget(), ctx.getParameters()); } finally { hack.remove(); } return null; }}); } else { ctx.proceed(); } return null; } }