[jboss-cvs] JBossAS SVN: r112096 - projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 19 12:01:20 EDT 2011


Author: jesper.pedersen
Date: 2011-08-19 12:01:19 -0400 (Fri, 19 Aug 2011)
New Revision: 112096

Added:
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolUtility.java
Modified:
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ArrayBlockingQueueManagedConnectionPool.java
   projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/SemaphoreArrayListManagedConnectionPool.java
Log:
[JBJCA-652] Business logging

Modified: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ArrayBlockingQueueManagedConnectionPool.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ArrayBlockingQueueManagedConnectionPool.java	2011-08-19 14:58:49 UTC (rev 112095)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ArrayBlockingQueueManagedConnectionPool.java	2011-08-19 16:01:19 UTC (rev 112096)
@@ -62,6 +62,9 @@
    /** The log */
    private CoreLogger log;
 
+   /** Whether debug is enabled */
+   private boolean debug;
+   
    /** Whether trace is enabled */
    private boolean trace;
    
@@ -86,13 +89,6 @@
    /** The pool */
    private Pool pool;
 
-   /** 
-    * Copy of the maximum size from the pooling parameters.
-    * Dynamic changes to this value are not compatible with
-    * the semaphore which cannot change be dynamically changed.
-    */
-   private int maxSize;
-
    /** The available connection event listeners */
    private ArrayBlockingQueue<ConnectionListener> cls;
 
@@ -135,13 +131,13 @@
       this.defaultSubject = subject;
       this.defaultCri = cri;
       this.poolConfiguration = pc;
-      this.maxSize = pc.getMaxSize();
       this.pool = p;
       this.log = pool.getLogger();
+      this.debug = log.isDebugEnabled();
       this.trace = log.isTraceEnabled();
-      this.cls = new ArrayBlockingQueue<ConnectionListener>(this.maxSize, true);
+      this.cls = new ArrayBlockingQueue<ConnectionListener>(pc.getMaxSize(), true);
       this.checkedOut = new ConcurrentSkipListSet<ConnectionListener>();
-      this.statistics = new ManagedConnectionPoolStatisticsImpl(maxSize);
+      this.statistics = new ManagedConnectionPoolStatisticsImpl(pc.getMaxSize());
   
       // Schedule managed connection pool for prefill
       if (pc.isPrefill() && p instanceof PrefillPool && pc.getMinSize() > 0)
@@ -198,6 +194,22 @@
     */
    public ConnectionListener getConnection(Subject subject, ConnectionRequestInfo cri) throws ResourceException
    {
+      if (trace)
+      {
+         synchronized (cls)
+         {
+            String method = "getConnection(" + subject + ", " + cri + ")";
+            log.trace(ManagedConnectionPoolUtility.fullDetails(System.identityHashCode(this), method,
+                                                               mcf, clf, pool, poolConfiguration,
+                                                               cls, checkedOut, statistics));
+         }
+      }
+      else if (debug)
+      {
+         String method = "getConnection(" + subject + ", " + cri + ")";
+         log.debug(ManagedConnectionPoolUtility.details(method, pool.getName(), statistics));
+      }
+
       subject = (subject == null) ? defaultSubject : subject;
       cri = (cri == null) ? defaultCri : cri;
 
@@ -353,6 +365,22 @@
     */
    public void returnConnection(ConnectionListener cl, boolean kill)
    {
+      if (trace)
+      {
+         synchronized (cls)
+         {
+            String method = "returnConnection(" + Integer.toHexString(System.identityHashCode(cl)) + ", " + kill + ")";
+            log.trace(ManagedConnectionPoolUtility.fullDetails(System.identityHashCode(this), method,
+                                                               mcf, clf, pool, poolConfiguration,
+                                                               cls, checkedOut, statistics));
+         }
+      }
+      else if (debug)
+      {
+         String method = "returnConnection(" + Integer.toHexString(System.identityHashCode(cl)) + ", " + kill + ")";
+         log.debug(ManagedConnectionPoolUtility.details(method, pool.getName(), statistics));
+      }
+
       if (cl.getState() == ConnectionState.DESTROYED)
       {
          if (trace)
@@ -361,9 +389,6 @@
          return;
       }
 
-      if (trace)
-         log.trace("putting ManagedConnection back into pool kill=" + kill + " cl=" + cl);
-
       try
       {
          cl.getManagedConnection().cleanup();

Added: projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolUtility.java
===================================================================
--- projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolUtility.java	                        (rev 0)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/ManagedConnectionPoolUtility.java	2011-08-19 16:01:19 UTC (rev 112096)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jca.core.connectionmanager.pool.mcp;
+
+import org.jboss.jca.core.api.connectionmanager.pool.PoolConfiguration;
+import org.jboss.jca.core.connectionmanager.listener.ConnectionListener;
+import org.jboss.jca.core.connectionmanager.listener.ConnectionListenerFactory;
+import org.jboss.jca.core.connectionmanager.pool.api.Pool;
+
+import java.util.Collection;
+
+import javax.resource.spi.ManagedConnectionFactory;
+
+/**
+ * Managed connection pool utility class
+ *
+ * @author <a href="mailto:jesper.pedersen at jboss.org">Jesper Pedersen</a>
+ */
+class ManagedConnectionPoolUtility
+{
+   private static String newLine = SecurityActions.getSystemProperty("line.separator");
+
+   /**
+    * Get the full details of a managed connection pool state
+    * @param method The method identifier
+    * @param poolName The pool name
+    * @param mcps The statistics
+    * @return The state
+    */
+   static String details(String method, String poolName, ManagedConnectionPoolStatistics mcps)
+   {
+      StringBuilder sb = new StringBuilder(1024);
+
+      sb.append(poolName).append(": ");
+      sb.append(method).append(" ");
+      sb.append("[");
+      sb.append(mcps.getActiveCount());
+      sb.append("/");
+      sb.append(mcps.getAvailableCount());
+      sb.append("]");
+
+      return sb.toString();
+   }
+
+   /**
+    * Get the full details of a managed connection pool state
+    * @param identifier The managed connection pool identifier
+    * @param method The method identifier
+    * @param mcf The managed connection factory
+    * @param clf The connection listener factory
+    * @param pool The pool
+    * @param pc The pool configuration
+    * @param available The available connection listeners
+    * @param inUse The in-use connection listeners
+    * @param mcps The statistics
+    * @return The state
+    */
+   static String fullDetails(int identifier, String method, ManagedConnectionFactory mcf,
+                             ConnectionListenerFactory clf, Pool pool, PoolConfiguration pc,
+                             Collection<ConnectionListener> available, Collection<ConnectionListener> inUse,
+                             ManagedConnectionPoolStatistics mcps)
+   {
+      StringBuilder sb = new StringBuilder(1024);
+
+      sb.append("ManagedConnectionPool: ").append(Integer.toHexString(identifier)).append(newLine);
+      sb.append("Method: ").append(method).append(newLine);
+      sb.append("ManagedConnectionFactory:").append(newLine);
+      sb.append("  Class: ").append(mcf.getClass().getName()).append(newLine);
+      sb.append("  Object: ").append(Integer.toHexString(System.identityHashCode(mcf))).append(newLine);
+      sb.append("ConnectionListenerFactory:").append(newLine);
+      sb.append("  Class: ").append(clf.getClass().getName()).append(newLine);
+      sb.append("  Object: ").append(Integer.toHexString(System.identityHashCode(clf))).append(newLine);
+      sb.append("Pool:").append(newLine);
+      sb.append("  Name: ").append(pool.getName()).append(newLine);
+      sb.append("PoolConfiguration:").append(newLine);
+      sb.append("  MinSize: ").append(pc.getMinSize()).append(newLine);
+      sb.append("  MaxSize: ").append(pc.getMaxSize()).append(newLine);
+      sb.append("  BlockingTimeout: ").append(pc.getBlockingTimeout()).append(newLine);
+      sb.append("  IdleTimeout: ").append(pc.getIdleTimeout()).append(newLine);
+      sb.append("  BackgroundValidation: ").append(pc.isBackgroundValidation()).append(newLine);
+      sb.append("  BackgroundValidationMillis: ").append(pc.getBackgroundValidationMillis()).append(newLine);
+      sb.append("  StrictMin: ").append(pc.isStrictMin()).append(newLine);
+      sb.append("  UseFastFail: ").append(pc.isUseFastFail()).append(newLine);
+
+      sb.append("Available:").append(newLine);
+      if (available != null)
+      {
+         for (ConnectionListener cl : available)
+         {
+            sb.append("  ").append(Integer.toHexString(System.identityHashCode(cl)));
+            sb.append(" (").append(cl.getState()).append(")").append(newLine);
+         }
+      }
+
+      sb.append("InUse:").append(newLine);
+      if (inUse != null)
+      {
+         for (ConnectionListener cl : inUse)
+         {
+            sb.append("  ").append(Integer.toHexString(System.identityHashCode(cl)));
+            sb.append(" (").append(cl.getState()).append(")").append(newLine);
+         }
+      }
+
+      sb.append("Statistics:").append(newLine);
+      sb.append("  ActiveCount: ").append(mcps.getActiveCount()).append(newLine);
+      sb.append("  AvailableCount: ").append(mcps.getAvailableCount()).append(newLine);
+      sb.append("  AverageBlockingTime: ").append(mcps.getAverageBlockingTime()).append(newLine);
+      sb.append("  AverageCreationTime: ").append(mcps.getAverageCreationTime()).append(newLine);
+      sb.append("  CreatedCount: ").append(mcps.getCreatedCount()).append(newLine);
+      sb.append("  DestroyedCount: ").append(mcps.getDestroyedCount()).append(newLine);
+      sb.append("  MaxCreationTime: ").append(mcps.getMaxCreationTime()).append(newLine);
+      sb.append("  MaxUsedCount: ").append(mcps.getMaxUsedCount()).append(newLine);
+      sb.append("  MaxWaitCount: ").append(mcps.getMaxWaitCount()).append(newLine);
+      sb.append("  MaxWaitTime: ").append(mcps.getMaxWaitTime()).append(newLine);
+      sb.append("  TimedOut: ").append(mcps.getTimedOut()).append(newLine);
+      sb.append("  TotalBlockingTime: ").append(mcps.getTotalBlockingTime()).append(newLine);
+      sb.append("  TotalCreationTime: ").append(mcps.getTotalCreationTime());
+
+      return sb.toString();
+   }
+}

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-08-19 14:58:49 UTC (rev 112095)
+++ projects/jboss-jca/trunk/core/src/main/java/org/jboss/jca/core/connectionmanager/pool/mcp/SemaphoreArrayListManagedConnectionPool.java	2011-08-19 16:01:19 UTC (rev 112096)
@@ -66,6 +66,9 @@
    /** The log */
    private CoreLogger log;
 
+   /** Whether debug is enabled */
+   private boolean debug;
+   
    /** Whether trace is enabled */
    private boolean trace;
    
@@ -149,6 +152,7 @@
       this.maxSize = pc.getMaxSize();
       this.pool = p;
       this.log = pool.getLogger();
+      this.debug = log.isDebugEnabled();
       this.trace = log.isTraceEnabled();
       this.cls = new ArrayList<ConnectionListener>(this.maxSize);
       this.statistics = new ManagedConnectionPoolStatisticsImpl(maxSize);
@@ -223,6 +227,22 @@
     */
    public ConnectionListener getConnection(Subject subject, ConnectionRequestInfo cri) throws ResourceException
    {
+      if (trace)
+      {
+         synchronized (cls)
+         {
+            String method = "getConnection(" + subject + ", " + cri + ")";
+            log.trace(ManagedConnectionPoolUtility.fullDetails(System.identityHashCode(this), method,
+                                                               mcf, clf, pool, poolConfiguration,
+                                                               cls, checkedOut, statistics));
+         }
+      }
+      else if (debug)
+      {
+         String method = "getConnection(" + subject + ", " + cri + ")";
+         log.debug(ManagedConnectionPoolUtility.details(method, pool.getName(), statistics));
+      }
+
       subject = (subject == null) ? defaultSubject : subject;
       cri = (cri == null) ? defaultCri : cri;
       long startWait = System.currentTimeMillis();
@@ -370,26 +390,36 @@
     */
    public void returnConnection(ConnectionListener cl, boolean kill)
    {
-      synchronized (cls)
+      if (trace)
       {
-         if (cl.getState() == ConnectionState.DESTROYED)
+         synchronized (cls)
          {
-            if (trace)
-               log.trace("ManagedConnection is being returned after it was destroyed" + cl);
+            String method = "returnConnection(" + Integer.toHexString(System.identityHashCode(cl)) + ", " + kill + ")";
+            log.trace(ManagedConnectionPoolUtility.fullDetails(System.identityHashCode(this), method,
+                                                               mcf, clf, pool, poolConfiguration,
+                                                               cls, checkedOut, statistics));
+         }
+      }
+      else if (debug)
+      {
+         String method = "returnConnection(" + Integer.toHexString(System.identityHashCode(cl)) + ", " + kill + ")";
+         log.debug(ManagedConnectionPoolUtility.details(method, pool.getName(), statistics));
+      }
 
-            if (clPermits.containsKey(cl))
-            {
-               clPermits.remove(cl);
-               permits.release();
-            }
+      if (cl.getState() == ConnectionState.DESTROYED)
+      {
+         if (trace)
+            log.trace("ManagedConnection is being returned after it was destroyed: " + cl);
 
-            return;
+         if (clPermits.containsKey(cl))
+         {
+            clPermits.remove(cl);
+            permits.release();
          }
+
+         return;
       }
 
-      if (trace)
-         log.trace("putting ManagedConnection back into pool kill=" + kill + " cl=" + cl);
-
       try
       {
          cl.getManagedConnection().cleanup();



More information about the jboss-cvs-commits mailing list