[weld-issues] [JBoss JIRA] (WELD-592) Support use of decorator of Callable<T>
Elias Ross (JIRA)
jira-events at lists.jboss.org
Mon Feb 27 16:34:36 EST 2012
[ https://issues.jboss.org/browse/WELD-592?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12671371#comment-12671371 ]
Elias Ross commented on WELD-592:
---------------------------------
I was interested in using CDI for an application that processed requests through a socket listener, much like a web service but for raw binary requests. We used Netty and it seemed appropriate to use CDI in this way.
Although I did have a patch, my old company didn't want me contributing to Open Source.
I never did use CDI but it was a consideration.
It would be kind of neat to tie in Netty and CDI.
> Support use of decorator of Callable<T>
> ---------------------------------------
>
> Key: WELD-592
> URL: https://issues.jboss.org/browse/WELD-592
> Project: Weld
> Issue Type: Feature Request
> Components: Java SE Support
> Reporter: Elias Ross
> Assignee: Peter Royle
> Fix For: TBC
>
>
> Decorator exists for Runnable. Should allow for Callable<T> to be used as well.
> This is actually pretty useful, for example if you want to execute under a temporary new scope in the same thread, e.g.
> @Inject Instance<PaymentProcessor> paymentProcessorSource; // which implements Callable<Result>
> Result result = paymentProcessorSource.get().call();
> Or, in the case of a thread pool, you can use Future<T> etc.
> /**
> * Decorator for all beans which implements Callable. It intercepts the call
> * to the call() method to set up the ThreadContext for the new thread so that
> * instances of @ThreadScoped beans can be correctly resolved.
> */
> @Decorator
> public class CallableDecorator<T> implements Callable<T> {
> @Inject @Delegate Callable<T> callable;
> /**
> * Set up the ThreadContet and delegate.
> */
> public T call()
> {
> // set up context for this thread
> final ThreadContext threadContext = WeldSEBeanRegistrant.THREAD_CONTEXT;
> threadContext.setBeanStore(new HashMapBeanStore());
> threadContext.setActive(true);
> // run the original thread
> try {
> return callable.call();
> } finally {
> threadContext.destroy();
> }
> }
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the weld-issues
mailing list