Author: sohil.shah(a)jboss.com
Date: 2007-02-06 00:05:56 -0500 (Tue, 06 Feb 2007)
New Revision: 6172
Modified:
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java
trunk/cms/src/resources/test/jcr/repository.xml
Log:
fixed the JBossCachePersistenceManager to work with test suite with multiple dbs
Modified:
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java
===================================================================
---
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java 2007-02-06
04:14:55 UTC (rev 6171)
+++
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java 2007-02-06
05:05:56 UTC (rev 6172)
@@ -58,6 +58,8 @@
import javax.jcr.PropertyType;
import javax.management.MBeanServer;
+import javax.naming.InitialContext;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -108,13 +110,20 @@
protected BLOBStore blobStore = null;
/**
- *
+ * JackRabbit initalizes multiple instances of the Persistence Manager to perform its
operations.
+ * A static TreeCache is used to make sure there is only once instance of the cache
per VM where
+ * the CMS node runs.
+ *
+ * One side effect of using a static instance is proper cleanup which is addressed in
the close
+ * method
*/
private static TreeCacheMBean pmCache = null;
- private static boolean createdByMe;
private static boolean preloaded = false;
- /** Creates a new <code>SimpleDbPersistenceManager</code> instance. */
+ /**
+ *
+ *
+ */
public JBossCachePersistenceManager()
{
schemaObjectPrefix = "";
@@ -163,7 +172,7 @@
*
*/
public void init(PMContext context) throws Exception
- {
+ {
if (initialized)
{
throw new IllegalStateException("already initialized");
@@ -200,39 +209,45 @@
try
{
Tools.init(this.jndiName);
- if (JBossCachePersistenceManager.pmCache == null)
+ if (pmCache == null)
{
- // julien : removed that, it should be deployed by the portal-cms.sar
properly
+ /*
+ * performing an mbean lookup of the tree cache service. Ideally it would be
nice to avoid this
+ * and have the service be injected from the sar config. But, a
PersistenceManager's lifecycle is managed
+ * by JackRabbit and is not easily modeled as a JMX mbean service.
+ *
+ * The typical mbean lifecycle doesn't map here unless the PM serves as a
wrapper/proxy to an mbean
+ * service, but not sure if the extra layer is necessary.
+ *
+ * Also, see the close method to see how the PM cache service is cleaned up.
+ */
+ try
+ {
+ MBeanServer server = MBeanServerLocator.locateJBoss();
+ pmCache = (TreeCacheMBean)MBeanProxyExt.create(TreeCacheMBean.class,
+ "cms.pm.cache:service=TreeCache", server);
+ }
+ catch (Exception e)
+ {
+ }
-// try
-// {
-// MBeanServer server = MBeanServerLocator.locateJBoss();
-// JBossCachePersistenceManager.pmCache =
(TreeCacheMBean)MBeanProxyExt.create(TreeCacheMBean.class,
"cms.pm.cache:service=TreeCache", server);
-// }
-// catch (Exception e)
-// {
-// }
- // For now we always create the cache, we could try a JMX lookup commented
above because not properly done
- pmCache = null;
-
//try to load from specified configuration if any
//if nothing found in the environment...chances are running in a non-managed
environment
- if (JBossCachePersistenceManager.pmCache == null)
+ if (pmCache == null)
{
InputStream is = null;
try
{
- JBossCachePersistenceManager.pmCache = new TreeCache();
- createdByMe = true;
+ pmCache = new TreeCache();
//configure the cache
PropertyConfigurator configurator = new PropertyConfigurator();
is =
JBossCachePersistenceManager.class.getClassLoader().getResourceAsStream("pm-cache.xml");
- configurator.configure(JBossCachePersistenceManager.pmCache, is);
+ configurator.configure(pmCache, is);
- JBossCachePersistenceManager.pmCache.createService();
- JBossCachePersistenceManager.pmCache.startService();
+ pmCache.createService();
+ pmCache.startService();
}
finally
{
@@ -1168,19 +1183,23 @@
*/
public void close() throws Exception
{
+ //cleanup session factory.
+ Tools.destroy();
+
+ //cleanup the jboss cache service
+ if(pmCache != null)
+ {
+ pmCache.stopService();
+ pmCache.destroyService();
+ pmCache = null;
+ preloaded = false;
+ }
+
if (!initialized)
{
throw new IllegalStateException("not initialized");
}
- // We created it, we destroy it
- if (createdByMe && pmCache != null)
- {
- TreeCacheMBean cache = pmCache;
- pmCache = null;
- cache.destroy();
- }
-
try
{
if (externalBLOBs)
Modified: trunk/cms/src/resources/test/jcr/repository.xml
===================================================================
--- trunk/cms/src/resources/test/jcr/repository.xml 2007-02-06 04:14:55 UTC (rev 6171)
+++ trunk/cms/src/resources/test/jcr/repository.xml 2007-02-06 05:05:56 UTC (rev 6172)
@@ -62,11 +62,11 @@
<!--
persistence manager of the workspace.
- Use XMLPersistenceManager for LocalFileSystem Store and
HibernatePersistentManager .
+ Use XMLPersistenceManager for LocalFileSystem Store and
HibernatePersistenceManager .
-->
<!-- HibernatePersistentManager: uses RDBMS + Hibernate for storage -->
- <PersistenceManager
class="org.jboss.portal.cms.hibernate.state.HibernatePersistenceManager">
+ <PersistenceManager
class="org.jboss.portal.cms.hibernate.state.JBossCachePersistenceManager">
<param name="schemaObjectPrefix" value="WSP"/>
<param name="JNDIName"
value="java:/SessionFactory"/>
<param name="externalBLOBs" value="false"/>
@@ -109,11 +109,11 @@
<!--
Configures the persistence manager to be used for persisting version state.
- Use XMLPersistenceManager for LocalFileSystem Store and
HibernatePersistentManager for HibernateStore.
+ Use XMLPersistenceManager for LocalFileSystem Store and
HibernatePersistenceManager for HibernateStore.
-->
<!-- HibernatePersistentManager: uses RDBMS + Hibernate for storage -->
- <PersistenceManager
class="org.jboss.portal.cms.hibernate.state.HibernatePersistenceManager">
+ <PersistenceManager
class="org.jboss.portal.cms.hibernate.state.JBossCachePersistenceManager">
<param name="schemaObjectPrefix" value="Version"/>
<param name="JNDIName"
value="java:/SessionFactory"/>
<param name="externalBLOBs" value="false"/>
Show replies by date