users@glassfish.java.net

Re: injecting the collection of EJBs, not the specific one, is that possible?

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Fri, 13 Jul 2007 11:19:07 +0200

Can you give me some hint how could I implement such a explicit lookup?

Is this possible to ask server about bean names? When I have only one
bean implementing an interface, the server somehow finds it and
injects that bean. When server finds more than one bean implementing
the interface, and I want to get such a bean without providing its
name, the server will not deploy such an application.

It means, he must have some kind of discovery service. Is such a
service available? If so, I could, in a loop, lookup for that beans
and return in a collection...

Witek

2007/7/9, Mahesh Kannan <Mahesh.Kannan_at_sun.com>:
>
> On Jul 9, 2007, at 4:30 AM, Witold Szczerba wrote:
>
> > Hi there,
> > I know this question is not Glassfish specific, but Java EE 5 in
> > general, but I do not know where to ask this: is this possible to use
> > something like @EJB to inject session bean, but I would like to inject
> > all the session beans implementing given interface? (not the only
> > one).
> No, this is not possible. The closest that I can think of is to do
> explicit jndi lookup(s) to get references of all such session beans
> and add to the collection.
> Note that you can use @Resource and use a custom ObjectFactory, but
> the ObjectFactory will have to do multiple lookup(s) itself to
> populate the collection.,
>
> Thanks,
> --Mahesh
>
>
> > I would like to create session beans implementing something like:
> >
> > public void process(Operation operation);
> >
> > I could implement each operation type in separate session bean, then
> > inject all of them and use like this:
> > Collection<OperationLocal> operationBeans;
> > ...
> > Operation someOperation = ....;
> > for (OperationLocal operationBean : operationBeans) {
> > operationBean.process(someOperation);
> > }
> >
> > Each implementation could internally check if it is interested in that
> > operation and ignore it if that is so.
> >
> > So, is this possible to inject collection of session beans
> > implementing given interface instead of only one per @EJB annotation?
> >
> > Thanks,
> > Witek
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> > For additional commands, e-mail: users-help_at_glassfish.dev.java.net
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>