Author: christian.bauer(a)jboss.com
Date: 2008-04-28 08:17:16 -0400 (Mon, 28 Apr 2008)
New Revision: 8046
Modified:
trunk/examples/wiki/src/main/org/jboss/seam/wiki/WikiInit.java
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/cache/EHCacheManager.java
Log:
Resolved EHCacheManager singleton conflict if multiple wikis run on the same JVM
Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/WikiInit.java
===================================================================
--- trunk/examples/wiki/src/main/org/jboss/seam/wiki/WikiInit.java 2008-04-28 10:58:51 UTC
(rev 8045)
+++ trunk/examples/wiki/src/main/org/jboss/seam/wiki/WikiInit.java 2008-04-28 12:17:16 UTC
(rev 8046)
@@ -35,6 +35,7 @@
private String appname;
private String adminContact;
private boolean debug;
+ private boolean hibernateStatistics = true;
@In(required = false)
DBUnitImporter dbunitImporter;
@@ -43,32 +44,37 @@
@Observer("org.jboss.seam.postInitialization")
public void initWiki() throws Exception {
- log.info("Starting LaceWiki for application
'"+appname+"'...");
+ log.info(">>>>>>>>>>>> Starting LaceWiki
for application '"+appname+"'...");
if (dbunitImporter != null) {
log.info("Importing development test data");
dbunitImporter.importDatasets();
}
- //System.out.println(listJNDITree("java:"));
-
- log.info("registering Hibernate statistics MBean");
- hibernateMBeanName = new
ObjectName("Hibernate:type=statistics,application="+appname);
- StatisticsService mBean = new StatisticsService();
-
mBean.setSessionFactoryJNDIName("SessionFactories/"+appname+"SF");
- ManagementFactory.getPlatformMBeanServer().registerMBean(mBean,
hibernateMBeanName);
+ if (hibernateStatistics) {
+ log.info("registering Hibernate statistics MBean");
+ hibernateMBeanName = new
ObjectName("Hibernate:type=statistics,application="+appname);
+ StatisticsService mBean = new StatisticsService();
+
mBean.setSessionFactoryJNDIName("SessionFactories/"+appname+"SF");
+ ManagementFactory.getPlatformMBeanServer().registerMBean(mBean,
hibernateMBeanName);
+ }
Events.instance().raiseEvent("Wiki.started");
- log.info("Started LaceWiki");
+ log.info("Started LaceWiki for application
'"+appname+"'...");
+
+ //System.out.println(listJNDITree("java:"));
}
@Destroy
public void shutdown() throws Exception {
- log.info("Stopping LaceWiki");
+ log.info("<<<<<<<<<<<<< Stopping
LaceWiki for application '"+appname+"'...");
- log.info("unregistering Hibernate statistics MBean");
- ManagementFactory.getPlatformMBeanServer().unregisterMBean(hibernateMBeanName);
+ if (hibernateStatistics) {
+ log.info("unregistering Hibernate statistics MBean");
+
ManagementFactory.getPlatformMBeanServer().unregisterMBean(hibernateMBeanName);
+ }
+ log.info("Stopped LaceWiki for application
'"+appname+"'...");
}
public String getAppname() {
@@ -95,6 +101,14 @@
this.debug = debug;
}
+ public boolean isHibernateStatistics() {
+ return hibernateStatistics;
+ }
+
+ public void setHibernateStatistics(boolean hibernateStatistics) {
+ this.hibernateStatistics = hibernateStatistics;
+ }
+
/** Utility to debug JBoss JNDI problems */
public static String listJNDITree(String namespace) {
StringBuffer buffer = new StringBuffer(4096);
Modified: trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/cache/EHCacheManager.java
===================================================================
---
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/cache/EHCacheManager.java 2008-04-28
10:58:51 UTC (rev 8045)
+++
trunk/examples/wiki/src/main/org/jboss/seam/wiki/core/cache/EHCacheManager.java 2008-04-28
12:17:16 UTC (rev 8046)
@@ -9,7 +9,6 @@
import org.jboss.seam.annotations.*;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
import org.jboss.seam.Component;
-import org.jboss.seam.ScopeType;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.log.Logging;
import org.jboss.seam.log.LogProvider;
@@ -42,8 +41,11 @@
@Create
public void initCacheManager() {
- log.info("initalizing EHCacheManager from /ehcache.xml");
- manager = CacheManager.create();
+ log.info("instantiating EHCacheManager from /ehcache.xml");
+ // Do NOT use the CacheManage.create() factory methods, as they create a
singleton! Our applicatoin
+ // has to have its own CacheManager instance, so that we can run several
applications in the same
+ // JVM or application server.
+ manager = new CacheManager();
if (isRegisterMonitoring()) {
// Register statistics MBean of EHCache on the current MBean server
Show replies by date