Skip to main content

1 reply [Last post]
okna2000
Offline
Joined: 2009-07-19
Points: 0

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ss141213
Offline
Joined: 2005-03-30
Points: 0

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@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
>
>