The Source for Java Technology Collaboration
User: Password:



Andreas Schaefer

Andreas Schaefer's Blog

SLSB -> SFSB: Meaningless ?

Posted by schaefa on October 02, 2003 at 03:26 PM | Comments (4)

A colleague of mine just pointed out that in Richard Monson-Heafel’s EJB book (3rd edition) configurations like Stateless Session Bean (SLSB) -> Stateful Session Bean (SFSB) are considered meaningless. I understand that any EJB book cannot deal with all possible scenarios otherwise you need a truck to take the book home but I find it too interesting not to talk about. Luckily I can discuss in my weblog any scenario I like and hopefully I can show you that rules are meant to be broken even when the result only confirms the rule.

Let us assume that we have a SLSB that has at least one business method in it that is quite elaborate and performs many tasks. In addition we want to have multiple resources or a non-standard resource wrapped in an EJB like a raw TCP/IP socket. Because the resource(s) should participate in a transaction and must be opened before usage and closed at the end it cannot be a SLSB because we never know what instance we get back on each invocation due the fact that the pool is returning the next free instance before a method is invoked. The only way left is to use an SFSB because a particular instance is available to the SLSB instance during the entire method call and so at the end I can close the resource(s) or do any other cleanup task. In this case the SLSB method does represent a client towards the SFSB even thought the life span of the SFSB is not that long.

Now one could object that I could just use a plain Java class instead of wrapping the resource(s) into an EJB but an EJB can use JNDI environment variable to specify setup properties, I can look it up very easily on a JNDI server and use an EJB reference in the Environment Naming Context (ENC) of the SLSB. Finally I can deploy the EJB in a separate application and use it throughout the server. One could also suggest using JCA instead but this could either overkill or what is wrapped in the SFSB does not adhere to JCA specification.

I want stress the fact that this rule should only be broken when there are compelling reasons to do so and you checked out the other options like keeping the code in the SLSB, creating a plain old Java object or using JCA and then selected the best solution that does not only fit you best now but also in the (near) future.

Enjoy - Andy

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Good example
    That was a good example to use SFSB.

    ---------------------------------------
    http://architectslobby.org
    http://javarss.com

    Posted by: architect on October 03, 2003 at 08:06 AM

  • One aspect perplexes me though. How does one get rid of the SFSB when one is through with it? If it is in a transaction, I do not believe that remove can be called. Also, I do not think that the SFSB implementing SessionSynchronization#afterCompletion(boolean) and calling remove on itself would work robustly/portably if at all either. Creating the SFSB in the SLSB's ejbCreate, opening and closing the resources in the SLSB's business methods, and removing the SFSB in the SLSB's ejbRemove does not seem to work either since assuming CMP and the business methods of the SLSB are called while in a global transaction, when the SLSB business method returns the SLSB will be repooled and can be handed out while its SFSB is still waiting for the other participants in the transaction to finish.

    Posted by: bayesianinstinct on March 08, 2006 at 12:52 AM

  • wow power leveling
    wow powerleveling
    wow power leveling
    wow gold
    wow items
    feelingame.com
    wow tips
    Most Valuable WOW Power Leveling Service
    wow power leveling faq
    cheap wow power leveling
    wow power leveling
    wow powerleveling
    wow power lvl

    Posted by: wowleveling3 on December 13, 2007 at 06:13 PM

  • 网络è¥é”€è½¯ä»¶
    网络è¥é”€è½¯ä»¶
    网络è¥é”€è½¯ä»¶
    群å‘软件
    群å‘软件
    ---
    群å‘软件
    网络è¥é”€è½¯ä»¶
    论å›ç¾¤å‘软件
    网站排å软件
    群å‘软件
    推广å°åŠ©æ‰‹ç ´è§£ç‰ˆ
    论å›ç¾¤å‘软件
    网站排å软件
    群å‘软件
    网络è¥é”€è½¯ä»¶
    网站推广软件
    ä¿¡æ¯ç¾¤å‘软件
    论å›ç¾¤å‘软件
    ä¿¡æ¯ç¾¤å‘软件
    åšå®¢ç¾¤å‘软件
    qq群å‘软件
    邮件群å‘软件
    åšå®¢ç¾¤å»ºè½¯ä»¶
    ä¼ä¸šå录æœç´¢è½¯ä»¶
    ä¿¡æ¯ç¾¤å‘软件
    邮件群å‘软件
    论å›ç¾¤å‘软件
    åšå®¢ç¾¤å‘软件
    网站推广软件
    网络è¥é”€è½¯ä»¶
    全能è¥é”€ç ´è§£ç‰ˆ

    Posted by: bininine on December 16, 2007 at 01:19 AM





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds