Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Statefull Bean - public member variable?

 
Swapan Mazumdar
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Again,

Should a member variable be declared "public" to participate in session state in a Statefull Session Bean. I am simply startled to see a simple Count bean example from Ed Roman book which has a "public int val".
Is it part of the EJB Specs? What you people have to say about it? Guru are you listening? :roll:
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Swapan,

I don�t think so. I won�t make references to EJB specs, since I cannot remember the specs totally (I hope someone else will do), but when we speak about a SFSB�s session state I might consider couple of things:
  • The way SFSB�s state is saved/retrieved during passivation/activation.
  • The way the container saves the bean�s state in a cluster environment if a sever failure occurs.


  • As far as I remember the first one has nothing to do with public, private or protected variables. It has everything to do whether the attributes themselves are serializable or not.
    As for the second one, it is vendor specific. WebLogic for example does an in-memory replication of the SFSB, which means that it keeps two copies of the same bean on different server instance within a cluster, in a primary-secondary manner (they are kept in sync using IP-multicast). If the primary server fails, WL will redirect client�s requests to the secondary (which will get promoted to primary and another secondary will be picked up). Again this has nothing to do with whether the variables are public or not.
    Finally I would imagine that a strategy that doesn�t save "private" state would be error prone, since good OOD says that internal attributes must be declared private, no matter if the class is a POJO or a SFSB.
     
    Swapan Mazumdar
    Ranch Hand
    Posts: 83
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Valentin,

    Your explanation created special interest to my post. I personally found the points quite informative, especially, the second one. I now understand that access modifiers for instance variables should be declared private for SF Session Beans.

    -Swapan
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic