-
1. Re: Modeshape connexion design pattern
bcarothers Jul 13, 2011 7:19 AM (in response to sjahan)As you've correctly identified, you want no more than one JcrEngine instance per-repository-and-JVM. You're also seeing that your sessions need to be per-request, not per-method or per-instance of your business objects.
My first cut would be to write an OpenSessionInView (OSIV) implementation for ModeShape. It's pretty straightforward to do so. You just write a servlet filter that opens up the session before chaining, sticks it in thread-local storage, and then closes the session after chaining is complete. There may already be one of these out there. Then, your access methods would pull the existing session off of the thread-local storage instead of creating and destroying sessions with each method. This also assumes that your methods that access content are not in a singleton, even though your JcrEngine itself may be.
The second thing that I would consider doing is implementing a connection pool for ModeShape connections. Apache commons has an ObjectPool class that makes this pretty easy to do. Just don't forget to call Session.refresh(false) before returning sessions to the pool. OTOH, Session.login and .logout are pretty inexpensive methods. You might want to hold off on pooling sessions until there's some evidence that you need to do so.
-
2. Re: Modeshape connexion design pattern
van.halbert Jul 13, 2011 8:42 AM (in response to bcarothers)If they are deploying to JBoss AS, modeshape already has a JcrEngine instance running. Would it be a better option to just use the RepositoryFactory (as described here: http://docs.jboss.org/modeshape/2.5.0.Final/manuals/gettingstarted/html_single/getting-started-en.html#repository_factory) to find the repository and create a session?