users@glassfish.java.net

Re: lookup ejb from OSGI ServiceListener

From: Sahoo <sanjeeb.sahoo_at_oracle.com>
Date: Thu, 02 Jun 2011 14:00:01 +0530

Depending on when the ServiceEvent is raised, the looked up EJB
reference may or may not be in a valid reference. If the EJB has been
undeployed, which happens on Bundle.STOPPING state, then the reference
becomes invalid. What's wrong if you look up every time you need the EJB?

Have you looked at GlassFish's support for EJB as OSGi service? It
automatically makes available stateless EJBs with local business
interfaces as OSGi services.

Sahoo

On Thursday 02 June 2011 12:37 PM, forums_at_java.net wrote:
> Hi,
> (I use glassfish 3.1, GA build)
> I have a ServiceListener class that needs to access EJB bean located
> in the
> same bundle. I noticed that it works only if ServiceListener makes EJB
> lookup
> on every event it gets.
> If I lookup EJB in ServiceListener constructor, when I try to access
> it in
> serviceChanged(), I get an exception "Attempt to invoke when container
> is in
> Undeployed."
> Here is the working version of code: public class MyServiceListener
> implements ServiceListener { private MyServiceBean adminService; public
> synchronized void serviceChanged(ServiceEvent event) { switch
> (event.getType()) { case ServiceEvent.REGISTERED: try {
> adminService = (MyServiceBean)
> new
> InitialContext().lookup("java:global/com.ex.test-war/adminServiceBean");
> } catch (NamingException e) {
> logger.error("exception: ",e);
> }
> ... do something
>
> adminService.installService(serviceName);
> break; }
> } }
> If I move the try-catch code to ServiceListener constructor, I get an
> exception in serviceChanged.
> Is it a known bug? Am I doing something wrong?
> thanks
>
>
> --
>
> [Message sent by forum member 'okna2000']
>
> View Post: http://forums.java.net/node/808456
>
>