EJB design: Command Pattern and Stateful Session Bean
- Posted by: Thierry R.
- Posted on: October 15 2002 12:37 EDT
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?
- Command Pattern and Stateful Session Bean by J2EE DISCUSSION ANIL LINGUTLA on October 15 2002 16:44 EDT
- Command Pattern and Stateful Session Bean by J2EE DISCUSSION ANIL LINGUTLA on October 17 2002 12:50 EDT
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.
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.
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.
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