Re: [Resin-interest] Resin 4: JMS Queue Injection
On Mar 23, 2009, at 12:46 PM, Scott Hernandez wrote: And everything is fine, but if I add another Queue (in resin-web.xml) then I get a problem as I have more than one Queue and it is not unique for injection. Now, in the examples it shows using @Named(QueueName) but that annotation cannot be applied to a field as the example seems to indicate. @Named(userUpdates) private BlockingQueue userUpdateQueue; How do I differentiate between the queues in my injection annotations? The docs are a bit out of date, because the Java Injection spec has changed a bit from the earlier draft. @Named is now _only_ for EL naming, not for binding. In this case, you're supposed to create your own @BindingType annotation, @UserUpdates. So you inject it like: @UserUpdates private BlockingQueue userUpdateQueue; And you configure it like: jms:FileQueue NameduserUpdates/Named mypkg:UserUpdates xmlns:mypkg=urn:java:com.me.mypkg/ /jms:FileQueue (I'd put the xmlns:mypkg at the top in a real config file.) Creating the annotation is a little bit of extra work but has the following advantages: 1. it's type safe, i.e. the compiler (and Java Injection) can verify the @UserUpdates is a valid @BindingType annotation, e.g. saving you from typos. 2. it's documented by JavaDoc, so you can explain the purpose of the @UserUpdates 3. it fits into IDEs, because IDEs have access to the annotation and to the xmlns of your configuration 4. it gives you a chance to think carefully about the organization of your components, in this case to double check that UserUpdates is a logical and self-documenting description of the queue you're using. The UserUpdates annotation is defined like: package com.me.mypkg; import static java.lang.annotation.ElementType.*; import static java.lang.annotation.RetentionPolicy.*; import java.lang.annotation.Retention; import java.lang.annotation.Target; import javax.inject.BindingType; @BindingType @Target({TYPE,FIELD,METHOD,PARAMETER}) @Retention(RUNTIME) public @interface UserUpdates { } (Resin does have a com.caucho.config.Name for generic things like databases, but that kind of general annotation is discouraged.) -- Scott Thanks in advance, Scott ___ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest ___ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest
Re: [Resin-interest] Resin 4: JMS Queue Injection
On Mar 24, 2009, at 10:06 AM, Scott Hernandez wrote: Okay, got it. I will give it a try. Also, this means I can annotate beans with @Production/@Mock in the xml also, right? Correct. I have a feeling my xmlns declarations section (in resin-web.xml) is going to be very long. ;( There's a solution for that. There's a special namespaces file that sits in com/mycom/mypkg that lists alias packages, one per line. So you could put all of your packages in a namespaces in com/mycom and use only one namespace declaration. Maybe I missed it but was there a section in jsr299 dealing with annotations of beans in xml, or is this resin specific? It's part of jsr299. You can specific any annotation as an XML child element of a bean definition and it gets added just as if you had declared the annotation on the bean. -- Scott Thanks, Scott On Tue, Mar 24, 2009 at 9:50 AM, Scott Ferguson f...@caucho.com wrote: On Mar 23, 2009, at 12:46 PM, Scott Hernandez wrote: And everything is fine, but if I add another Queue (in resin- web.xml) then I get a problem as I have more than one Queue and it is not unique for injection. Now, in the examples it shows using @Named(QueueName) but that annotation cannot be applied to a field as the example seems to indicate. @Named(userUpdates) private BlockingQueue userUpdateQueue; How do I differentiate between the queues in my injection annotations? The docs are a bit out of date, because the Java Injection spec has changed a bit from the earlier draft. @Named is now _only_ for EL naming, not for binding. In this case, you're supposed to create your own @BindingType annotation, @UserUpdates. So you inject it like: @UserUpdates private BlockingQueue userUpdateQueue; And you configure it like: jms:FileQueue NameduserUpdates/Named mypkg:UserUpdates xmlns:mypkg=urn:java:com.me.mypkg/ /jms:FileQueue (I'd put the xmlns:mypkg at the top in a real config file.) Creating the annotation is a little bit of extra work but has the following advantages: 1. it's type safe, i.e. the compiler (and Java Injection) can verify the @UserUpdates is a valid @BindingType annotation, e.g. saving you from typos. 2. it's documented by JavaDoc, so you can explain the purpose of the @UserUpdates 3. it fits into IDEs, because IDEs have access to the annotation and to the xmlns of your configuration 4. it gives you a chance to think carefully about the organization of your components, in this case to double check that UserUpdates is a logical and self-documenting description of the queue you're using. The UserUpdates annotation is defined like: package com.me.mypkg; import static java.lang.annotation.ElementType.*; import static java.lang.annotation.RetentionPolicy.*; import java.lang.annotation.Retention; import java.lang.annotation.Target; import javax.inject.BindingType; @BindingType @Target({TYPE,FIELD,METHOD,PARAMETER}) @Retention(RUNTIME) public @interface UserUpdates { } (Resin does have a com.caucho.config.Name for generic things like databases, but that kind of general annotation is discouraged.) -- Scott Thanks in advance, Scott ___ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest ___ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest ___ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest ___ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest
[Resin-interest] Resin 4: JMS Queue Injection
I'm developing a sample to test a few things and I have a simple question about injecting a Queue by name. I have a bit of xml in my resin-web.xml config like this: jms:JmsConnectionFactory/ jms:FileQueue NameduserUpdates/Named /jms:FileQueue ejb-message-bean class=resinscratchspace.queues.UserUpdateListener destination#{userUpdates}/destination /ejb-message-bean And my code is this: @Current private BlockingQueue userUpdateQueue; And everything is fine, but if I add another Queue (in resin-web.xml) then I get a problem as I have more than one Queue and it is not unique for injection. Now, in the examples it shows using @Named(QueueName) but that annotation cannot be applied to a field as the example seems to indicate. @Named(userUpdates) private BlockingQueue userUpdateQueue; How do I differentiate between the queues in my injection annotations? Thanks in advance, Scott ___ resin-interest mailing list resin-interest@caucho.com http://maillist.caucho.com/mailman/listinfo/resin-interest