[jboss-svn-commits] JBL Code SVN: r22976 - in labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta: src/org/jboss/soa/esb/listeners/message and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Sep 22 06:47:23 EDT 2008
Author: kevin.conner at jboss.com
Date: 2008-09-22 06:47:23 -0400 (Mon, 22 Sep 2008)
New Revision: 22976
Added:
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounterLifecycleResource.java
Modified:
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecyclePriorities.java
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounter.java
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipelineUnitTest.java
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounterUnitTest.java
Log:
Aggregate counter across listeners: JBESB-2059
Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecyclePriorities.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecyclePriorities.java 2008-09-22 08:14:58 UTC (rev 22975)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/lifecycle/LifecyclePriorities.java 2008-09-22 10:47:23 UTC (rev 22976)
@@ -37,6 +37,11 @@
public static final int RULE_BASE_PRIORITY = 50000;
/**
+ * The service message counter priority.
+ */
+ public static final int SERVICE_MESSAGE_COUNTER_PRIORITY = 75000 ;
+
+ /**
* The courier priority.
*/
public static final int COURIER_PRIORITY = 100000 ;
Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java 2008-09-22 08:14:58 UTC (rev 22975)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java 2008-09-22 10:47:23 UTC (rev 22976)
@@ -49,6 +49,7 @@
import org.jboss.soa.esb.couriers.CourierFactory;
import org.jboss.soa.esb.couriers.CourierUtil;
import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceException;
import org.jboss.soa.esb.listeners.ListenerTagNames;
import org.jboss.soa.esb.listeners.message.errors.Factory;
import org.jboss.soa.esb.message.Message;
@@ -204,7 +205,14 @@
final ArrayList<ActionPipelineProcessor> processorList = new ArrayList<ActionPipelineProcessor>();
- serviceMessageCounter = new ServiceMessageCounter(config);
+ try
+ {
+ serviceMessageCounter = ServiceMessageCounterLifecycleResource.getServiceMessageCounter(config);
+ }
+ catch (final LifecycleResourceException lre)
+ {
+ throw new ConfigurationException("Failed to obtain the service message counter", lre);
+ }
for (final ConfigTree actionConfig : actionList)
{
@@ -312,7 +320,6 @@
*/
public void initialise() throws ConfigurationException
{
- serviceMessageCounter.registerMBean();
final int numLifecycles = processors.length;
for (int count = 0; count < numLifecycles; count++)
{
@@ -340,7 +347,6 @@
{
active.set(false);
handleDestroy(processors.length - 1);
- serviceMessageCounter.unregisterMBean() ;
}
/**
Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounter.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounter.java 2008-09-22 08:14:58 UTC (rev 22975)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounter.java 2008-09-22 10:47:23 UTC (rev 22976)
@@ -37,7 +37,6 @@
import javax.management.MBeanOperationInfo;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
import javax.management.NotCompliantMBeanException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
@@ -62,8 +61,7 @@
private Hashtable<String, Integer> actionBytesProcessedHash;
private Hashtable<String, Integer> actionBytesFailedHash;
- private ConfigTree m_config;
- private ConfigTree[] actionArray;
+ private String[] actionNames;
private final ObjectName listObjectName ;
private Integer serviceCount;
@@ -87,8 +85,9 @@
/**
* Constructor
* @param f_config config tree
+ * @param objectName The name to use as the MBean.
*/
- public ServiceMessageCounter(ConfigTree f_config) {
+ public ServiceMessageCounter(ConfigTree f_config, final String objectName) {
actionCounterHash = new Hashtable<String, Integer>();
actionFailedCounterHash = new Hashtable<String, Integer>();
actionProcessTimeHash = new Hashtable<String, Long>();
@@ -99,11 +98,17 @@
bytesProcessed = new Integer(0);
bytesFailed = new Integer(0);
- m_config = f_config;
- actionArray = m_config.getChildren(ListenerTagNames.ACTION_ELEMENT_TAG);
-
- initHashes();
- listObjectName = getObjectName();
+ init(f_config);
+ ObjectName listObjectName = null ;
+ try
+ {
+ listObjectName = new ObjectName("jboss.esb:" + objectName);
+ }
+ catch (final Exception ex)
+ {
+ logger.error("Unexpected exception creating MBean object name, counter will be unregistered", ex);
+ }
+ this.listObjectName = listObjectName ;
}
/**
@@ -112,7 +117,7 @@
* @param ct config tree
* @return action id
*/
- public String getActionId(ConfigTree ct) {
+ private String getActionId(ConfigTree ct) {
if (ct.getAttribute("name") != null) {
return ct.getAttribute("name");
} else if (ct.getAttribute("action") != null) {
@@ -124,24 +129,29 @@
/**
* Increment the total message count of this service.
*/
- public void incrementTotalCount() {
+ public synchronized void incrementTotalCount() {
serviceCount = new Integer(serviceCount.intValue() + 1);
}
/**
- * Initialize the hashes by setting the counts and the processing time to an initial value of 0.
+ * Initialize the bean.
+ * @param configTree The current configuration.
*/
- public void initHashes() {
- ConfigTree[] actionList = m_config.getChildren(ListenerTagNames.ACTION_ELEMENT_TAG);
+ private void init(final ConfigTree configTree) {
+ ConfigTree[] actionList = configTree.getChildren(ListenerTagNames.ACTION_ELEMENT_TAG);
+ final int numActions = actionList.length ;
+ actionNames = new String[numActions] ;
- for (ConfigTree actionConfig : actionList) {
+ for (int count = 0 ; count < numActions ; count++) {
+ final ConfigTree actionConfig = actionList[count] ;
String actionId = getActionId(actionConfig);
- actionCounterHash.put(actionId + " " + MESSAGE_COUNTER, new Integer(0));
+ actionCounterHash.put(actionId + " " + MESSAGE_COUNTER, new Integer(0));
actionFailedCounterHash.put(actionId + " " + FAILED_MESSAGE_COUNTER, new Integer(0));
actionProcessTimeHash.put(actionId + " " + PROCESSING_TIME, new Long(0));
actionBytesFailedHash.put(actionId + " " + BYTES_FAILED, new Integer(0));
actionBytesProcessedHash.put(actionId + " " + BYTES_PROCESSED, new Integer(0));
- }
+ actionNames[count] = actionId ;
+ }
serviceCount = new Integer(0);
bytesProcessed = new Integer(0);
bytesFailed = new Integer(0);
@@ -151,7 +161,7 @@
* Reset the counters - set all the entries in the action counter hash
* and in the action process time hash to zero.
*/
- public void resetCounter() {
+ public synchronized void resetCounter() {
serviceCount = new Integer(0);
bytesProcessed = new Integer(0);
bytesFailed = new Integer(0);
@@ -183,7 +193,7 @@
* attribute), all of the attributes are read-only, and we provide four
* invocation methods - start/stop/initialise/destroy on the Lifecycle.
*/
- public MBeanInfo getMBeanInfo() {
+ public synchronized MBeanInfo getMBeanInfo() {
int count = actionCounterHash.size() + actionProcessTimeHash.size()
+ actionFailedCounterHash.size() + actionBytesProcessedHash.size()
@@ -250,7 +260,7 @@
/* (non-Javadoc)
* @see javax.management.DynamicMBean#getAttribute(java.lang.String)
*/
- public Object getAttribute(String key) throws AttributeNotFoundException, MBeanException, ReflectionException {
+ public synchronized Object getAttribute(String key) throws AttributeNotFoundException, MBeanException, ReflectionException {
if (actionCounterHash.containsKey(key)) {
Integer value = null;
value = actionCounterHash.get(key);
@@ -289,7 +299,7 @@
/* (non-Javadoc)
* @see javax.management.DynamicMBean#getAttributes(java.lang.String[])
*/
- public AttributeList getAttributes(String[] arg0) {
+ public synchronized AttributeList getAttributes(String[] arg0) {
AttributeList attributeList = new AttributeList();
for (String key : actionCounterHash.keySet()) {
Attribute at = new Attribute(key, actionCounterHash.get(key).toString());
@@ -410,8 +420,8 @@
* Update the ServiceMessageCounter
* @param asb ActionStatusBean
*/
- public void update(ActionStatusBean asb) {
- String actionName = getActionId(actionArray[asb.getProcCount()]);
+ public synchronized void update(ActionStatusBean asb) {
+ String actionName = actionNames[asb.getProcCount()];
if (ActionStatusBean.ACTION_SENT.equals(asb.getStatus())) {
Integer count = actionCounterHash.get(actionName + " " + MESSAGE_COUNTER);
@@ -437,36 +447,6 @@
protected ObjectName getObjectName()
{
- ObjectName listObjectName = null;
- try {
- String deploymentName = m_config.getParent().getAttribute(ListenerTagNames.DEPLOYMENT_NAME_TAG);
- String serviceName = m_config.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
- final String categoryName = m_config.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG) ;
-
- StringBuffer objectName = new StringBuffer("category=MessageCounter");
- if (deploymentName != null) {
- objectName.append(",").append(ListenerTagNames.DEPLOYMENT_NAME_TAG).append("=").append(deploymentName);
- }
-
- if (categoryName != null) {
- if (objectName.length() > 0) {
- objectName.append(",") ;
- }
- objectName.append(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG).append('=').append(categoryName) ;
- }
- if (serviceName != null) {
- if (objectName.length() > 0) {
- objectName.append(",");
- }
- objectName.append(ListenerTagNames.SERVICE_NAME_TAG).append("=").append(serviceName);
- }
-
- listObjectName = new ObjectName("jboss.esb:" + objectName.toString());
- } catch (MalformedObjectNameException e1) {
- e1.printStackTrace();
- } catch (NullPointerException e1) {
- e1.printStackTrace();
- }
return listObjectName;
}
}
Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounterLifecycleResource.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounterLifecycleResource.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounterLifecycleResource.java 2008-09-22 10:47:23 UTC (rev 22976)
@@ -0,0 +1,167 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.listeners.message;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.lifecycle.LifecyclePriorities;
+import org.jboss.soa.esb.lifecycle.LifecycleResource;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceException;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceFactory;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceManager;
+import org.jboss.soa.esb.listeners.ListenerTagNames;
+
+/**
+ */
+public class ServiceMessageCounterLifecycleResource
+{
+ /**
+ * The lifecycle resource factory for service message counters.
+ */
+ private static final LifecycleResourceFactory<Map<String, ServiceMessageCounter>> lifecycleServiceMessageCounterFactory = new LifecycleServiceMessageCounterFactory();
+ /**
+ * The lifecycle resources for service message counters.
+ */
+ private static final LifecycleResource<Map<String, ServiceMessageCounter>> lifecycleServiceMessageCounters =
+ new LifecycleResource<Map<String, ServiceMessageCounter>>(lifecycleServiceMessageCounterFactory, LifecyclePriorities.SERVICE_MESSAGE_COUNTER_PRIORITY);
+
+ /**
+ * The logger for the service message counter lifecycle resource.
+ */
+ private static final Logger LOGGER = Logger.getLogger(ServiceMessageCounterLifecycleResource.class) ;
+
+ /**
+ * Get the service message counter for the specified config tree.
+ * @param configTree The configTree
+ * @return The service message counter.
+ * throws LifecycleResourceException for errors accessing the lifecycle context.
+ */
+ public static ServiceMessageCounter getServiceMessageCounter(final ConfigTree configTree)
+ throws LifecycleResourceException
+ {
+ final String objectName = getObjectName(configTree) ;
+ final Map<String, ServiceMessageCounter> contextCounters = lifecycleServiceMessageCounters.getLifecycleResource() ;
+
+ synchronized(contextCounters)
+ {
+ final ServiceMessageCounter serviceMessageCounter = contextCounters.get(objectName) ;
+ if (serviceMessageCounter != null)
+ {
+ return serviceMessageCounter ;
+ }
+ final ServiceMessageCounter newServiceMessageCounter = new ServiceMessageCounter(configTree, objectName) ;
+ newServiceMessageCounter.registerMBean() ;
+ contextCounters.put(objectName, newServiceMessageCounter) ;
+ return newServiceMessageCounter ;
+ }
+ }
+
+ /**
+ * Create the object name associated with the configuration.
+ * @param configTree The current configuration.
+ * @return The object name.
+ */
+ private static String getObjectName(final ConfigTree configTree)
+ {
+ final String categoryName = configTree.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
+ final String serviceName = configTree.getAttribute(ListenerTagNames.SERVICE_NAME_TAG);
+ final String targetCategoryName = configTree.getAttribute(ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG);
+ final String targetServiceName = configTree.getAttribute(ListenerTagNames.TARGET_SERVICE_NAME_TAG);
+ final LifecycleResourceManager lifecycleResourceManager = LifecycleResourceManager.getSingleton() ;
+ final String[] associatedDeployments = lifecycleResourceManager.getAssociatedDeployments() ;
+ final String deployment ;
+ if ((associatedDeployments != null) && (associatedDeployments.length == 1))
+ {
+ deployment = associatedDeployments[0] ;
+ }
+ else
+ {
+ deployment = lifecycleResourceManager.getIdentity() ;
+ }
+
+ final StringBuffer objectName = new StringBuffer("category=MessageCounter");
+ append(objectName, "deployment", deployment) ;
+ append(objectName, ListenerTagNames.SERVICE_CATEGORY_NAME_TAG, categoryName) ;
+ append(objectName, ListenerTagNames.SERVICE_NAME_TAG, serviceName);
+ append(objectName, ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG, targetCategoryName);
+ append(objectName, ListenerTagNames.TARGET_SERVICE_NAME_TAG, targetServiceName);
+
+ return objectName.toString();
+ }
+
+ /**
+ * Append the name/value to the object name.
+ * @param objectName The current object name.
+ * @param name The property name.
+ * @param value The property value.
+ */
+ private static void append(final StringBuffer objectName, final String name, final String value)
+ {
+ if ((value != null) && (value.length() > 0)) {
+ objectName.append(",").append(name).append("=").append(value) ;
+ }
+ }
+
+ /**
+ * The lifecycle resource factory
+ * @author kevin
+ */
+ private static class LifecycleServiceMessageCounterFactory implements LifecycleResourceFactory<Map<String, ServiceMessageCounter>>
+ {
+ /**
+ * Create a resource object which will be associated with the specified lifecycle identity.
+ * @param lifecycleIdentity The associated lifecycle identity.
+ * @return The lifecycle resource
+ * @throws LifecycleResourceException for errors during construction.
+ */
+ public Map<String, ServiceMessageCounter> createLifecycleResource(final String lifecycleIdentity)
+ throws LifecycleResourceException
+ {
+ return new HashMap<String, ServiceMessageCounter>() ;
+ }
+
+ /**
+ * Destroy a resource object which is associated with the specified lifecycle identity.
+ * @param resource The lifecycle resource.
+ * @param lifecycleIdentity The associated lifecycle identity.
+ * @return The lifecycle resource.
+ * @throws LifecycleResourceException for errors during destroy.
+ */
+ public void destroyLifecycleResource(final Map<String, ServiceMessageCounter> resource,
+ final String lifecycleIdentity)
+ throws LifecycleResourceException
+ {
+ if (resource.size() > 0)
+ {
+ LOGGER.warn("Calling cleanup on existing service message counters for identity " + lifecycleIdentity) ;
+ for (final ServiceMessageCounter counter: resource.values())
+ {
+ counter.unregisterMBean() ;
+ }
+ }
+ }
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounterLifecycleResource.java
___________________________________________________________________
Name: svn:keywords
+ Rev Date
Name: svn:eol-style
+ native
Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipelineUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipelineUnitTest.java 2008-09-22 08:14:58 UTC (rev 22975)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipelineUnitTest.java 2008-09-22 10:47:23 UTC (rev 22976)
@@ -27,6 +27,7 @@
import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.common.ModulePropertyManager;
import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceManager;
import org.jboss.soa.esb.listeners.ListenerTagNames;
import org.jboss.soa.esb.message.format.MessageFactory;
@@ -45,8 +46,16 @@
com.arjuna.common.util.propertyservice.PropertyManager pm = ModulePropertyManager.getPropertyManager(ModulePropertyManager.DBSTORE_MODULE);
pm.setProperty("javax.xml.registry.ConnectionFactoryClass", "org.apache.ws.scout.registry.ConnectionFactoryImpl");
+ LifecycleResourceManager.getSingleton().associateDeployment(getClass().getCanonicalName()) ;
}
+ @Override
+ protected void tearDown() throws Exception
+ {
+ LifecycleResourceManager.getSingleton().disassociateDeployment(getClass().getCanonicalName()) ;
+ super.tearDown();
+ }
+
/*
* Tests to run
* - create a pipeline with a failure, make sure failure is called in correct order and subsequent actions are not called.
Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounterUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounterUnitTest.java 2008-09-22 08:14:58 UTC (rev 22975)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounterUnitTest.java 2008-09-22 10:47:23 UTC (rev 22976)
@@ -27,6 +27,7 @@
import org.apache.log4j.Logger;
import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.lifecycle.LifecycleResourceException;
import org.junit.Test;
/**
@@ -41,11 +42,12 @@
@Test
public void getObjectName()
+ throws LifecycleResourceException
{
ConfigTree config = createConfigTreeForScheduler();
log.debug( config );
- ServiceMessageCounter counter = new ServiceMessageCounter( config );
+ ServiceMessageCounter counter = ServiceMessageCounterLifecycleResource.getServiceMessageCounter(config);
ObjectName objectName = counter.getObjectName();
log.debug( objectName );
}
More information about the jboss-svn-commits
mailing list