[jboss-cvs] JBossAS SVN: r111122 - in projects/jboss-jca/trunk/adapters/src/main: java/org/jboss/jca/adapters/jdbc/statistics and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 7 16:06:17 EDT 2011


Author: jesper.pedersen
Date: 2011-04-07 16:06:17 -0400 (Thu, 07 Apr 2011)
New Revision: 111122

Modified:
   projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnection.java
   projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/statistics/JdbcStatisticsPlugin.java
   projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/jar/jdbc.properties
Log:
[JBJCA-542] Statistics support (Part 6)

Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnection.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnection.java	2011-04-07 18:36:33 UTC (rev 111121)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/BaseWrapperManagedConnection.java	2011-04-07 20:06:17 UTC (rev 111122)
@@ -170,7 +170,10 @@
       this.props = props;
 
       if (psCacheSize > 0)
+      {
          psCache = new PreparedStatementCache(psCacheSize);
+         mcf.getStatistics().registerPreparedStatementCache(psCache);
+      }
 
       if (transactionIsolation == -1)
          this.transactionIsolation = con.getTransactionIsolation();
@@ -400,6 +403,9 @@
       {
          getLog().trace("Ignored error during close: ", ignored);
       }
+
+      if (psCache != null)
+         mcf.getStatistics().deregisterPreparedStatementCache(psCache);
    }
 
    /**
@@ -573,6 +579,8 @@
    {
       if (psCache != null)
       {
+         mcf.getStatistics().deltaPreparedStatementCacheAccessCount();
+
          PreparedStatementCache.Key key = 
             new PreparedStatementCache.Key(sql,
                                            PreparedStatementCache.Key.PREPARED_STATEMENT, 
@@ -584,10 +592,14 @@
          {
             if (canUse(cachedps))
             {
+               mcf.getStatistics().deltaPreparedStatementCacheHitCount();
+
                cachedps.inUse();
             }
             else
             {
+               mcf.getStatistics().deltaPreparedStatementCacheMissCount();
+
                return doPrepareStatement(sql, resultSetType, resultSetConcurrency);
             }
          }
@@ -596,6 +608,8 @@
             PreparedStatement ps = doPrepareStatement(sql, resultSetType, resultSetConcurrency);
             cachedps = WRAPPED_CONNECTION_FACTORY.createCachedPreparedStatement(ps);
             psCache.insert(key, cachedps);
+
+            mcf.getStatistics().deltaPreparedStatementCacheAddCount();
          }
 
          return cachedps;
@@ -631,6 +645,8 @@
    {
       if (psCache != null)
       {
+         mcf.getStatistics().deltaPreparedStatementCacheAccessCount();
+
          PreparedStatementCache.Key key = 
             new PreparedStatementCache.Key(sql, 
                                            PreparedStatementCache.Key.CALLABLE_STATEMENT, 
@@ -643,10 +659,12 @@
          {
             if (canUse(cachedps))
             {
+               mcf.getStatistics().deltaPreparedStatementCacheHitCount();
                cachedps.inUse();
             }
             else
             {
+               mcf.getStatistics().deltaPreparedStatementCacheMissCount();
                return doPrepareCall(sql, resultSetType, resultSetConcurrency);
             }
          }
@@ -655,6 +673,7 @@
             CallableStatement cs = doPrepareCall(sql, resultSetType, resultSetConcurrency);
             cachedps = WRAPPED_CONNECTION_FACTORY.createCachedCallableStatement(cs);
             psCache.insert(key, cachedps);
+            mcf.getStatistics().deltaPreparedStatementCacheAddCount();
          }
          return cachedps;
       }

Modified: projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/statistics/JdbcStatisticsPlugin.java
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/statistics/JdbcStatisticsPlugin.java	2011-04-07 18:36:33 UTC (rev 111121)
+++ projects/jboss-jca/trunk/adapters/src/main/java/org/jboss/jca/adapters/jdbc/statistics/JdbcStatisticsPlugin.java	2011-04-07 20:06:17 UTC (rev 111122)
@@ -21,6 +21,7 @@
  */
 package org.jboss.jca.adapters.jdbc.statistics;
 
+import org.jboss.jca.adapters.jdbc.PreparedStatementCache;
 import org.jboss.jca.core.spi.statistics.StatisticsPlugin;
 
 import java.util.Collections;
@@ -31,6 +32,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;
 
 /**
  * JDBC statistics.
@@ -39,11 +42,26 @@
  */
 public class JdbcStatisticsPlugin implements StatisticsPlugin
 {
+   private static final String PREPARED_STATEMENT_CACHE_ACCESS_COUNT = "PreparedStatementCacheAccessCount";
+   private static final String PREPARED_STATEMENT_CACHE_ADD_COUNT = "PreparedStatementCacheAddCount";
+   private static final String PREPARED_STATEMENT_CACHE_CURRENT_SIZE = "PreparedStatementCacheCurrentSize";
+   private static final String PREPARED_STATEMENT_CACHE_DELETE_COUNT = "PreparedStatementCacheDeleteCount";
+   private static final String PREPARED_STATEMENT_CACHE_HIT_COUNT = "PreparedStatementCacheHitCount";
+   private static final String PREPARED_STATEMENT_CACHE_MISS_COUNT = "PreparedStatementCacheMissCount";
+
+   private AtomicLong preparedStatementCacheAccessCount;
+   private AtomicLong preparedStatementCacheAddCount;
+   private AtomicLong preparedStatementCacheDeleteCount;
+   private AtomicInteger preparedStatementCacheHitCount;
+   private AtomicInteger preparedStatementCacheMissCount;
+
    private Set<String> names;
    private Map<String, Class> types;
    private AtomicBoolean enabled;
    private Map<Locale, ResourceBundle> rbs;
 
+   private Set<PreparedStatementCache> psCaches;
+
    /**
     * Constructor
     */
@@ -52,6 +70,24 @@
       Set<String> n = new HashSet<String>();
       Map<String, Class> t = new HashMap<String, Class>();
 
+      n.add(PREPARED_STATEMENT_CACHE_ACCESS_COUNT);
+      t.put(PREPARED_STATEMENT_CACHE_ACCESS_COUNT, long.class);
+
+      n.add(PREPARED_STATEMENT_CACHE_ADD_COUNT);
+      t.put(PREPARED_STATEMENT_CACHE_ADD_COUNT, long.class);
+
+      n.add(PREPARED_STATEMENT_CACHE_CURRENT_SIZE);
+      t.put(PREPARED_STATEMENT_CACHE_CURRENT_SIZE, int.class);
+
+      n.add(PREPARED_STATEMENT_CACHE_DELETE_COUNT);
+      t.put(PREPARED_STATEMENT_CACHE_DELETE_COUNT, long.class);
+
+      n.add(PREPARED_STATEMENT_CACHE_HIT_COUNT);
+      t.put(PREPARED_STATEMENT_CACHE_HIT_COUNT, int.class);
+
+      n.add(PREPARED_STATEMENT_CACHE_MISS_COUNT);
+      t.put(PREPARED_STATEMENT_CACHE_MISS_COUNT, int.class);
+
       this.names = Collections.unmodifiableSet(n);
       this.types = Collections.unmodifiableMap(t);
       this.enabled = new AtomicBoolean(true);
@@ -61,6 +97,14 @@
       this.rbs = new HashMap<Locale, ResourceBundle>(1);
       this.rbs.put(Locale.US, defaultResourceBundle);
 
+      this.preparedStatementCacheAccessCount = new AtomicLong(0);
+      this.preparedStatementCacheAddCount = new AtomicLong(0);
+      this.preparedStatementCacheDeleteCount = new AtomicLong(0);
+      this.preparedStatementCacheHitCount = new AtomicInteger(0);
+      this.preparedStatementCacheMissCount = new AtomicInteger(0);
+
+      this.psCaches = Collections.synchronizedSet(new HashSet<PreparedStatementCache>());
+
       clear();
    }
 
@@ -118,6 +162,31 @@
     */
    public Object getValue(String name)
    {
+      if (PREPARED_STATEMENT_CACHE_ACCESS_COUNT.equals(name))
+      {
+         return getPreparedStatementCacheAccessCount();
+      }
+      else if (PREPARED_STATEMENT_CACHE_ADD_COUNT.equals(name))
+      {
+         return getPreparedStatementCacheAddCount();
+      }
+      else if (PREPARED_STATEMENT_CACHE_CURRENT_SIZE.equals(name))
+      {
+         return getPreparedStatementCacheCurrentSize();
+      }
+      else if (PREPARED_STATEMENT_CACHE_DELETE_COUNT.equals(name))
+      {
+         return getPreparedStatementCacheDeleteCount();
+      }
+      else if (PREPARED_STATEMENT_CACHE_HIT_COUNT.equals(name))
+      {
+         return getPreparedStatementCacheHitCount();
+      }
+      else if (PREPARED_STATEMENT_CACHE_MISS_COUNT.equals(name))
+      {
+         return getPreparedStatementCacheMissCount();
+      }
+
       return null;
    }
 
@@ -138,9 +207,162 @@
    }
 
    /**
+    * Register prepared statement cache
+    * @param v The cache
+    */
+   public void registerPreparedStatementCache(PreparedStatementCache v)
+   {
+      psCaches.add(v);
+   }
+
+   /**
+    * Deregister prepared statement cache
+    * @param v The cache
+    */
+   public void deregisterPreparedStatementCache(PreparedStatementCache v)
+   {
+      psCaches.remove(v);
+   }
+
+   /**
+    * Get the access count for the prepated statement cache
+    * @return The value
+    */
+   public long getPreparedStatementCacheAccessCount()
+   {
+      if (isEnabled())
+         return preparedStatementCacheAccessCount.get();
+
+      return 0;
+   }
+
+   /**
+    * Delta the access count for the prepated statement cache
+    */
+   public void deltaPreparedStatementCacheAccessCount()
+   {
+      if (isEnabled())
+         preparedStatementCacheAccessCount.incrementAndGet();
+   }
+
+   /**
+    * Get the add count for the prepated statement cache
+    * @return The value
+    */
+   public long getPreparedStatementCacheAddCount()
+   {
+      if (isEnabled())
+         return preparedStatementCacheAddCount.get();
+
+      return 0;
+   }
+
+   /**
+    * Delta the add count for the prepated statement cache
+    */
+   public void deltaPreparedStatementCacheAddCount()
+   {
+      if (isEnabled())
+         preparedStatementCacheAddCount.incrementAndGet();
+   }
+
+   /**
+    * Get the current size for the prepated statement cache
+    * @return The value
+    */
+   public int getPreparedStatementCacheCurrentSize()
+   {
+      if (isEnabled())
+      {
+         Set<PreparedStatementCache> copy = new HashSet<PreparedStatementCache>(psCaches);
+         int size = 0;
+
+         for (PreparedStatementCache psc : copy)
+         {
+            size += psc.size();
+         }
+
+         return size;
+      }
+
+      return 0;
+   }
+
+   /**
+    * Get the delete count for the prepated statement cache
+    * @return The value
+    */
+   public long getPreparedStatementCacheDeleteCount()
+   {
+      if (isEnabled())
+         return preparedStatementCacheDeleteCount.get();
+
+      return 0;
+   }
+
+   /**
+    * Delta the delete count for the prepated statement cache
+    */
+   public void deltaPreparedStatementCacheDeleteCount()
+   {
+      if (isEnabled())
+         preparedStatementCacheDeleteCount.incrementAndGet();
+   }
+
+   /**
+    * Get the hit count for the prepated statement cache
+    * @return The value
+    */
+   public int getPreparedStatementCacheHitCount()
+   {
+      if (isEnabled())
+         return preparedStatementCacheHitCount.get();
+
+      return 0;
+   }
+
+   /**
+    * Delta the hit count for the prepated statement cache
+    */
+   public void deltaPreparedStatementCacheHitCount()
+   {
+      if (isEnabled())
+         preparedStatementCacheHitCount.incrementAndGet();
+   }
+
+   /**
+    * Get the miss count for the prepated statement cache
+    * @return The value
+    */
+   public int getPreparedStatementCacheMissCount()
+   {
+      if (isEnabled())
+         return preparedStatementCacheMissCount.get();
+
+      return 0;
+   }
+
+   /**
+    * Delta the miss count for the prepated statement cache
+    */
+   public void deltaPreparedStatementCacheMissCount()
+   {
+      if (isEnabled())
+         preparedStatementCacheMissCount.incrementAndGet();
+   }
+
+   /**
     * {@inheritDoc}
     */
    public synchronized void clear()
    {
+      if (isEnabled())
+      {
+         preparedStatementCacheAccessCount.set(0);
+         preparedStatementCacheAddCount.set(0);
+         preparedStatementCacheDeleteCount.set(0);
+         preparedStatementCacheHitCount.set(0);
+         preparedStatementCacheMissCount.set(0);
+      }
    }
 }

Modified: projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/jar/jdbc.properties
===================================================================
--- projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/jar/jdbc.properties	2011-04-07 18:36:33 UTC (rev 111121)
+++ projects/jboss-jca/trunk/adapters/src/main/resources/jdbc/jar/jdbc.properties	2011-04-07 20:06:17 UTC (rev 111122)
@@ -0,0 +1,6 @@
+PreparedStatementCacheAccessCount=The number of times that the statement cache was accessed
+PreparedStatementCacheAddCount=The number of statements added to the statement cache
+PreparedStatementCacheCurrentSize=The number of prepared and callable statements currently cached in the statement cache
+PreparedStatementCacheDeleteCount=The number of statements discarded from the cache
+PreparedStatementCacheHitCount=The number of times that statements from the cache were used
+PreparedStatementCacheMissCount=The number of times that a statement request could not be satisfied with a statement from the cache



More information about the jboss-cvs-commits mailing list