You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openwebbeans.apache.org by Mario Ivankovits <ma...@ops.co.at> on 2010/04/12 13:31:31 UTC

ContextsService for standalone applications

Hi!



I am developing a "standalone" Swing Application and trying to make use of CDI 
(using openwebbeans). Also for being more fit when discussing Orchestra 
related things :-)





Naturally a Swing Application consists of multiple threads. At least the main 
thread and the so called Event Dispatcher Thread (EDT) for UI handling.

Beside this you will find a lot of other short-time threads handling actions 
triggered by the user through the UI.



The problem I have is the org.apache.webbeans.spi.se.DefaultContextsService 
class which uses ThreadLocals to store all the contexts.



I think this is not right, at least not for all the contexts provided.

For example the ApplicationContext, SessionContext, SingletonContext and 
DependentContext should be a simple member of the class. Not sure about (CDI 
like) ConversationContext.

The RequestContext might be arguable to life with the Thread - however, the 
developer need to take care to destroy the RequestContext manually somehow - 
or something we can implment into the Swing Application Framework.



For now I solved that by providing my own ContextsService impl through 
openwebbeans.properties.





Also, like in Weld, I'd love to see some utility class to startup CDI in an 
standalone app. Once you figured out it is easy already, but it can be even 
more easy, and we can provide some predefined events like ContainerInitialized 
[1].





Said that (and given my observations are correct), what do you think about 
starting up a webbeans-se module where we put these things together?

It won't grow to a huge project, though.



Ciao,

Mario



[1] 
http://www.jarvana.com/jarvana/view/org/jboss/weld/weld-se/1.0.0-CR2/weld-se-1.0.0-CR2-javadoc.jar!/org/jboss/weld/environment/se/events/ContainerInitialized.html


AW: ContextsService for standalone applications

Posted by Mario Ivankovits <ma...@ops.co.at>.
Hi!

Actually, I have it working here already. :-)
And yes, I looked at the Swing example.

With this simple example the ThreadLocal problem in the
DefaultContextsService does not take effect, but as soon as you e.g. use the
BeanManager to get a reference to a bean from various threads problems will
arise.
Depending on the flow also the normal @Inject annotation will not work
correctly.

Ciao,
Mario

-----Ursprüngliche Nachricht-----
Von: Gurkan Erdogdu [mailto:cgurkanerdogdu@gmail.com] 
Gesendet: Montag, 12. April 2010 16:30
An: dev@openwebbeans.apache.org
Betreff: Re: ContextsService for standalone applications

Hello;

That is great news, creating a maven module with webbeans-se.

In the mean time, could you look at org.apache.webbeans.boot.Bootstrap
class. Also there is a Java Swing sample, maybe you could want to look at
it, it is located in the samples/standalone-sample.



Thanks;

--Gurkan

2010/4/12 Mario Ivankovits <ma...@ops.co.at>

>  Hi!
>
>
>
> I am developing a "standalone" Swing Application and trying to make use of
> CDI (using openwebbeans). Also for being more fit when discussing
Orchestra
> related things :-)
>
>
>
>
>
> Naturally a Swing Application consists of multiple threads. At least the
> main thread and the so called Event Dispatcher Thread (EDT) for UI
handling.
>
> Beside this you will find a lot of other short-time threads handling
> actions triggered by the user through the UI.
>
>
>
> The problem I have is the
org.apache.webbeans.spi.se.DefaultContextsService
> class which uses ThreadLocals to store all the contexts.
>
>
>
> I think this is not right, at least not for all the contexts provided.
>
> For example the ApplicationContext, SessionContext, SingletonContext and
> DependentContext should be a simple member of the class. Not sure about
(CDI
> like) ConversationContext.
>
> The RequestContext might be arguable to life with the Thread - however,
the
> developer need to take care to destroy the RequestContext manually somehow
-
> or something we can implment into the Swing Application Framework.
>
>
>
> For now I solved that by providing my own ContextsService impl through
> openwebbeans.properties.
>
>
>
>
>
> Also, like in Weld, I'd love to see some utility class to startup CDI in
an
> standalone app. Once you figured out it is easy already, but it can be
even
> more easy, and we can provide some predefined events like
> ContainerInitialized [1].
>
>
>
>
>
> Said that (and given my observations are correct), what do you think about
> starting up a webbeans-se module where we put these things together?
>
> It won't grow to a huge project, though.
>
>
>
> Ciao,
>
> Mario
>
>
>
> [1]
>
http://www.jarvana.com/jarvana/view/org/jboss/weld/weld-se/1.0.0-CR2/weld-se
-1.0.0-CR2-javadoc.jar!/org/jboss/weld/environment/se/events/ContainerInitia
lized.html<http://www.jarvana.com/jarvana/view/org/jboss/weld/weld-se/1.0.0-
CR2/weld-se-1.0.0-CR2-javadoc.jar%21/org/jboss/weld/environment/se/events/Co
ntainerInitialized.html>
>



-- 
Gurkan Erdogdu
http://gurkanerdogdu.blogspot.com

Re: ContextsService for standalone applications

Posted by Gurkan Erdogdu <cg...@gmail.com>.
Hello;

That is great news, creating a maven module with webbeans-se.

In the mean time, could you look at org.apache.webbeans.boot.Bootstrap
class. Also there is a Java Swing sample, maybe you could want to look at
it, it is located in the samples/standalone-sample.



Thanks;

--Gurkan

2010/4/12 Mario Ivankovits <ma...@ops.co.at>

>  Hi!
>
>
>
> I am developing a "standalone" Swing Application and trying to make use of
> CDI (using openwebbeans). Also for being more fit when discussing Orchestra
> related things :-)
>
>
>
>
>
> Naturally a Swing Application consists of multiple threads. At least the
> main thread and the so called Event Dispatcher Thread (EDT) for UI handling.
>
> Beside this you will find a lot of other short-time threads handling
> actions triggered by the user through the UI.
>
>
>
> The problem I have is the org.apache.webbeans.spi.se.DefaultContextsService
> class which uses ThreadLocals to store all the contexts.
>
>
>
> I think this is not right, at least not for all the contexts provided.
>
> For example the ApplicationContext, SessionContext, SingletonContext and
> DependentContext should be a simple member of the class. Not sure about (CDI
> like) ConversationContext.
>
> The RequestContext might be arguable to life with the Thread - however, the
> developer need to take care to destroy the RequestContext manually somehow -
> or something we can implment into the Swing Application Framework.
>
>
>
> For now I solved that by providing my own ContextsService impl through
> openwebbeans.properties.
>
>
>
>
>
> Also, like in Weld, I'd love to see some utility class to startup CDI in an
> standalone app. Once you figured out it is easy already, but it can be even
> more easy, and we can provide some predefined events like
> ContainerInitialized [1].
>
>
>
>
>
> Said that (and given my observations are correct), what do you think about
> starting up a webbeans-se module where we put these things together?
>
> It won't grow to a huge project, though.
>
>
>
> Ciao,
>
> Mario
>
>
>
> [1]
> http://www.jarvana.com/jarvana/view/org/jboss/weld/weld-se/1.0.0-CR2/weld-se-1.0.0-CR2-javadoc.jar!/org/jboss/weld/environment/se/events/ContainerInitialized.html<http://www.jarvana.com/jarvana/view/org/jboss/weld/weld-se/1.0.0-CR2/weld-se-1.0.0-CR2-javadoc.jar%21/org/jboss/weld/environment/se/events/ContainerInitialized.html>
>



-- 
Gurkan Erdogdu
http://gurkanerdogdu.blogspot.com