You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@openwebbeans.apache.org by Harald Wellmann <hw...@googlemail.com> on 2012/06/22 19:24:47 UTC

Booting in Java SE?

What's the proper way of starting OWB in a Java SE environment?

The corresponding section in the User Guide is empty.

samples/standalone-sample/src/main/java/org/apache/webbeans/se/sample/Boot.java
uses WebBeansContext.getInstance(), but this method is deprecated and
does not document its replacement.

Best regards,
Harald

Re: Booting in Java SE?

Posted by Mark Struberg <st...@yahoo.de>.
Well, request, session and conversation DO make sense in at least _some_ SE apps. It's only a matter of the interpretation. 


Especially if your app is multithreaded and you e.g. work with JPA or other single-threaded-only resources. In that case you could use the @RequestScoped to provide exactly that. A 'conversation' or 'session' might also be handy  in case of parallel batch processing for example.

Of course, they are _not_ Web Requests, Session, etc - but they are nonetheless useful.


LieGrue,
strub



----- Original Message -----
> From: Harald Wellmann <hw...@googlemail.com>
> To: user@openwebbeans.apache.org
> Cc: 
> Sent: Friday, June 22, 2012 8:47 PM
> Subject: Re: Booting in Java SE?
> 
> Am 22.06.2012 20:30, schrieb Mark Struberg:
>>  It's not only about starting the container itself. You also need to 
> control the Contexts ;)
>> 
> 
> Do I? I'd expect the container SE adapter to take care of that...
> 
> Weld SE automatically starts the application context, AFAIK. And request, 
> session and conversation contexts don't make sense in Java SE, anyway.
> 
>>  PS: it's out of question that our documentation currently is not our 
> strongest point :D
> 
> So it seems this list isn't busy enough, or else you'd save time writing 
> docs instead of answering emails ;-)
> 
> 
>>  WebBeansContext.currentInstance() is an INTERNAL method
> 
> But it doesn't say so...
> 
>>  cdictrl shields all this away from your customer project!
> 
> Oh, it's not about a customer project. I'm currently experimenting with 
> CDI + OSGi, and that will require some low-level classloader wrestling and other 
> nasty stuff anyway.
> 
> Best regards,
> Harald
> 

Re: Booting in Java SE?

Posted by Harald Wellmann <hw...@googlemail.com>.
Am 22.06.2012 20:30, schrieb Mark Struberg:
> It's not only about starting the container itself. You also need to control the Contexts ;)
>

Do I? I'd expect the container SE adapter to take care of that...

Weld SE automatically starts the application context, AFAIK. And 
request, session and conversation contexts don't make sense in Java SE, 
anyway.

> PS: it's out of question that our documentation currently is not our strongest point :D

So it seems this list isn't busy enough, or else you'd save time writing 
docs instead of answering emails ;-)


 > WebBeansContext.currentInstance() is an INTERNAL method

But it doesn't say so...

 > cdictrl shields all this away from your customer project!

Oh, it's not about a customer project. I'm currently experimenting with 
CDI + OSGi, and that will require some low-level classloader wrestling 
and other nasty stuff anyway.

Best regards,
Harald

Re: Booting in Java SE?

Posted by Mark Struberg <st...@yahoo.de>.
It's not only about starting the container itself. You also need to control the Contexts ;)

LieGrue,
strub

PS: it's out of question that our documentation currently is not our strongest point :D




>________________________________
> From: Harald Wellmann <hw...@googlemail.com>
>To: user@openwebbeans.apache.org 
>Sent: Friday, June 22, 2012 8:18 PM
>Subject: Re: Booting in Java SE?
> 
>Hi Mark,
>
>Quoting from your blog:
>
><quote>
>Have you ever tried to boot a CDI container like JBoss Weld or Apache 
>OpenWebBeans in Java SE? While doing this task you will end up knee deep 
>in the implementation code of the container you are using!
></quote>
>
>Well, I've never had any trouble using
>
>   new Weld().initialize();
>
>that's simple enough and documented, so where's the problem?
>
>Only with OWB I'm currently knee-deep in source code, for lack of decent 
>documentation....
>
>Deltaspike as another wrapper doesn't help understanding the underlying 
>containers, either.
>
>Of course, it's nice to have such an abstraction, but I think this 
>should really be part of the official CDI API.
>
>I believe there's a CDI spec JIRA issue on this topic - is there any 
>progress for CDI 1.1?
>
>Best regards,
>Harald
>
>
>
>Am 22.06.2012 19:46, schrieb Mark Struberg:
>> Hi Harald!
>>
>>
>> Those days I recommend to use DeltaSpike cdictrl [1]. The work is based on the stuff we did in OWB cdi-test, but we also added implementations not only for OpenWebBeans, but also for JBoss Weld and Apache TomEE. Others might follow ;)
>>
>>
>> I also wrote a small blog about it recently [2][3].
>>
>>
>> LieGrue,
>> strub
>>
>>
>> [1] https://cwiki.apache.org/confluence/display/DeltaSpike/Temporary+Documentation#TemporaryDocumentation-WithJavaSE
>> [2] http://struberg.wordpress.com/2012/03/17/controlling-cdi-containers-in-se-and-ee/
>> [3] http://struberg.wordpress.com/2012/03/27/unit-testing-strategies-for-cdi-based-projects/
>>
>
>
>

Re: Booting in Java SE?

Posted by Harald Wellmann <hw...@googlemail.com>.
Hi Mark,

Quoting from your blog:

<quote>
Have you ever tried to boot a CDI container like JBoss Weld or Apache 
OpenWebBeans in Java SE? While doing this task you will end up knee deep 
in the implementation code of the container you are using!
</quote>

Well, I've never had any trouble using

   new Weld().initialize();

that's simple enough and documented, so where's the problem?

Only with OWB I'm currently knee-deep in source code, for lack of decent 
documentation....

Deltaspike as another wrapper doesn't help understanding the underlying 
containers, either.

Of course, it's nice to have such an abstraction, but I think this 
should really be part of the official CDI API.

I believe there's a CDI spec JIRA issue on this topic - is there any 
progress for CDI 1.1?

Best regards,
Harald



Am 22.06.2012 19:46, schrieb Mark Struberg:
> Hi Harald!
>
>
> Those days I recommend to use DeltaSpike cdictrl [1]. The work is based on the stuff we did in OWB cdi-test, but we also added implementations not only for OpenWebBeans, but also for JBoss Weld and Apache TomEE. Others might follow ;)
>
>
> I also wrote a small blog about it recently [2][3].
>
>
> LieGrue,
> strub
>
>
> [1] https://cwiki.apache.org/confluence/display/DeltaSpike/Temporary+Documentation#TemporaryDocumentation-WithJavaSE
> [2] http://struberg.wordpress.com/2012/03/17/controlling-cdi-containers-in-se-and-ee/
> [3] http://struberg.wordpress.com/2012/03/27/unit-testing-strategies-for-cdi-based-projects/
>

Re: Booting in Java SE?

Posted by Mark Struberg <st...@yahoo.de>.
Hi Harald!


Those days I recommend to use DeltaSpike cdictrl [1]. The work is based on the stuff we did in OWB cdi-test, but we also added implementations not only for OpenWebBeans, but also for JBoss Weld and Apache TomEE. Others might follow ;)


I also wrote a small blog about it recently [2][3].


LieGrue,
strub


[1] https://cwiki.apache.org/confluence/display/DeltaSpike/Temporary+Documentation#TemporaryDocumentation-WithJavaSE
[2] http://struberg.wordpress.com/2012/03/17/controlling-cdi-containers-in-se-and-ee/
[3] http://struberg.wordpress.com/2012/03/27/unit-testing-strategies-for-cdi-based-projects/

>________________________________
> From: Romain Manni-Bucau <rm...@gmail.com>
>To: user@openwebbeans.apache.org 
>Sent: Friday, June 22, 2012 7:28 PM
>Subject: Re: Booting in Java SE?
> 
>
>Hi, in openwebbeans-test you have the CdiContainer.
>In deltaspike project you have a common api between owb and weld.
>Both are fine.
>- Romain
>Le 22 juin 2012 19:25, "Harald Wellmann" <hw...@googlemail.com> a écrit :
>
>What's the proper way of starting OWB in a Java SE environment?
>>
>>The corresponding section in the User Guide is empty.
>>
>>samples/standalone-sample/src/main/java/org/apache/webbeans/se/sample/Boot.java
>>uses WebBeansContext.getInstance(), but this method is deprecated and
>>does not document its replacement.
>>
>>Best regards,
>>Harald
>>
>
>

Re: Booting in Java SE?

Posted by Mark Struberg <st...@yahoo.de>.

Hi Romain!

Using openejb would be an option, but the problem is not openejb, but that you get tons of additional APIs he might not need.

I really suggest to use DeltaSpike for this. It provides a portable API 
which works with lots of containers (including openejb btw). 



And here comes how it goes. Please put the following into your pom.xml:

><properties>
>    <deltaspike.version>0.2-incubating</deltaspike.version>
></properties>
>...
><dependencies>
>    <dependency>
>        <groupId>org.apache.deltaspike.cdictrl</groupId>
>        <artifactId>deltaspike-cdictrl-api</artifactId>
>        <version>${deltaspike.version}</version>
>        <scope>compile</scope>
>    </dependency>
>    <dependency>
>        <groupId>org.apache.deltaspike.cdictrl</groupId>
>        <artifactId>deltaspike-cdictrl-owb</artifactId>
>        <version>${deltaspike.version}</version>
>        <scope>runtime</scope>
>    </dependency>
></dependencies>



And then you can use the following Code:

>import org.apache.deltaspike.cdise.api.CdiContainer;
>import org.apache.deltaspike.cdise.api.CdiContainerLoader;
>
>...
>CdiContainer cdiContainer= CdiContainerLoader.getCdiContainer();
>cdiContainer.boot();
>cdiContainer.getContextControl().startContexts();>
>....
>
>cdiContainer.shutdown();



That's all, there is nothing more needed...


LieGrue,
strub



>________________________________
> From: Romain Manni-Bucau <rm...@gmail.com>
>To: user@openwebbeans.apache.org 
>Sent: Friday, June 22, 2012 7:51 PM
>Subject: Re: Booting in Java SE?
> 
>
>Getunstance is replaced by currentinstance, just a semantic change.
>There is no standard api that's why it is in test module but it is comparable to weldse. Deltaspike is the proof. If you want sthg standard there is the EJBContainer and openejb for instance.
>- Romain
>Le 22 juin 2012 19:47, "Harald Wellmann" <hw...@googlemail.com> a écrit :
>
>Am 22.06.2012 19:28, schrieb Romain Manni-Bucau:
>>
>>Hi, in openwebbeans-test you have the CdiContainer.
>>>
>>>
>>Do you mean org.apache.webbeans.cditest.CdiTestContainer in org.apache.openwebbeans.test:cditest:1.1.4?
>>
>>The corresponding implementation class CdiTestOpenWebBeansContainer also calls WebBeansContext.getInstance() in its bootContainer() methods.
>>
>>Besides, isn't this container meant for testing and not for running applications?
>>
>>I'm looking for something like weld-se.
>>
>>Best regards,
>>Harald
>>
>
>

Re: Booting in Java SE?

Posted by Mark Struberg <st...@yahoo.de>.
Hi Harald!

WebBeansContext.currentInstance() is an INTERNAL method - I really suggest to use NONE of them in a customer project.

cdictrl shields all this away from your customer project!

LieGrue,
strub


----- Original Message -----
> From: Harald Wellmann <hw...@googlemail.com>
> To: user@openwebbeans.apache.org
> Cc: 
> Sent: Friday, June 22, 2012 8:02 PM
> Subject: Re: Booting in Java SE?
> 
> Am 22.06.2012 19:51, schrieb Romain Manni-Bucau:
>>  Getunstance is replaced by currentinstance, just a semantic change.
>> 
> 
> Ok. so I'll use WebBeansContext.currentInstance(). You might want to add a 
> reference to the getInstance() Javadoc, though. Users tend to get confused when 
> you deprecate a method and don't tell them what to use instead ;-)
> 
> 
> 
>>  There is no standard api that's why it is in test module but it is
>>  comparable to weldse. Deltaspike is the proof. If you want sthg standard
>>  there is the EJBContainer and openejb for instance.
> 
> Yes, but there are no EJBs in Java SE...
> 
> Best regards,
> Harald
> 

Re: Booting in Java SE?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
No cdi bean neither today so same fight ;)
Le 22 juin 2012 20:02, "Harald Wellmann" <hw...@googlemail.com> a
écrit :

> Am 22.06.2012 19:51, schrieb Romain Manni-Bucau:
>
>> Getunstance is replaced by currentinstance, just a semantic change.
>>
>>
> Ok. so I'll use WebBeansContext.**currentInstance(). You might want to
> add a reference to the getInstance() Javadoc, though. Users tend to get
> confused when you deprecate a method and don't tell them what to use
> instead ;-)
>
>
>
>  There is no standard api that's why it is in test module but it is
>> comparable to weldse. Deltaspike is the proof. If you want sthg standard
>> there is the EJBContainer and openejb for instance.
>>
>
> Yes, but there are no EJBs in Java SE...
>
> Best regards,
> Harald
>
>

Re: Booting in Java SE?

Posted by Harald Wellmann <hw...@googlemail.com>.
Am 22.06.2012 19:51, schrieb Romain Manni-Bucau:
> Getunstance is replaced by currentinstance, just a semantic change.
>

Ok. so I'll use WebBeansContext.currentInstance(). You might want to add 
a reference to the getInstance() Javadoc, though. Users tend to get 
confused when you deprecate a method and don't tell them what to use 
instead ;-)



> There is no standard api that's why it is in test module but it is
> comparable to weldse. Deltaspike is the proof. If you want sthg standard
> there is the EJBContainer and openejb for instance.

Yes, but there are no EJBs in Java SE...

Best regards,
Harald


Re: Booting in Java SE?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Getunstance is replaced by currentinstance, just a semantic change.

There is no standard api that's why it is in test module but it is
comparable to weldse. Deltaspike is the proof. If you want sthg standard
there is the EJBContainer and openejb for instance.

- Romain
Le 22 juin 2012 19:47, "Harald Wellmann" <hw...@googlemail.com> a
écrit :

> Am 22.06.2012 19:28, schrieb Romain Manni-Bucau:
>
>> Hi, in openwebbeans-test you have the CdiContainer.
>>
>>
> Do you mean org.apache.webbeans.cditest.**CdiTestContainer in
> org.apache.openwebbeans.test:**cditest:1.1.4?
>
> The corresponding implementation class CdiTestOpenWebBeansContainer also
> calls WebBeansContext.getInstance() in its bootContainer() methods.
>
> Besides, isn't this container meant for testing and not for running
> applications?
>
> I'm looking for something like weld-se.
>
> Best regards,
> Harald
>

Re: Booting in Java SE?

Posted by Harald Wellmann <hw...@googlemail.com>.
Am 22.06.2012 19:28, schrieb Romain Manni-Bucau:
> Hi, in openwebbeans-test you have the CdiContainer.
>

Do you mean org.apache.webbeans.cditest.CdiTestContainer in 
org.apache.openwebbeans.test:cditest:1.1.4?

The corresponding implementation class CdiTestOpenWebBeansContainer also 
calls WebBeansContext.getInstance() in its bootContainer() methods.

Besides, isn't this container meant for testing and not for running 
applications?

I'm looking for something like weld-se.

Best regards,
Harald

Re: Booting in Java SE?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi, in openwebbeans-test you have the CdiContainer.

In deltaspike project you have a common api between owb and weld.

Both are fine.

- Romain
Le 22 juin 2012 19:25, "Harald Wellmann" <hw...@googlemail.com> a
écrit :

> What's the proper way of starting OWB in a Java SE environment?
>
> The corresponding section in the User Guide is empty.
>
>
> samples/standalone-sample/src/main/java/org/apache/webbeans/se/sample/Boot.java
> uses WebBeansContext.getInstance(), but this method is deprecated and
> does not document its replacement.
>
> Best regards,
> Harald
>