Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do clients always end up with the same Stateful bean

 
Mark Garland
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

With Stateful beans, the client is always redirected to the same bean (or a bean representing the same state).
My question is how?

I guess it must be like a session id in Web development... but I wondered how it worked?
Is this handled at the RMI-IIOP level, or does the stub keep hold of it? I've not see it defined in the client code (nor should it I guess).

Thanks,

MG
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because containers don't use instance pooling for Stateful Session Beans.

Actually, it's very normal, for example outside EJB context if clients use Object A, it will use the same object every time.
 
Mark Garland
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kengkaj,

Thank you for your reply.

What I meant by my original question, is how is a client identified by the container?
i.e. a 2nd request comes in from a client - how does the container know which object is theirs?
There must be some id somewhere.

Thanks,

MG
 
Dhiren Lodhia
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Garland wrote:Hi Kengkaj,

Thank you for your reply.

What I meant by my original question, is how is a client identified by the container?
i.e. a 2nd request comes in from a client - how does the container know which object is theirs?
There must be some id somewhere.

Thanks,

MG


Hi Mark,

I think i can explain your quey.
First thing to remember when using Stateful SessionBean [SFSB] is that there will be unique ONE SFSB for each client.

Now while implementing SFSB there are actually 2 ID that work togather.
First in web containr you create Session and you add the reference to SFSB in the session .
so 1st you have Session id in web container.
now for each session id in web container your EJB container will create a uniwue SFSB and it will also be given some id
and this both Session id & SLSB id are bound togather
so from next time onwards if you come come with same session id you will be given same corresponding SFSB.

try this if your session expires in Web container you will also loose your SFSB.

 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Garland wrote:
With Stateful beans, the client is always redirected to the same bean (or a bean representing the same state).
My question is how?



Remember the jndi-lookup The lookup returns a proxy and if you keep working on the same proxy, the containers are smart enough to use the same bean instance for a SFSB. So if you do another lookup for the SFSB, the proxy returned will work on a different instance of the SFSB.
 
Mark Garland
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dhiren and Jaikiran,

Thank you very much for your replies.

Dhiren - I understand what you mean by putting a reference to the SFSB into the session, however this is just the same as me holding the reference locally. I'm not sure that this entirely answers my question.

Jaikiran - Are you saying that the JNDI lookup returns a proxy, and for a SFSB each instance of the proxy points to one and only one SFSB? If this is right, it is here where the id is kept.

Thanks once again,

MG
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Garland wrote:
Jaikiran - Are you saying that the JNDI lookup returns a proxy, and for a SFSB each instance of the proxy points to one and only one SFSB? If this is right, it is here where the id is kept.



Yes.
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai wrote:
Mark Garland wrote:
Jaikiran - Are you saying that the JNDI lookup returns a proxy, and for a SFSB each instance of the proxy points to one and only one SFSB? If this is right, it is here where the id is kept.



Yes.

I don't quite sure about this, in that case how the container separate clients? Could you please to explain more?
 
Hong Anderson
Ranch Hand
Posts: 1936
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Garland wrote:
Dhiren - I understand what you mean by putting a reference to the SFSB into the session, however this is just the same as me holding the reference locally. I'm not sure that this entirely answers my question.

As I understand, we put SFSB to HttpSession to able to use the same SFSB in the session.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic