[jboss-cvs] JBossAS SVN: r111110 - in projects/jboss-jca/trunk: core/src/main/java/org/jboss/jca/core/connectionmanager/pool and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 6 14:35:20 EDT 2011
Author: jesper.pedersen
Date: 2011-04-06 14:35:20 -0400 (Wed, 06 Apr 2011)
New Revision: 111110
Modified:
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/connectionmanager/pool/PoolStatistics.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolStatistics.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolStatisticsImpl.java
projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/SemaphoreArrayListManagedConnectionPool.java
projects/jboss-jca/trunk/core/src/main/resources/poolstatistics.properties
projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/DsXmlDeployer.java
Log:
[JBJCA-542] Statistics support (Part 3)
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/connectionmanager/pool/PoolStatistics.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/connectionmanager/pool/PoolStatistics.java 2011-04-06 15:14:12 UTC (rev 111109)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/api/connectionmanager/pool/PoolStatistics.java 2011-04-06 18:35:20 UTC (rev 111110)
@@ -30,4 +30,45 @@
*/
public interface PoolStatistics extends StatisticsPlugin
{
+ /**
+ * Get active count
+ * @return The value
+ */
+ public int getActiveCount();
+
+ /**
+ * Get the average time spent waiting on a connection (milliseconds)
+ * @return The value
+ */
+ public long getAverageBlockingTime();
+
+ /**
+ * Get created count
+ * @return The value
+ */
+ public int getCreatedCount();
+
+ /**
+ * Get destroyed count
+ * @return The value
+ */
+ public int getDestroyedCount();
+
+ /**
+ * Get max wait time (milliseconds)
+ * @return The value
+ */
+ public long getMaxWaitTime();
+
+ /**
+ * Get timed out
+ * @return The value
+ */
+ public int getTimedOut();
+
+ /**
+ * Get the total time spent waiting on connections (milliseconds)
+ * @return The value
+ */
+ public long getTotalBlockingTime();
}
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolStatistics.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolStatistics.java 2011-04-06 15:14:12 UTC (rev 111109)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/SubPoolStatistics.java 2011-04-06 18:35:20 UTC (rev 111110)
@@ -41,6 +41,14 @@
*/
public class SubPoolStatistics implements PoolStatistics
{
+ private static final String ACTIVE_COUNT = "ActiveCount";
+ private static final String AVERAGE_BLOCKING_TIME = "AverageBlockingTime";
+ private static final String CREATED_COUNT = "CreatedCount";
+ private static final String DESTROYED_COUNT = "DestroyedCount";
+ private static final String MAX_WAIT_TIME = "MaxWaitTime";
+ private static final String TIMED_OUT = "TimedOut";
+ private static final String TOTAL_BLOCKING_TIME = "TotalBlockingTime";
+
private ConcurrentMap<Object, SubPoolContext> subPools;
private Set<String> names;
private Map<String, Class> types;
@@ -58,6 +66,27 @@
Set<String> n = new HashSet<String>();
Map<String, Class> t = new HashMap<String, Class>();
+ n.add(ACTIVE_COUNT);
+ t.put(ACTIVE_COUNT, int.class);
+
+ n.add(AVERAGE_BLOCKING_TIME);
+ t.put(AVERAGE_BLOCKING_TIME, long.class);
+
+ n.add(CREATED_COUNT);
+ t.put(CREATED_COUNT, int.class);
+
+ n.add(DESTROYED_COUNT);
+ t.put(DESTROYED_COUNT, int.class);
+
+ n.add(MAX_WAIT_TIME);
+ t.put(MAX_WAIT_TIME, long.class);
+
+ n.add(TIMED_OUT);
+ t.put(TIMED_OUT, int.class);
+
+ n.add(TOTAL_BLOCKING_TIME);
+ t.put(TOTAL_BLOCKING_TIME, long.class);
+
this.names = Collections.unmodifiableSet(n);
this.types = Collections.unmodifiableMap(t);
this.enabled = new AtomicBoolean(true);
@@ -126,6 +155,35 @@
@Override
public Object getValue(String name)
{
+ if (ACTIVE_COUNT.equals(name))
+ {
+ return getActiveCount();
+ }
+ else if (AVERAGE_BLOCKING_TIME.equals(name))
+ {
+ return getAverageBlockingTime();
+ }
+ else if (CREATED_COUNT.equals(name))
+ {
+ return getCreatedCount();
+ }
+ else if (DESTROYED_COUNT.equals(name))
+ {
+ return getDestroyedCount();
+ }
+ else if (MAX_WAIT_TIME.equals(name))
+ {
+ return getMaxWaitTime();
+ }
+ else if (TIMED_OUT.equals(name))
+ {
+ return getTimedOut();
+ }
+ else if (TOTAL_BLOCKING_TIME.equals(name))
+ {
+ return getTotalBlockingTime();
+ }
+
return null;
}
@@ -152,8 +210,111 @@
/**
* {@inheritDoc}
*/
+ public int getActiveCount()
+ {
+ int result = 0;
+
+ for (SubPoolContext spc : subPools.values())
+ {
+ result += spc.getSubPool().getStatistics().getActiveCount();
+ }
+
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getAverageBlockingTime()
+ {
+ return getCreatedCount() != 0 ? getTotalBlockingTime() / getCreatedCount() : 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getCreatedCount()
+ {
+ int result = 0;
+
+ for (SubPoolContext spc : subPools.values())
+ {
+ result += spc.getSubPool().getStatistics().getCreatedCount();
+ }
+
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getDestroyedCount()
+ {
+ int result = 0;
+
+ for (SubPoolContext spc : subPools.values())
+ {
+ result += spc.getSubPool().getStatistics().getDestroyedCount();
+ }
+
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getMaxWaitTime()
+ {
+ long result = Long.MIN_VALUE;
+
+ for (SubPoolContext spc : subPools.values())
+ {
+ long v = spc.getSubPool().getStatistics().getMaxWaitTime();
+ if (v > result)
+ result = v;
+ }
+
+ return result != Long.MIN_VALUE ? result : 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getTimedOut()
+ {
+ int result = 0;
+
+ for (SubPoolContext spc : subPools.values())
+ {
+ result += spc.getSubPool().getStatistics().getTimedOut();
+ }
+
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getTotalBlockingTime()
+ {
+ long result = 0;
+
+ for (SubPoolContext spc : subPools.values())
+ {
+ result += spc.getSubPool().getStatistics().getTotalBlockingTime();
+ }
+
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void clear()
{
- // Do nothing
+ for (SubPoolContext spc : subPools.values())
+ {
+ spc.getSubPool().getStatistics().clear();
+ }
}
}
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolStatisticsImpl.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolStatisticsImpl.java 2011-04-06 15:14:12 UTC (rev 111109)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolStatisticsImpl.java 2011-04-06 18:35:20 UTC (rev 111110)
@@ -30,6 +30,8 @@
import java.util.ResourceBundle;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
/**
* Core statistics.
@@ -38,11 +40,25 @@
*/
public class ManagedConnectionPoolStatisticsImpl implements ManagedConnectionPoolStatistics
{
+ private static final String ACTIVE_COUNT = "ActiveCount";
+ private static final String AVERAGE_BLOCKING_TIME = "AverageBlockingTime";
+ private static final String CREATED_COUNT = "CreatedCount";
+ private static final String DESTROYED_COUNT = "DestroyedCount";
+ private static final String MAX_WAIT_TIME = "MaxWaitTime";
+ private static final String TIMED_OUT = "TimedOut";
+ private static final String TOTAL_BLOCKING_TIME = "TotalBlockingTime";
+
private Set<String> names;
private Map<String, Class> types;
private AtomicBoolean enabled;
private Map<Locale, ResourceBundle> rbs;
+ private AtomicLong totalBlockingTime;
+ private AtomicInteger createdCount;
+ private AtomicInteger destroyedCount;
+ private AtomicLong maxWaitTime;
+ private AtomicInteger timedOut;
+
/**
* Constructor
*/
@@ -51,6 +67,27 @@
Set<String> n = new HashSet<String>();
Map<String, Class> t = new HashMap<String, Class>();
+ n.add(ACTIVE_COUNT);
+ t.put(ACTIVE_COUNT, int.class);
+
+ n.add(AVERAGE_BLOCKING_TIME);
+ t.put(AVERAGE_BLOCKING_TIME, long.class);
+
+ n.add(CREATED_COUNT);
+ t.put(CREATED_COUNT, int.class);
+
+ n.add(DESTROYED_COUNT);
+ t.put(DESTROYED_COUNT, int.class);
+
+ n.add(MAX_WAIT_TIME);
+ t.put(MAX_WAIT_TIME, long.class);
+
+ n.add(TIMED_OUT);
+ t.put(TIMED_OUT, int.class);
+
+ n.add(TOTAL_BLOCKING_TIME);
+ t.put(TOTAL_BLOCKING_TIME, long.class);
+
this.names = Collections.unmodifiableSet(n);
this.types = Collections.unmodifiableMap(t);
this.enabled = new AtomicBoolean(true);
@@ -61,6 +98,12 @@
this.rbs = new HashMap<Locale, ResourceBundle>(1);
this.rbs.put(Locale.US, defaultResourceBundle);
+ this.totalBlockingTime = new AtomicLong(0);
+ this.createdCount = new AtomicInteger(0);
+ this.destroyedCount = new AtomicInteger(0);
+ this.maxWaitTime = new AtomicLong(Long.MIN_VALUE);
+ this.timedOut = new AtomicInteger(0);
+
clear();
}
@@ -119,6 +162,35 @@
*/
public Object getValue(String name)
{
+ if (ACTIVE_COUNT.equals(name))
+ {
+ return getActiveCount();
+ }
+ else if (AVERAGE_BLOCKING_TIME.equals(name))
+ {
+ return getAverageBlockingTime();
+ }
+ else if (CREATED_COUNT.equals(name))
+ {
+ return getCreatedCount();
+ }
+ else if (DESTROYED_COUNT.equals(name))
+ {
+ return getDestroyedCount();
+ }
+ else if (MAX_WAIT_TIME.equals(name))
+ {
+ return getMaxWaitTime();
+ }
+ else if (TIMED_OUT.equals(name))
+ {
+ return getTimedOut();
+ }
+ else if (TOTAL_BLOCKING_TIME.equals(name))
+ {
+ return getTotalBlockingTime();
+ }
+
return null;
}
@@ -141,6 +213,98 @@
/**
* {@inheritDoc}
*/
+ public int getActiveCount()
+ {
+ return createdCount.get() - destroyedCount.get();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getAverageBlockingTime()
+ {
+ return createdCount.get() != 0 ? totalBlockingTime.get() / createdCount.get() : 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getCreatedCount()
+ {
+ return createdCount.get();
+ }
+
+ /**
+ * Delta the created count value
+ */
+ public void deltaCreatedCount()
+ {
+ createdCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getDestroyedCount()
+ {
+ return destroyedCount.get();
+ }
+
+ /**
+ * Delta the destroyed count value
+ */
+ public void deltaDestroyedCount()
+ {
+ destroyedCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getMaxWaitTime()
+ {
+ return maxWaitTime.get() != Long.MIN_VALUE ? maxWaitTime.get() : 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getTimedOut()
+ {
+ return timedOut.get();
+ }
+
+ /**
+ * Delta the timed out value
+ */
+ public void deltaTimedOut()
+ {
+ timedOut.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getTotalBlockingTime()
+ {
+ return totalBlockingTime.get();
+ }
+
+ /**
+ * Add delta to total blocking timeout
+ * @param delta The value
+ */
+ public void deltaTotalBlockingTime(long delta)
+ {
+ totalBlockingTime.addAndGet(delta);
+
+ if (delta > maxWaitTime.get())
+ maxWaitTime.set(delta);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public void clear()
{
// Do nothing
Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/SemaphoreArrayListManagedConnectionPool.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/SemaphoreArrayListManagedConnectionPool.java 2011-04-06 15:14:12 UTC (rev 111109)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/SemaphoreArrayListManagedConnectionPool.java 2011-04-06 18:35:20 UTC (rev 111110)
@@ -235,6 +235,8 @@
{
if (permits.tryAcquire(poolConfiguration.getBlockingTimeout(), TimeUnit.MILLISECONDS))
{
+ statistics.deltaTotalBlockingTime(System.currentTimeMillis() - startWait);
+
//We have a permit to get a connection. Is there one in the pool already?
ConnectionListener cl = null;
do
@@ -371,6 +373,7 @@
catch (InterruptedException ie)
{
long end = System.currentTimeMillis() - startWait;
+ statistics.deltaTotalBlockingTime(end);
throw new ResourceException("Interrupted while requesting permit! Waited " + end + " ms");
}
}
@@ -539,6 +542,8 @@
ConnectionListener cl = cls.get(0);
if (cl.isTimedOut(timeout) && shouldRemove())
{
+ statistics.deltaTimedOut();
+
// We need to destroy this one
cls.remove(0);
@@ -665,12 +670,14 @@
{
ManagedConnection mc = mcf.createManagedConnection(subject, cri);
+ statistics.deltaCreatedCount();
try
{
return clf.createConnectionListener(mc, this);
}
catch (ResourceException re)
{
+ statistics.deltaDestroyedCount();
mc.destroy();
throw re;
}
@@ -691,6 +698,7 @@
return;
}
+ statistics.deltaDestroyedCount();
cl.setState(ConnectionState.DESTROYED);
try
Modified: projects/jboss-jca/trunk/core/src/main/resources/poolstatistics.properties
===================================================================
--- projects/jboss-jca/trunk/core/src/main/resources/poolstatistics.properties 2011-04-06 15:14:12 UTC (rev 111109)
+++ projects/jboss-jca/trunk/core/src/main/resources/poolstatistics.properties 2011-04-06 18:35:20 UTC (rev 111110)
@@ -0,0 +1,7 @@
+ActiveCount=The active count
+AverageBlockingTime=The average time spent blocking for a connection
+CreatedCount=The created count
+DestroyedCount=The destroyed count
+MaxWaitTime=The maximum wait time for a connection
+TimedOut=The timed out count
+TotalBlockingTime=The total blocking time
Modified: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/DsXmlDeployer.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/DsXmlDeployer.java 2011-04-06 15:14:12 UTC (rev 111109)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/fungal/DsXmlDeployer.java 2011-04-06 18:35:20 UTC (rev 111110)
@@ -383,6 +383,18 @@
server.registerMBean(dsPDMB, dsPON);
ons.add(dsPON);
+
+ if (mgtDs.getPool().getStatistics() != null)
+ {
+ String dsPSName = baseName + ",type=PoolStatistics";
+
+ DynamicMBean dsPSDMB = JMX.createMBean(mgtDs.getPool().getStatistics(), "PoolStatistics");
+ ObjectName dsPSON = new ObjectName(dsPSName);
+
+ server.registerMBean(dsPSDMB, dsPSON);
+
+ ons.add(dsPSON);
+ }
}
if (mgtDs.getStatistics() != null)
More information about the jboss-cvs-commits
mailing list