Author: trang_vu
Date: 2011-08-17 00:02:33 -0400 (Wed, 17 Aug 2011)
New Revision: 4760
Added:
kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainerScopingObjects.java
kernel/branches/2.2.x/patch/2.2.10-GA/KER-175/readme.txt
Modified:
kernel/branches/2.2.x/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheFactoryImpl.java
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java
kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainer.java
Log:
KER-175: Find a way to have a name for MBeans of JBossCaches used by the JCR
Fix description
* Set MBeans names of JBossCaches explicitly.
Modified:
kernel/branches/2.2.x/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheFactoryImpl.java
===================================================================
---
kernel/branches/2.2.x/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheFactoryImpl.java 2011-08-16
15:41:35 UTC (rev 4759)
+++
kernel/branches/2.2.x/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/ExoCacheFactoryImpl.java 2011-08-17
04:02:33 UTC (rev 4760)
@@ -18,6 +18,8 @@
*/
package org.exoplatform.services.cache.impl.jboss;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.container.configuration.ConfigurationManager;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.ValueParam;
@@ -32,16 +34,21 @@
import org.jboss.cache.CacheFactory;
import org.jboss.cache.DefaultCacheFactory;
import org.jboss.cache.config.Configuration;
+import org.jboss.cache.config.Configuration.CacheMode;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
-import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.jmx.JmxRegistrationManager;
+import org.picocontainer.Startable;
import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import javax.management.ObjectName;
+
/**
* This class is the JBoss Cache implementation of the {@link
org.exoplatform.services.cache.ExoCacheFactory}
* Created by The eXo Platform SAS
@@ -49,7 +56,7 @@
* exo(a)exoplatform.com
* 17 juil. 2009
*/
-public class ExoCacheFactoryImpl implements ExoCacheFactory
+public class ExoCacheFactoryImpl implements ExoCacheFactory, Startable
{
/**
@@ -90,6 +97,11 @@
private final Map<String, String> mappingCacheNameConfig = new
HashMap<String, String>();
/**
+ * The list of all the JMX Managers registered
+ */
+ private final List<JmxRegistrationManager> jmxManagers = new
CopyOnWriteArrayList<JmxRegistrationManager>();
+
+ /**
* The default creator
*/
private final ExoCacheCreator defaultCreator = new FIFOExoCacheCreator();
@@ -149,6 +161,13 @@
cache.create();
// Start the cache
cache.start();
+ // Create JMX Manager for this cache instance
+ JmxRegistrationManager jmxManager = getJmxRegistrationManager(cache, region);
+ if (jmxManager != null)
+ {
+ jmxManager.registerAllMBeans();
+ jmxManagers.add(jmxManager);
+ }
}
catch (Exception e)
{
@@ -156,8 +175,34 @@
}
return eXoCache;
}
-
+
/**
+ * Gives the {@link JmxRegistrationManager} instance corresponding to the given
context
+ */
+ private static JmxRegistrationManager getJmxRegistrationManager(Cache<?, ?>
parentCache,
+ String cacheName)
+ {
+ try
+ {
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ ObjectName containerObjectName = container.getScopingObjectName();
+ final String objectNameBase = (containerObjectName != null ?
containerObjectName.toString() + "," : "exo:")+
"cache-name=" + cacheName;
+ return new JmxRegistrationManager(container.getMBeanServer(), parentCache,
objectNameBase)
+ {
+ public String getObjectName(String resourceName)
+ {
+ return objectNameBase + JMX_RESOURCE_KEY + resourceName;
+ }
+ };
+ }
+ catch (Exception e)
+ {
+ LOG.error("Could not create the JMX Manager", e);
+ }
+ return null;
+ }
+
+ /**
* Add a list of creators to register
* @param plugin the plugin that contains the creators
*/
@@ -245,4 +290,22 @@
config.setClusterName(clusterName + " " + region);
}
}
+
+ /**
+ * @see org.picocontainer.Startable#start()
+ */
+ public void start()
+ {
+ }
+
+ /**
+ * @see org.picocontainer.Startable#stop()
+ */
+ public void stop()
+ {
+ for (JmxRegistrationManager jmxManager : jmxManagers)
+ {
+ jmxManager.unregisterAllMBeans();
+ }
+ }
}
Modified:
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java
===================================================================
---
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java 2011-08-16
15:41:35 UTC (rev 4759)
+++
kernel/branches/2.2.x/exo.kernel.container/src/main/java/org/exoplatform/container/management/ManageableContainer.java 2011-08-17
04:02:33 UTC (rev 4760)
@@ -25,8 +25,12 @@
import org.exoplatform.management.annotations.Managed;
import org.exoplatform.management.annotations.ManagedDescription;
import org.exoplatform.management.annotations.ManagedName;
+import org.exoplatform.management.jmx.impl.JMX;
import org.exoplatform.management.jmx.impl.JMXManagementProvider;
+import org.exoplatform.management.jmx.impl.MBeanScopingData;
import org.exoplatform.management.spi.ManagementProvider;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
import org.picocontainer.ComponentAdapter;
import org.picocontainer.PicoContainer;
import org.picocontainer.PicoException;
@@ -37,9 +41,13 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.management.MBeanServer;
+import javax.management.ObjectName;
/**
* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
@@ -48,6 +56,11 @@
public class ManageableContainer extends CachingContainer
{
+ /**
+ * The logger
+ */
+ private static final Log LOG =
ExoLogger.getLogger("org.exoplatform.container.management.ManageableContainer");
+
private static MBeanServer findMBeanServer()
{
J2EEServerInfo serverenv_ = new J2EEServerInfo();
@@ -63,6 +76,9 @@
/** . */
private MBeanServer server;
+ private volatile boolean objectNameSet;
+ private ObjectName objectName;
+
/** . */
private final Set<ManagementProvider> providers;
@@ -163,6 +179,46 @@
return super.registerComponent(componentAdapter);
}
+ /**
+ * Gives the ObjectName of the container build from the scoping data
+ * @return
+ */
+ public ObjectName getScopingObjectName()
+ {
+ if (!objectNameSet)
+ {
+ synchronized (this)
+ {
+ if (!objectNameSet)
+ {
+ Map<String, String> props = new LinkedHashMap<String,
String>();
+
+ // Merge scoping properties
+ List<MBeanScopingData> list =
managementContext.getScopingData(MBeanScopingData.class);
+ if (list != null && !list.isEmpty())
+ {
+ // Read in revert order because wee received list of parents in upward
order
+ for (int i = list.size(); i > 0; i--)
+ {
+ MBeanScopingData scopingData = list.get(i - 1);
+ props.putAll(scopingData);
+ }
+ try
+ {
+ this.objectName = JMX.createObjectName("exo", props);
+ }
+ catch (Exception e)
+ {
+ LOG.error("Could not create the object name", e);
+ }
+ }
+ this.objectNameSet = true;
+ }
+ }
+ }
+ return objectName;
+ }
+
public ComponentAdapter registerComponentInstance(Object componentKey, Object
componentInstance)
throws PicoRegistrationException
{
Modified:
kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainer.java
===================================================================
---
kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainer.java 2011-08-16
15:41:35 UTC (rev 4759)
+++
kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainer.java 2011-08-17
04:02:33 UTC (rev 4760)
@@ -31,6 +31,7 @@
*/
public class TestPortalContainer extends AbstractTestContainer
{
+
public void testInitValues()
{
createRootContainer("portal-container-config-with-settings.xml");
Added:
kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainerScopingObjects.java
===================================================================
---
kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainerScopingObjects.java
(rev 0)
+++
kernel/branches/2.2.x/exo.kernel.container/src/test/java/org/exoplatform/container/TestPortalContainerScopingObjects.java 2011-08-17
04:02:33 UTC (rev 4760)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2003-2010 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Affero General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.container;
+
+import org.exoplatform.container.jmx.AbstractTestContainer;
+import org.exoplatform.container.support.ContainerBuilder;
+
+import java.net.URL;
+
+/**
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto
+ * nicolas.filotto(a)exoplatform.com
+ * 18 fホvr. 2010
+ */
+public class TestPortalContainerScopingObjects extends AbstractTestContainer
+{
+
+ public void testHasScopingObjectName()
+ {
+ URL rootURL = getClass().getResource("empty-config.xml");
+ URL portalURL = getClass().getResource("empty-config.xml");
+ assertNotNull(rootURL);
+ assertNotNull(portalURL);
+ //
+ new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).build();
+ assertNull(RootContainer.getInstance().getScopingObjectName());
+ assertNotNull(PortalContainer.getInstance().getScopingObjectName());
+ }
+}
Added: kernel/branches/2.2.x/patch/2.2.10-GA/KER-175/readme.txt
===================================================================
--- kernel/branches/2.2.x/patch/2.2.10-GA/KER-175/readme.txt (rev
0)
+++ kernel/branches/2.2.x/patch/2.2.10-GA/KER-175/readme.txt 2011-08-17 04:02:33 UTC (rev
4760)
@@ -0,0 +1,72 @@
+Summary
+
+ * Status: Find a way to have a name for MBeans of JBossCaches used by the JCR
+ * CCP Issue: CCP-1032, Product Jira Issue: KER-175.
+ * Complexity: Medium
+
+The Proposal
+Problem description
+
+What is the problem to fix?
+
+ * Find a way to have a name for MBeans of JBossCaches used by the JCR
+
+Fix description
+
+How is the problem fixed?
+
+ * Set MBeans names of JBossCaches explicitly
+
+Patch file: KER-175.patch
+
+Tests to perform
+
+Reproduction test
+PROBLEM:
+
+ * When monitoring the JCR with a JMX Tool (like VisualVM)
+ * The JBossCaches used by the JCR have generated names, and no informations about
what they are managing.
+
+EXPECTED:
+
+ * A name stable between two start up
+ * An indication of the content managed by the cache
+
+Tests performed at DevLevel
+* Functional testing jcr projcects
+
+Tests performed at QA/Support Level
+*
+
+Documentation changes
+
+Documentation changes:
+* No
+
+Configuration changes
+
+Configuration changes:
+* No
+
+Will previous configuration continue to work?
+* Yes
+
+Risks and impacts
+
+Can this bug fix have any side effects on current client projects?
+
+ * No
+
+Is there a performance risk/cost?
+* No
+
+Validation (PM/Support/QA)
+
+PM Comment
+* Patch approved.
+
+Support Comment
+*
+
+QA Feedbacks
+*