the type of error that occurred than using a DatastoreException. Furthermore, adding this new exception to our IStorefrontService declarations still wouldn’t expose the fact that the implementation is based on EJB. 13.2.1.2 Swapping the implementation All that’s left to do is to swap the current Storefront service implementation with the delegate we have created. The framework put into place with the StorefrontServiceFactoryin Chapter 6 makes this easy to do. We simply need to change the class specified for our service implementation in the web.xml file to the following:
storefront-service-class
com.oreilly.struts.storefront.service.StorefrontEJBDelegate With this change made, an action will be creating a delegate instance whenever it calls the getStorefrontService( )method implemented in the StorefrontBaseAction. This method should be called only once during a request, to avoid the unnecessary overhead of creating additional remote references. However, even taking care to use the same delegate throughout a request leaves us with an implementation that isn’t very efficient. The next section covers some ways to improve our use of JNDI and home interfaces. Don’t forget that you’ll need to copy the JBoss client JARs to the lib directory for your web application before using your delegate. You’ll also need the home and remote interface class files for the Storefrontsession bean in the classes directory. 13.2.2 Managing EJB Home and Remote References Implementing a business delegate clearly isolates and minimizes the dependencies between the web and application tiers. We were able to implement our Storefront session bean using a business interface that isn’t tied to any particular client type. We also were able to leave our Struts action classes untouched when switching to this implementation of our model. We do have a couple of problems to address, though, to turn this into a solution you would want to use in a real application. Most importantly, we need to improve how we’re obtaining our home interface references. We also should get rid of the hardcoded parameters used by our JNDI lookup. Performing a JNDI lookup to obtain a home interface reference is an expensive (slow) operation. We couldn’t do much about this overhead if we actually needed a new home reference for each request, but that’s not the case. An EJB home is a factory object that is valid throughout the lifetime of the client application. There is no state in this object that prevents it from being used across requests or client threads. Our delegate would be significantly improved if the home reference it needed were cached within the web tier after being requested the first time. As with any design problem, there is more than one technique we should consider for caching our home reference. We’re basically talking about application-scope data in the web tier, so modifying the
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.
This entry was posted
on Thursday, October 11th, 2007 at 10:08 am and is filed under Domain.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.