This discussion is archived
7 Replies Latest reply: Feb 2, 2012 3:47 AM by gimbal2 RSS

Can client keep stateless session bean reference?

908165 Newbie
Currently Being Moderated
Hi,

are there any cons for keeping reference to the stateless session bean (in e.g. servlet http session)? The solution is working without problems, but I started to think about this scenario:
1. Servlet acquires and stores SSB reference
2. Servlet calls SSB and it is executed on server A in a cluster
3. the server A is shut down. Server B remains.
4. Servlet calls SSB again

Is the SSB client stub pointing to server A causing error?

_
Jukka
  • 1. Re: Can client keep stateless session bean reference?
    gimbal2 Guru
    Currently Being Moderated
    Think about it for a moment. You want to store a reference to a -stateless- bean. Stateless. It has no state. It stores nothing. There is nothing in there that you might need later.

    I hope you already see the pointlessness in keeping references to stateless EJBs around. But on top of that: you have this wonderful JEE container that performs all kinds of magic for you and is there to support you all the way. Why do you want to spit in its face and do things your own way anyway?
  • 2. Re: Can client keep stateless session bean reference?
    908165 Newbie
    Currently Being Moderated
    Hello,

    The main point is not that we want to keep reference to exactly same bean!

    This is related to the user interface solution which is very stateful. We are not doing EJB lookup on demand, but we are injecting EJB services to the UI class fields when UI is initialized. The UI remains in the http session with its state.

    _
    Jukka
  • 3. Re: Can client keep stateless session bean reference?
    gimbal2 Guru
    Currently Being Moderated
    Unfortunately, you design is flawed because that way you will indeed be holding on to EJB references when you shouldn't. Switch to lookups in stead of injections to solve that design flaw, or otherwise cross your fingers that you won't ever get into trouble because of it.
  • 4. Re: Can client keep stateless session bean reference?
    908165 Newbie
    Currently Being Moderated
    One more scenario came into my mind.

    0. Servlet function execution starts
    1. Servlet looks up stateless session bean
    2. Servlet calls session bean (executed on server A)
    3. Server A goes down
    4. Servlet calls session bean again. We are still in the same Servlet function.
    5. Servlet function end

    So should bean always looked up for each call?
    What if server where EJB container is running goes off-line after lookup, but before EJB call?

    _
    Jukka
  • 5. Re: Can client keep stateless session bean reference?
    gimbal2 Guru
    Currently Being Moderated
    user12159399 wrote:
    One more scenario came into my mind.

    0. Servlet function execution starts
    1. Servlet looks up stateless session bean
    2. Servlet calls session bean (executed on server A)
    3. Server A goes down
    4. Servlet calls session bean again. We are still in the same Servlet function.
    5. Servlet function end
    You seem to be stuck on doom scenarios. When things go bad, there isn't much you can do when servers start failing on you. What you expect the technology to do is break down, which will be the trigger to investigate what is really going on.
    >
    So should bean always looked up for each call?
    Only in situations where the bean is not managed by the container. Objects stored in some sort of persistent storage (like a session) must not hold on to server managed resources, so you should do lookups.
    What if server where EJB container is running goes off-line after lookup, but before EJB call?
    Then things go boom no matter how you got the EJB reference.
  • 6. Re: Can client keep stateless session bean reference?
    908165 Newbie
    Currently Being Moderated
    Hi,

    I did some investigations and at least WebLogic seems to be intelligent. So the client stub is aware of available cluster nodes and provides transparent support to find and call working node.

    http://docs.oracle.com/cd/E11035_01/wls100/cluster/failover.html#wp1044561

    Chapter "Clustering Objects with Replica-Aware Stubs" says:

    If a failure occurs during the call, the stub intercepts the exception and retries the call on another replica. This provides a failover that is also transparent to the caller.


    I need to check out the EJB specification if there are any definitions no this.
  • 7. Re: Can client keep stateless session bean reference?
    gimbal2 Guru
    Currently Being Moderated
    That seems to be stale connection handling logic. Robust, but it won't do you any good in the scenarios you described so far. The second instance tried will naturally also fail in case of server downtime.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points