-
1. Re: Seam Component Out of Box, Guice, JobssMC
wrzep Apr 28, 2008 7:10 PM (in response to skajotde)Hi Kamil,
You might be interested in the Seam and Guice integration I've implemented. It doesn't use MC, but it works as an interceptor.
Basically, all you need to do is to annotate your Seam component with @Guice annotation and configure default Guice module to use in the components.xml file.
@Name("myComponent") @Guice public class MyComponent { @Inject MyObject myObject; }
and the components.xml file:
<component name="org.jboss.labs.injection.seam.guiceModule" class="com.domain.YourGuiceModule" auto-create="true" scope="APPLICATION" startup="true"/>
The Guice injection will be triggered automatically :)
You can also use more than one Guice module. Just pass it's name to the @Guice annotation, like @Guice("myGuiceModule").
You will find the sources in the repository. I'm in the middle of writing some wiki page describing how to use it ;)
Cheers,
-Pawel -
2. Re: Seam Component Out of Box, Guice, JobssMC
skajotde Apr 28, 2008 8:36 PM (in response to skajotde)Thanks, it sounds cool ;)
-
3. Re: Seam Component Out of Box, Guice, JobssMC
wrzep Apr 29, 2008 10:57 PM (in response to skajotde)Hello,
I've just finished implementing Seam and Guice integration. As I mentioned before, it's all about @Guice annotation :)
You can find more information, including configuration and usage examples, on the wiki page.
You can also download seam-guice.jar and give it a try. Source code is also available.
Let me know what you think. Or maybe, you know a better way to integrate Seam and Guice, like using ELResolver? Your feedback is welcome.
Cheers,
-Pawel -
4. Re: Seam Component Out of Box, Guice, JobssMC
skajotde May 4, 2008 3:18 PM (in response to skajotde)
Pawel Wrzeszcz wrote on Apr 29, 2008 10:57 PM:
Let me know what you think. Or maybe, you know a better way to integrate Seam and Guice, like using ELResolver? Your feedback is welcome.I think integration at annotation level is great. First seam inject its members and next guice inject own members and annotations may coexist.
I'm against EL variables, besause it uses not-typesafe Strings. It is Spring fashion and it is reason I chose Guice instead of Spring. All with typesafe annotations with Java Code, No XML with not-typesafe strings,
If I would write with not-typesafe coding I chose one of dynamic lanugage (jython, jruby) over Java+XML. It's only comparision ;)
My question: why do you use guice module as seam component (and it is stored in application context of seam) instead of Guice Injector. I this case If I would used guice context outside seam components (eg. in other interceptor) I had to create other Injector? IMHO (I'm not guice expert) In guice is one assumption: one injector, one context, And It fallows up one instance of singleton etc.
Kamil
-
5. Re: Seam Component Out of Box, Guice, JobssMC
wrzep May 6, 2008 11:59 AM (in response to skajotde)
Kamil Demecki wrote on May 04, 2008 03:18 PM:
My question: why do you use guice module as seam component (and it is stored in application context of seam) instead of Guice Injector. I this case If I would used guice context outside seam components (eg. in other interceptor) I had to create other Injector? IMHO (I'm not guice expert) In guice is one assumption: one injector, one context, And It fallows up one instance of singleton etc.
KamilKamil, you're absolutely right! Thanks for pointing this out.
There is also a small thread safety issue. There might be 2 injectors for one module created in almost the same time and only the second one will be stored in cache (but the first one will be used as well).
I'm going to rewrite my interceptor to use injector instead of guice module :)
-Pawel
-
6. Re: Seam Component Out of Box, Guice, JobssMC
szimano.szimano.szimano.org May 6, 2008 12:37 PM (in response to skajotde)If you put Injector into servlet context you get get it from everywhere.
Resolver can be used to automatically inject members on every resolved bean that still keeps everything typesafe.
Cheers,
Tomek -
7. Re: Seam Component Out of Box, Guice, JobssMC
skajotde May 6, 2008 4:48 PM (in response to skajotde)
Pawel Wrzeszcz wrote on May 06, 2008 11:59 AM:
Kamil, you're absolutely right! Thanks for pointing this out.
There is also a small thread safety issue. There might be 2 injectors for one module created in almost the same time and only the second one will be stored in cache (but the first one will be used as well).
I'm going to rewrite my interceptor to use injector instead of guice module :)
-PawelNo problem ;) I saw this thread leak. I think If you declare Guice Injector as seam component in components.xml there will be no problem with threads? (I dont know so much seam components). On the other side your solution has good support for many modules. What will it look with many Guice Injector? (many declarations in components.xml or no chancy many injectors?)
Cheers
Kamil -
8. Re: Seam Component Out of Box, Guice, JobssMC
skajotde May 6, 2008 4:54 PM (in response to skajotde)
Tomasz Szymanski wrote on May 06, 2008 12:37 PM:
If you put Injector into servlet context you get get it from everywhere.I think seam component at aplication scope is good abstraction above servlet context.
Resolver can be used to automatically inject members on every resolved bean that still keeps everything typesafe.I strongly prefer @Inject Guice Annotation instead of EL expression. Run Injector.injectMembers(seamcompononet) after inject members by seam and before using components methods is cool.
Hm, what with two interceptors: one for authetification and one for guice, which runs first? Interceptor for authentification can use object injected by Guice?
--
Cheers
Kamil -
9. Re: Seam Component Out of Box, Guice, JobssMC
wrzep May 7, 2008 11:24 AM (in response to skajotde)
Kamil Demecki wrote on May 06, 2008 04:54 PM:
Hm, what with two interceptors: one for authetification and one for guice, which runs first? Interceptor for authentification can use object injected by Guice?
--
Cheers
KamilIf you have your own auth interceptor, you can always enforce specific order of interceptors using
within
andaround
attributes of the @Interceptor annotation.-Pawel
-
10. Re: Seam Component Out of Box, Guice, JobssMC
wrzep May 14, 2008 4:36 PM (in response to skajotde)Here it is. New, updated Seam and Guice integration :)
As for the Java code, almost nothing changes. You annotate your class with @Guice and it works.
I've made significant changes to the configuration. To initialize Guice support just put this to the components.xml file:
<components xmlns="http://jboss.com/products/seam/components" ... xmlns:guice="http://jboss.org/jbosslabs/seam-guice"> ... <guice:init injector="#{myGuiceInjector}"/> </components>
and provide your injector. Any EL expression that evaluates to Injector is valid here.
Moreover, if you just want to build an injector from modules, there is a convenient way to do so:
<guice:injector name="myGuiceInjector"> <guice:modules> <value>com.example.guice.GuiceModule1</value> <value>com.example.guice.GuiceModule2</value> </guice:modules> </guice:injector>
I've updated documentation and download page.
Enjoy.
-Pawel
-
11. Re: Seam Component Out of Box, Guice, JobssMC
skajotde May 14, 2008 9:22 PM (in response to skajotde)It looks nice work ;)
This code is heavy used (on creating millions of seam
beans) and I'm fan using log.isDebugEnabled() and log.isTraceEnabled().
I dont know how it is jboss politcs to logging and dont know real performance... just my habit ;p Which way logging you are using?--
Kamil -
12. Re: Seam Component Out of Box, Guice, JobssMC
wrzep May 20, 2008 5:35 PM (in response to skajotde)
Kamil Demecki wrote on May 14, 2008 09:22 PM:
This code is heavy used (on creating millions of seam
beans) and I'm fan using log.isDebugEnabled() and log.isTraceEnabled().
I dont know how it is jboss politcs to logging and dont know real performance... just my habit ;p Which way logging you are using?Using Seam logger you don't have to care about it. If you have a look at the org.jboss.seam.log.LogImpl source code, it solves the issue with boring log.isDebugEnabled() :)
-P
-
13. Re: Seam Component Out of Box, Guice, JobssMC
skajotde May 22, 2008 1:11 PM (in response to skajotde)
Pawel Wrzeszcz wrote on May 20, 2008 17:35:
Using Seam logger you don't have to care about it. If you have a look at the org.jboss.seam.log.LogImpl source code, it solves the issue with boring log.isDebugEnabled() :)
-PI Java arguments are evaluated at each method invocation, sometimes it cares and even sql is executed at simple log statement:
log.debug("user=" + user + ", roles=" + user.getRoles())
In such situation additional methods are executed: string concatenation and user methods user#toString() and user#getRoles(). if user#getRoles is lazy (normal case) addition sql is executed ;/
-- Kamil
-
14. Re: Seam Component Out of Box, Guice, JobssMC
skajotde May 23, 2008 12:59 PM (in response to skajotde)About twice computing values betore putting to cache there is section (number 5.19) in excellent book
Java Concurrency in Practise
;)--
Kamil