TomEE Managedexecutorservice and context lookup

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

TomEE Managedexecutorservice and context lookup

hwaastad
Hi,
I'm testing a few scenarios using the concurrentutils and TomEE.

I was wondering if this would work (not working now)

Singleton

// Injecting runnable instance
@Inject
    Instance<DeltaCustomerRetriever> myRetrieverInstance;
.
.
ArrayList<Callable<DeltaCustomer>> retrieverTasks = new ArrayList<>();
DeltaCustomerRetriever myRetriever = myRetrieverInstance.get();
myRetriever.setCustomer(c);
retrieverTasks.add(myRetriever);
ses.invokeAll(retrieverTasks);

And my Callable:
call()
p.put("java.naming.factory.initial", "org.apache.openejb.core.LocalInitialContextFactory");
        final EJBContext ejbContext;
        final InitialContext ctx = new InitialContext(p);
        ejbContext = (EJBContext) ctx.lookup("java:comp/EJBContext");
        LOG.info(ejbContext.getCallerPrincipal().toString());

this results in NPE

Would it be possible to use @resource sessioncontext? (not sure about the spec here)

br hw

Reply | Threaded
Open this post in threaded view
|

Re: TomEE Managedexecutorservice and context lookup

Romain Manni-Bucau
Hi

maybe try removing properties from initial context.

A sample example would be welcomed too to go deeper (but for this case
you can pass the principal directly to your callable which would be
cleaner IMHO)

Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-07-04 12:22 GMT+02:00 hwaastad <[hidden email]>:

> Hi,
> I'm testing a few scenarios using the concurrentutils and TomEE.
>
> I was wondering if this would work (not working now)
>
> Singleton
>
> // Injecting runnable instance
> @Inject
>     Instance<DeltaCustomerRetriever> myRetrieverInstance;
> .
> .
> ArrayList<Callable&lt;DeltaCustomer>> retrieverTasks = new ArrayList<>();
> DeltaCustomerRetriever myRetriever = myRetrieverInstance.get();
> myRetriever.setCustomer(c);
> retrieverTasks.add(myRetriever);
> ses.invokeAll(retrieverTasks);
>
> And my Callable:
> call()
> p.put("java.naming.factory.initial",
> "org.apache.openejb.core.LocalInitialContextFactory");
>         final EJBContext ejbContext;
>         final InitialContext ctx = new InitialContext(p);
>         ejbContext = (EJBContext) ctx.lookup("java:comp/EJBContext");
>         LOG.info(ejbContext.getCallerPrincipal().toString());
>
> this results in NPE
>
> Would it be possible to use @resource sessioncontext? (not sure about the
> spec here)
>
> br hw
>
>
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.n4.nabble.com/TomEE-Managedexecutorservice-and-context-lookup-tp4670305.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: TomEE Managedexecutorservice and context lookup

hwaastad
Sure,
that is possible off cource.

https://github.com/hwaastad/ConcurrentTest.git

br
hw
Reply | Threaded
Open this post in threaded view
|

Re: TomEE Managedexecutorservice and context lookup

Romain Manni-Bucau
Ok

that's cause the EJB is freed (clean up if you want) when the task
execute (concurrency issue if you prefer). So no bug AFAIK but you
need to pass the state you need to the runnable


Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-07-04 13:19 GMT+02:00 hwaastad <[hidden email]>:

> Sure,
> that is possible off cource.
>
> https://github.com/hwaastad/ConcurrentTest.git
>
> br
> hw
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.n4.nabble.com/TomEE-Managedexecutorservice-and-context-lookup-tp4670305p4670309.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: TomEE Managedexecutorservice and context lookup

hwaastad
Okey,
just wondering since it's working in Wildfly 8 ;-)

br hw
Reply | Threaded
Open this post in threaded view
|

Re: TomEE Managedexecutorservice and context lookup

Romain Manni-Bucau
It works in tomee if you wait the task to be executed in the ejb, can be a
timing issue but ejbcontext when you are no more wrapped in an ejb is not
that safe anyway.
Le 4 juil. 2014 19:32, "hwaastad" <[hidden email]> a écrit :

> Okey,
> just wondering since it's working in Wildfly 8 ;-)
>
> br hw
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-Managedexecutorservice-and-context-lookup-tp4670305p4670319.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: TomEE Managedexecutorservice and context lookup

Romain Manni-Bucau
PS: we'll need to support it as well I guess since we already do it
for @Async (and both impl will be the same)


Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-07-04 22:22 GMT+02:00 Romain Manni-Bucau <[hidden email]>:

> It works in tomee if you wait the task to be executed in the ejb, can be a
> timing issue but ejbcontext when you are no more wrapped in an ejb is not
> that safe anyway.
>
> Le 4 juil. 2014 19:32, "hwaastad" <[hidden email]> a écrit :
>
>> Okey,
>> just wondering since it's working in Wildfly 8 ;-)
>>
>> br hw
>>
>>
>>
>> --
>> View this message in context:
>> http://tomee-openejb.979440.n4.nabble.com/TomEE-Managedexecutorservice-and-context-lookup-tp4670305p4670319.html
>> Sent from the TomEE Users mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: TomEE Managedexecutorservice and context lookup

Romain Manni-Bucau
should pass now


Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-07-04 22:42 GMT+02:00 Romain Manni-Bucau <[hidden email]>:

> PS: we'll need to support it as well I guess since we already do it
> for @Async (and both impl will be the same)
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
> 2014-07-04 22:22 GMT+02:00 Romain Manni-Bucau <[hidden email]>:
>> It works in tomee if you wait the task to be executed in the ejb, can be a
>> timing issue but ejbcontext when you are no more wrapped in an ejb is not
>> that safe anyway.
>>
>> Le 4 juil. 2014 19:32, "hwaastad" <[hidden email]> a écrit :
>>
>>> Okey,
>>> just wondering since it's working in Wildfly 8 ;-)
>>>
>>> br hw
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://tomee-openejb.979440.n4.nabble.com/TomEE-Managedexecutorservice-and-context-lookup-tp4670305p4670319.html
>>> Sent from the TomEE Users mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: TomEE Managedexecutorservice and context lookup

hwaastad
That was quickly done :-)

regarding your comment if this is safe or not, could this still be an issue?

br hw
Reply | Threaded
Open this post in threaded view
|

Re: TomEE Managedexecutorservice and context lookup

Romain Manni-Bucau
Well securitycontext is saved now but need to check the spec a bit more.

In all cases not using it but using message passing pattern is better IMHO
and more robust since then it becomes not contextually dependent, testable
and totally thread safe (this case is but it is a more general comment).
 Le 4 juil. 2014 23:04, "hwaastad" <[hidden email]> a écrit :

> That was quickly done :-)
>
> regarding your comment if this is safe or not, could this still be an
> issue?
>
> br hw
>
>
>
> --
> View this message in context:
> http://tomee-openejb.979440.n4.nabble.com/TomEE-Managedexecutorservice-and-context-lookup-tp4670305p4670325.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>