Command Pattern and Stateful Session Bean


EJB design: Command Pattern and Stateful Session Bean

  1. Command Pattern and Stateful Session Bean (4 messages)


    I am using the Command pattern described in the EJB Design patterns book from F.Marinescu.

    As specified, my remote command server is a stateless session bean.

    I would like to know how it is possible to manage a stateful session bean with this pattern ?

    I have a command that need to interact with a SFSB.
    Moreover, I would like to use the avantage of a business delegate to synchronize the SFSB access (due to frames in the web tier). Is there a usefull way to combine the command pattern and the business delegate pattern for SFSB?

    thanks !

  2. we are using the command pattern with a stateless ejb and the business delegation model which handles the business validation and delegation to DAO.Frames should not create a problem in accessing the bean(Bean is just service medium to the client, anyone is free to call for service!!). Synchronize access to the bean??? May be synchronization can be done at the business layer and at the DAO.

  3. a SFSB is theoretically linked to a unique session, so only one client can call the bean at a time. But in case of frames accessing a SFSB, the bean can receive two requests simultaneously (one per frame when loading the page). Here is the raised exception:

    java.rmi.RemoteException: nested exception is: java.lang.IllegalStateException: Bean is associated with a different unfinished transaction;

    This is why it is necessary to synchronize at a business delegate level (it is explained p103 in the Design pattern book).

    To resolve this problem, I slightly modify the Command pattern. Every command tied up with a SFSB are called through a synchronized method of the corresponding business delegate.

  4. Hi,
    I would recommend exploring other solutions to avoid concurrent calls to the stateful session beans.However,if you have decided to use the same -
    Set allow-concurrent-calls attribute to true in weblogic-ejb-jar.xml.
    This is weblogic specific you may try the similar setting for other App servers.
  5. Access to a stateful session bean can be serialized by creating a Web-tier class that acts as a proxy to a stateful session bean in the EJB tier. The proxy class would present have the same interface as the session enterprise bean, and would forward all calls to the session enterprise bean, but its methods would be synchronized. Keep in mind that other clients must be prevented from accessing the session enterprise bean remote interface directly.

    hope this solves the problem.. goodluck