EventListener in a Session Bean


EJB design: EventListener in a Session Bean

  1. EventListener in a Session Bean (4 messages)


    i am working on an method call that may time some times to process, but i want to kick back some "information" to the client.

    i am thinking to pass a some sort "EventListener" to the session bean when the method is being executed. but i am not sure if it will be safe to do it. here are my worries:

    -> the event listener may have registered to some services
       or resources that only the client can access.

    -> should i ask the client to pass the name of the
       "Class" of the EventListener rather than an instance
       of the EventListener. Therefore the session bean can
       call the "newInstance()" method to create an instance of
       the class. The event listener should have a constructor
       that take on argument.

    i know the alternative of using MDBean or JMS. It's too heavy and i found the problem once we change the JMS topics or any API update. I am trying to make this more losse couple.

    an insight?
    thx in advance.

    -ljb. XP

    Threaded Messages (4)

  2. EventListener in a Session Bean[ Go to top ]


    First of all, using callback mechanism is more "tight couple" than JMS.

    For one, how can you register such listener against each session bean instance?

    Fro two, instantiate a new instance of the listener at server side doesn't work, either. The listener has to be a "remote object", it's passed as remote reference, not value.

  3. EventListener in a Session Bean[ Go to top ]

    thanks marco, ... thought about it for a while.. how if the session bean is stateless, and the listener must be passed as one of the method parameters?

    i checked out the observer pattern, basically it is using singleton pattern + still required the listener to have the distribute capability.

    i tried to use JMS before, but it too *tight* to couple with a JMS topic. i am trying to let the client to decide what they want to do when event happens.

    which one do you guys think is better? making this listener to be *remote* or go back to the JMS land?
  4. EventListener in a Session Bean[ Go to top ]

    You can't register listener against session bean because session bean instances are "pooled", you register your listener only on one instance.

    If you don't want JMS, the observer framework is good alternative.

    If your clients can handle HTTP request, maybe you want to notify clients via HTTP/SOAP?
  5. http://www.javaworld.com/javaworld/javatips/jw-javatip110.html

    this should help search on observer pattern for ejbs.