Start Request scope manually fro a worker thread(asynchronous thread) in WAS8

classic Classic list List threaded Threaded
10 messages Options
akm
Reply | Threaded
Open this post in threaded view
|

Start Request scope manually fro a worker thread(asynchronous thread) in WAS8

akm
Since RequestScope is not available as part of the worker thread we are trying to use Deltaspike API to start the RequestScope context, WAS throws exception -
Caused by: java.lang.NoClassDefFoundError: org.apache.webbeans.config.WebBeansContext
        at org.apache.deltaspike.cdise.owb.OpenWebBeansContextControl.getContextsService(OpenWebBeansContextControl.java:225)
        at org.apache.deltaspike.cdise.owb.OpenWebBeansContextControl.startRequestScope(OpenWebBeansContextControl.java:157)
        at org.apache.deltaspike.cdise.owb.OpenWebBeansContextControl.startContext(OpenWebBeansContextControl.java:75)
        at com.ford.doesbatch.inbound.scheduler.TimerListener.timerExpired(TimerListener.java:41)
        at com.ibm.ws.asynchbeans.timer.TimerImpl.callListenerMethod(TimerImpl.java:361)
        at com.ibm.ws.asynchbeans.timer.GenericTimer.run(GenericTimer.java:228)
        at com.ibm.ws.asynchbeans.J2EEContext$RunProxy.run(J2EEContext.java:265)
        at java.security.AccessController.doPrivileged(AccessController.java:298)
        at javax.security.auth.Subject.doAs(Subject.java:495)
        at com.ibm.websphere.security.auth.WSSubject.doAs(WSSubject.java:132)

akm
Reply | Threaded
Open this post in threaded view
|

Re: Start Request scope manually fro a worker thread(asynchronous thread) in WAS8

akm
TimerBean-CDI-Integration.zip


Sample Project EAR...
Reply | Threaded
Open this post in threaded view
|

Re: Start Request scope manually fro a worker thread(asynchronous thread) in WAS8

Mark Struberg
Administrator
Hi akm!

Sadly this does not work on WAS as they are using an ancient OpenWebBeans version.
What is your final goal? Do you just like to use
1.) an asynchronous thread as a parallel scheduler or
2.) just start a short asynchronous task or
3.) do you like to use a real batch?

I’m using WAS8 at some customers myself so don’t hesitate to ask further questions. Please note that WAS-8.5.5.3 seems to be the best version so far. Later versions have a few nasty bugs…

Back to the topic:
In the first case you might use @Startup @javax.ejb.Singjeton and start a timer via TimerService and @TimeOut method. You might also use @Scheduled on a @Singleton.

In the second case you should use an @Asynchronous wrapper. Of course you can always invoke CDI beans from those EJB wrappers!

In the third case you might look at Apache BatchEE which is a JBatch implementation which I have running fine on WAS. Ping me if you need help with setting this up.

hope that helps.

LieGrue,
strub
 

> Am 09.07.2015 um 18:36 schrieb akm <[hidden email]>:
>
> TimerBean-CDI-Integration.zip
> <http://apache-deltaspike-incubator-discussions.2316169.n4.nabble.com/file/n4661027/TimerBean-CDI-Integration.zip>  
>
>
> Sample Project EAR...
>
>
>
> --
> View this message in context: http://apache-deltaspike-incubator-discussions.2316169.n4.nabble.com/Start-Request-scope-manually-fro-a-worker-thread-asynchronous-thread-in-WAS8-tp4661026p4661027.html
> Sent from the Apache DeltaSpike Incubator Discussions mailing list archive at Nabble.com.

akm
Reply | Threaded
Open this post in threaded view
|

Re: Start Request scope manually fro a worker thread(asynchronous thread) in WAS8

akm
Thanks Mark for the reply...  At our company  couple of years ago  we created a Homegrown Async framework (backed by the IBM Timerbean and  database tables).It provides the  Batch Admin screens functionality ,  Jobs Dependency functionality etc...Currently we are trying enable CDI featutes for this framework.

I did use EJB  @Scheduled for the different usecase....  


Reply | Threaded
Open this post in threaded view
|

Re: Start Request scope manually fro a worker thread(asynchronous thread) in WAS8

Mark Struberg
Administrator
The problem I got when I tried this was that the CDI part was perfectly working. But all the com.ibm.ws.* EJB interceptors you get did blow up because those parts were not set up. Sadly this hits you on more CDI beans than you expect :(

As DeltaSpike CdiCtrl was originally the openwebbeans test module you should be able to take the following code and turn it into a CdiCtrl backend:
https://svn.apache.org/repos/asf/openwebbeans/tags/openwebbeans-1.1.6/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/


LieGrue,
strub

> Am 09.07.2015 um 21:53 schrieb akm <[hidden email]>:
>
> Thanks Mark for the reply...  At our company  couple of years ago  we created
> a Homegrown Async framework (backed by the IBM Timerbean and  database
> tables).It provides the  Batch Admin screens functionality ,  Jobs
> Dependency functionality etc...Currently we are trying enable CDI featutes
> for this framework.
>
> I did use EJB  @Scheduled for the different usecase....  
>
>
>
>
>
>
> --
> View this message in context: http://apache-deltaspike-incubator-discussions.2316169.n4.nabble.com/Start-Request-scope-manually-fro-a-worker-thread-asynchronous-thread-in-WAS8-tp4661026p4661030.html
> Sent from the Apache DeltaSpike Incubator Discussions mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Start Request scope manually fro a worker thread(asynchronous thread) in WAS8

Mark Struberg
Administrator
Think you even need to taken an older version
https://svn.apache.org/repos/asf/openwebbeans/tags/openwebbeans-1.0.0/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/


> Am 10.07.2015 um 14:33 schrieb Mark Struberg <[hidden email]>:
>
> The problem I got when I tried this was that the CDI part was perfectly working. But all the com.ibm.ws.* EJB interceptors you get did blow up because those parts were not set up. Sadly this hits you on more CDI beans than you expect :(
>
> As DeltaSpike CdiCtrl was originally the openwebbeans test module you should be able to take the following code and turn it into a CdiCtrl backend:
> https://svn.apache.org/repos/asf/openwebbeans/tags/openwebbeans-1.1.6/webbeans-test/cditest-owb/src/main/java/org/apache/webbeans/cditest/owb/
>
>
> LieGrue,
> strub
>
>> Am 09.07.2015 um 21:53 schrieb akm <[hidden email]>:
>>
>> Thanks Mark for the reply...  At our company  couple of years ago  we created
>> a Homegrown Async framework (backed by the IBM Timerbean and  database
>> tables).It provides the  Batch Admin screens functionality ,  Jobs
>> Dependency functionality etc...Currently we are trying enable CDI featutes
>> for this framework.
>>
>> I did use EJB  @Scheduled for the different usecase....  
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context: http://apache-deltaspike-incubator-discussions.2316169.n4.nabble.com/Start-Request-scope-manually-fro-a-worker-thread-asynchronous-thread-in-WAS8-tp4661026p4661030.html
>> Sent from the Apache DeltaSpike Incubator Discussions mailing list archive at Nabble.com.
>

akm
Reply | Threaded
Open this post in threaded view
|

Re: Start Request scope manually fro a worker thread(asynchronous thread) in WAS8

akm
Thank you Mark... That did work.. Now RequestScope is available for the Batch(Async) Jobs.
akm
Reply | Threaded
Open this post in threaded view
|

Re: Start Request scope manually fro a worker thread(asynchronous thread) in WAS8

akm
Mark,

Now we are getting a NullPointer Exception while  trying to enable the CDI features for the Worker thread (created by the concurrent ExecutorService )in our MultiCore framework. Earlier It did work fine in our asynchronous  framework when  the Worker Thread(Actually this worker thread is managed by the websphere-web container) is created using the CommonJ-API.

WebSphere Platform  : 8.0.0.7


[7/16/15 17:54:00:639 UTC] 000000c5 ManagedBean   E ManagedBean injectResources An error occured while injecting Java EE Resources for the bean instance : [org.apache.deltaspike.cdise.owb.OpenWebBeansContextControl@f23932f9]
[7/16/15 17:54:00:642 UTC] 000000c5 TaskExecutor  E com.ford.it.mccdi.TaskExecutor logTaskNotProcessedException com.ford.it.mccdi.TaskExecutor@aca78cc4 Exception is
                                 java.lang.NullPointerException
        at com.ibm.ws.webbeans.services.ResourceInjectionServiceImpl.injectJavaEEResources(ResourceInjectionServiceImpl.java:532)
        at org.apache.webbeans.component.AbstractInjectionTargetBean.injectResources(AbstractInjectionTargetBean.java:414)
        at org.apache.webbeans.portable.creation.InjectionTargetProducer.inject(InjectionTargetProducer.java:93)
        at org.apache.webbeans.component.InjectionTargetWrapper.inject(InjectionTargetWrapper.java:80)
        at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:175)
        at org.apache.webbeans.context.DependentContext.getInstance(DependentContext.java:69)
        at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:191)
        at org.apache.webbeans.container.BeanManagerImpl.getReference(BeanManagerImpl.java:892)
        at org.apache.webbeans.container.InjectableBeanManager.getReference(InjectableBeanManager.java:137)
akm
Reply | Threaded
Open this post in threaded view
|

Re: Start Request scope manually fro a worker thread(asynchronous thread) in WAS8

akm
CDI-WorkerThread.zip

Attached a Sample-EAR Project.

TestCdiServlet -Front Controller...
Reply | Threaded
Open this post in threaded view
|

Re: Start Request scope manually fro a worker thread(asynchronous thread) in WAS8

Mark Struberg
Administrator
In reply to this post by akm

> Am 16.07.2015 um 20:27 schrieb akm <[hidden email]>:
>
> injectJavaEEResources

ouch, this indicates that some non-CDI EE stuff is not set up and you use it in this thread. In that case it might be better to use @javax.ejb.Asynchronous to start this new thread. Please note that you might need to tweak timeouts etc for this freshly spawned thread.

LieGrue,
strub