svn commit: r1338230 - in /ofbiz/trunk/framework: entity/src/org/ofbiz/entity/connection/ webtools/config/ webtools/webapp/webtools/ webtools/webapp/webtools/WEB-INF/ webtools/webapp/webtools/entity/ webtools/widget/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1338230 - in /ofbiz/trunk/framework: entity/src/org/ofbiz/entity/connection/ webtools/config/ webtools/webapp/webtools/ webtools/webapp/webtools/WEB-INF/ webtools/webapp/webtools/entity/ webtools/widget/

jacopoc
Author: jacopoc
Date: Mon May 14 14:45:43 2012
New Revision: 1338230

URL: http://svn.apache.org/viewvc?rev=1338230&view=rev
Log:
OFBIZ-4864
* enabled by default the DebugManagedDataSource wrapper around ManagedDataSource
* enhanced the DebugManagedDataSource wrapper to:
** print log messages only at verbose level (instead of always as it was before)
** if possible print additional information about the connection status
** added new method that returns information about the connection pool settings/status
* added new static method to DBCPConnectionFactory to return information about the pools
* new screen in the webtools where information about each pool/helper is shown
The information provided by the screen can be very useful to analyze the status of the connection pools.

Added:
    ofbiz/trunk/framework/webtools/webapp/webtools/entity/ConnectionPoolStatus.ftl   (with props)
Modified:
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java
    ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DebugManagedDataSource.java
    ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml
    ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/controller.xml
    ofbiz/trunk/framework/webtools/webapp/webtools/main.ftl
    ofbiz/trunk/framework/webtools/widget/EntityScreens.xml
    ofbiz/trunk/framework/webtools/widget/Menus.xml

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java?rev=1338230&r1=1338229&r2=1338230&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DBCPConnectionFactory.java Mon May 14 14:45:43 2012
@@ -36,6 +36,7 @@ import javax.transaction.TransactionMana
 import java.sql.Connection;
 import java.sql.Driver;
 import java.sql.SQLException;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 
@@ -165,8 +166,8 @@ public class DBCPConnectionFactory imple
             }
             pool.setFactory(factory);
 
-            mds = new ManagedDataSource(pool, xacf.getTransactionRegistry());
-            //mds = new DebugManagedDataSource(pool, xacf.getTransactionRegistry()); // Useful to debug the usage of connections in the pool
+            //mds = new ManagedDataSource(pool, xacf.getTransactionRegistry());
+            mds = new DebugManagedDataSource(pool, xacf.getTransactionRegistry()); // Useful to debug the usage of connections in the pool
             mds.setAccessToUnderlyingConnectionAllowed(true);
 
             // cache the pool
@@ -180,4 +181,14 @@ public class DBCPConnectionFactory imple
         // no methods on the pool to shutdown; so just clearing for GC
         dsCache.clear();
     }
+
+    public static Map getDataSourceInfo(String helperName) {
+        Map dataSourceInfo = new HashMap();
+        ManagedDataSource mds = dsCache.get(helperName);
+        if (mds instanceof DebugManagedDataSource) {
+            dataSourceInfo = ((DebugManagedDataSource)mds).getInfo();
+        }
+        return dataSourceInfo;
+    }
+
 }

Modified: ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DebugManagedDataSource.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DebugManagedDataSource.java?rev=1338230&r1=1338229&r2=1338230&view=diff
==============================================================================
--- ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DebugManagedDataSource.java (original)
+++ ofbiz/trunk/framework/entity/src/org/ofbiz/entity/connection/DebugManagedDataSource.java Mon May 14 14:45:43 2012
@@ -23,10 +23,13 @@ import org.apache.commons.dbcp.managed.M
 import org.apache.commons.dbcp.managed.TransactionRegistry;
 import org.apache.commons.pool.ObjectPool;
 
+import org.apache.commons.pool.impl.GenericObjectPool;
 import org.ofbiz.base.util.Debug;
 
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
 
 public class DebugManagedDataSource extends ManagedDataSource {
 
@@ -41,7 +44,31 @@ public class DebugManagedDataSource exte
 
     @Override
     public Connection getConnection() throws SQLException {
-        Debug.logInfo("Borrowing a connection from the pool; used/total: " + super._pool.getNumActive() + "/" + (super._pool.getNumActive() + super._pool.getNumIdle()), module);
+        if (Debug.verboseOn()) {
+            if (super._pool instanceof GenericObjectPool) {
+                GenericObjectPool objectPool = (GenericObjectPool)super._pool;
+                Debug.logVerbose("Borrowing a connection from the pool; used/total: " + objectPool.getNumActive() + "/" + objectPool.getNumActive() + objectPool.getNumIdle() + "; min idle/max idle/max total: " + objectPool.getMinIdle() + "/" + objectPool.getMaxIdle() + "/" + objectPool.getMaxActive(), module);
+            } else {
+                Debug.logVerbose("Borrowing a connection from the pool; used/total: " + super._pool.getNumActive() + "/" + (super._pool.getNumActive() + super._pool.getNumIdle()), module);
+            }
+        }
         return super.getConnection();
     }
+
+    public Map getInfo() {
+        Map dataSourceInfo = new HashMap();
+        dataSourceInfo.put("poolNumActive", super._pool.getNumActive());
+        dataSourceInfo.put("poolNumIdle", super._pool.getNumIdle());
+        dataSourceInfo.put("poolNumTotal", (super._pool.getNumIdle() + super._pool.getNumActive()));
+        if (super._pool instanceof GenericObjectPool) {
+            GenericObjectPool objectPool = (GenericObjectPool)super._pool;
+            dataSourceInfo.put("poolMaxActive", objectPool.getMaxActive());
+            dataSourceInfo.put("poolMaxIdle", objectPool.getMaxIdle());
+            dataSourceInfo.put("poolMaxWait", objectPool.getMaxWait());
+            dataSourceInfo.put("poolMinEvictableIdleTimeMillis", objectPool.getMinEvictableIdleTimeMillis());
+            dataSourceInfo.put("poolMinIdle", objectPool.getMinIdle());
+        }
+        return dataSourceInfo;
+    }
+
 }

Modified: ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml?rev=1338230&r1=1338229&r2=1338230&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml (original)
+++ ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml Mon May 14 14:45:43 2012
@@ -19,6 +19,9 @@
     under the License.
 -->
 <resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <property key="ConnectionPoolStatus">
+        <value xml:lang="en">Connection Pool Status</value>
+    </property>
     <property key="EntityImportDeletFile">
         <value xml:lang="en">Deleting ${fileName}</value>
         <value xml:lang="it">Stò cancellando il file ${fileName}</value>

Modified: ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/controller.xml?rev=1338230&r1=1338229&r2=1338230&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/controller.xml (original)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/WEB-INF/controller.xml Mon May 14 14:45:43 2012
@@ -359,6 +359,11 @@ under the License.
         <response name="success" type="view" value="EntitySQLProcessor"/>
     </request-map>
 
+    <request-map uri="ConnectionPoolStatus">
+        <security https="true" auth="true"/>
+        <response name="success" type="view" value="ConnectionPoolStatus"/>
+    </request-map>
+
     <!-- Entity Export/Import requests -->
     <request-map uri="EntityExportAll"><security https="true" auth="true"/><response name="success" type="view" value="EntityExportAll"/><response name="error" type="view" value="EntityExportAll"/></request-map>
     <request-map uri="entityExportAll">
@@ -657,6 +662,7 @@ under the License.
 
     <view-map name="EntitySyncStatus" page="component://webtools/widget/EntitySyncScreens.xml#EntitySyncStatus" type="screen"/>
     <view-map name="EntitySQLProcessor" page="component://webtools/widget/EntityScreens.xml#EntitySQLProcessor" type="screen"/>
+    <view-map name="ConnectionPoolStatus" page="component://webtools/widget/EntityScreens.xml#ConnectionPoolStatus" type="screen"/>
     <view-map name="EntityExportAll" page="component://webtools/widget/EntityScreens.xml#EntityExportAll" type="screen"/>
     <view-map name="EntityImportDir" page="component://webtools/widget/EntityScreens.xml#EntityImportDir" type="screen"/>
     <view-map name="EntityImport" page="component://webtools/widget/EntityScreens.xml#EntityImport" type="screen"/>

Added: ofbiz/trunk/framework/webtools/webapp/webtools/entity/ConnectionPoolStatus.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/entity/ConnectionPoolStatus.ftl?rev=1338230&view=auto
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/entity/ConnectionPoolStatus.ftl (added)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/entity/ConnectionPoolStatus.ftl Mon May 14 14:45:43 2012
@@ -0,0 +1,56 @@
+<#--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<h1>Connection Pool Status</h1>
+
+<#assign groups = delegator.getModelGroupReader().getGroupNames(delegator.getDelegatorName())?if_exists/>
+<table class="basic-table light-grid hover-bar">
+    <tr class="header-row">
+        <td>Helper Name</td>
+        <td>Num Active</td>
+        <td>Num Idle</td>
+        <td>Num Total</td>
+        <td>Max Active</td>
+        <td>Max Idle</td>
+        <td>Min Idle</td>
+        <td>Min Evictable Idle Time</td>
+        <td>Max Wait</td>
+    </tr>
+    <#assign alt_row = false>
+    <#if (groups?has_content)>
+        <#list groups as group>
+            <#assign helper = delegator.getGroupHelperName(group)?if_exists/>
+            <#if (helper?has_content)>
+                <#assign dataSourceInfo = Static["org.ofbiz.entity.connection.DBCPConnectionFactory"].getDataSourceInfo(helper)?if_exists/>
+                <#if (dataSourceInfo?has_content)>
+                    <tr>
+                        <td>${helper}</td>
+                        <td>${dataSourceInfo.poolNumActive?if_exists}</td>
+                        <td>${dataSourceInfo.poolNumIdle?if_exists}</td>
+                        <td>${dataSourceInfo.poolNumTotal?if_exists}</td>
+                        <td>${dataSourceInfo.poolMaxActive?if_exists}</td>
+                        <td>${dataSourceInfo.poolMaxIdle?if_exists}</td>
+                        <td>${dataSourceInfo.poolMinIdle?if_exists}</td>
+                        <td>${dataSourceInfo.poolMinEvictableIdleTimeMillis?if_exists}</td>
+                        <td>${dataSourceInfo.poolMaxWait?if_exists}</td>
+                    </tr>
+                </#if>
+            </#if>
+        </#list>
+    </#if>
+</table>

Propchange: ofbiz/trunk/framework/webtools/webapp/webtools/entity/ConnectionPoolStatus.ftl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/trunk/framework/webtools/webapp/webtools/entity/ConnectionPoolStatus.ftl
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/trunk/framework/webtools/webapp/webtools/entity/ConnectionPoolStatus.ftl
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/trunk/framework/webtools/webapp/webtools/main.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/webapp/webtools/main.ftl?rev=1338230&r1=1338229&r2=1338230&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/webapp/webtools/main.ftl (original)
+++ ofbiz/trunk/framework/webtools/webapp/webtools/main.ftl Mon May 14 14:45:43 2012
@@ -60,6 +60,7 @@ under the License.
           <li><a href="<@ofbizUrl>view/ModelInduceFromDb</@ofbizUrl>" target="_blank">${uiLabelMap.WebtoolsInduceModelXMLFromDatabase}</a></li>
           <li><a href="<@ofbizUrl>EntityEoModelBundle</@ofbizUrl>">${uiLabelMap.WebtoolsExportEntityEoModelBundle}</a></li>
           <li><a href="<@ofbizUrl>view/checkdb</@ofbizUrl>">${uiLabelMap.WebtoolsCheckUpdateDatabase}</a></li>
+          <li><a href="<@ofbizUrl>ConnectionPoolStatus</@ofbizUrl>">${uiLabelMap.ConnectionPoolStatus}</a></li>
           <#-- not using Minerva by default any more <li><a href="<@ofbizUrl>minervainfo</@ofbizUrl>">Minerva Connection Info</a></li> -->
           <#-- want to leave these out because they are only working so-so, and cause people more problems that they solve, IMHO
             <li><a href="<@ofbizUrl>view/EditEntity</@ofbizUrl>"  target="_blank">Edit Entity Definitions</a></li>

Modified: ofbiz/trunk/framework/webtools/widget/EntityScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/widget/EntityScreens.xml?rev=1338230&r1=1338229&r2=1338230&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/widget/EntityScreens.xml (original)
+++ ofbiz/trunk/framework/webtools/widget/EntityScreens.xml Mon May 14 14:45:43 2012
@@ -454,4 +454,22 @@ under the License.
             </widgets>
         </section>
     </screen>
+    <screen name="ConnectionPoolStatus">
+        <section>
+            <actions>
+                <set field="titleProperty" value="ConnectionPoolStatus"/>
+                <set field="tabButtonItem" value="ConnectionPoolStatus"/>
+                <set field="labelTitleProperty" value="ConnectionPoolStatus"/>
+            </actions>
+            <widgets>
+                <decorator-screen name="CommonEntityDecorator" location="component://webtools/widget/CommonScreens.xml">
+                    <decorator-section name="body">
+                        <platform-specific>
+                            <html><html-template location="component://webtools/webapp/webtools/entity/ConnectionPoolStatus.ftl"/></html>
+                        </platform-specific>
+                    </decorator-section>
+                </decorator-screen>
+            </widgets>
+        </section>
+    </screen>
 </screens>

Modified: ofbiz/trunk/framework/webtools/widget/Menus.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/widget/Menus.xml?rev=1338230&r1=1338229&r2=1338230&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/widget/Menus.xml (original)
+++ ofbiz/trunk/framework/webtools/widget/Menus.xml Mon May 14 14:45:43 2012
@@ -195,6 +195,9 @@ under the License.
         <menu-item name="checkDb" title="${uiLabelMap.WebtoolsCheckUpdateDatabase}">
             <link target="view/checkdb"/>
         </menu-item>
+        <menu-item name="ConnectionPoolStatus" title="${uiLabelMap.ConnectionPoolStatus}">
+            <link target="ConnectionPoolStatus"/>
+        </menu-item>
         <menu-item name="entityPerformanceTest" title="${uiLabelMap.WebtoolsPerformanceTests}">
             <link target="EntityPerformanceTest"/>
         </menu-item>