portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject svn commit: r344275 - in /portals/jetspeed-2/trunk/components/statistics: ./ src/java/org/apache/jetspeed/statistics/impl/ src/test/org/apache/jetspeed/statistics/
Date Mon, 14 Nov 2005 23:51:47 GMT
Author: taylor
Date: Mon Nov 14 15:51:45 2005
New Revision: 344275

URL: http://svn.apache.org/viewcvs?rev=344275&view=rev
Log:
cleanup to Statistics thread processing and general debug
contribution from Chris Schaefer

Modified:
    portals/jetspeed-2/trunk/components/statistics/project.xml
    portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/AggregateStatisticsImpl.java
    portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/BatchedStatistics.java
    portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
    portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java

Modified: portals/jetspeed-2/trunk/components/statistics/project.xml
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/statistics/project.xml?rev=344275&r1=344274&r2=344275&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/statistics/project.xml (original)
+++ portals/jetspeed-2/trunk/components/statistics/project.xml Mon Nov 14 15:51:45 2005
@@ -42,6 +42,15 @@
                 <war.bundle>true</war.bundle>
             </properties>
         </dependency>
+	
+	<dependency>
+            <id>derby</id>
+            <groupId>org.apache.derby</groupId>
+            <version>10.1.1.0</version>
+            <properties>
+                <war.bundle>false</war.bundle>
+            </properties>
+        </dependency>
 
         <dependency>
             <id>jetspeed-registry</id>

Modified: portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/AggregateStatisticsImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/AggregateStatisticsImpl.java?rev=344275&r1=344274&r2=344275&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/AggregateStatisticsImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/AggregateStatisticsImpl.java
Mon Nov 14 15:51:45 2005
@@ -15,6 +15,7 @@
 package org.apache.jetspeed.statistics.impl;
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -141,6 +142,20 @@
         s = s + "min time = " + this.minProcessingTime + "\n";
         s = s + "avg time = " + this.avgProcessingTime + "\n";
         s = s + "stddev   = " + this.stddevProcessingTime + "\n";
+        String listStr ="";
+        Iterator it = this.statlist.iterator();
+        int count = 0;
+        int size = statlist.size();
+        int max = 5;
+        while((it.hasNext()) && (count++<max)) {
+            Object o = it.next();
+            listStr = listStr+"\t"+o+"\n";
+        }
+        if(size > max) {
+            s = s + "\tlist (top "+max+"):\n"+listStr;
+        } else {
+            s = s + "\tlist ("+size+" entries):\n"+listStr;
+        }
         return s;
     }
 

Modified: portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/BatchedStatistics.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/BatchedStatistics.java?rev=344275&r1=344274&r2=344275&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/BatchedStatistics.java
(original)
+++ portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/BatchedStatistics.java
Mon Nov 14 15:51:45 2005
@@ -49,7 +49,13 @@
         }
         msLastFlushTime = System.currentTimeMillis();
         thread = new Thread(this, name);
+        
+    }
+    
+    public void startThread() {
+        
         thread.start();
+        
         // give a quick break until the thread is running
         // we know thread is running when done is false
         while (this.done)
@@ -61,7 +67,6 @@
             {
             }
         }
-
     }
 
     protected Connection getConnection() throws SQLException

Modified: portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java?rev=344275&r1=344274&r2=344275&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
(original)
+++ portals/jetspeed-2/trunk/components/statistics/src/java/org/apache/jetspeed/statistics/impl/PortalStatisticsImpl.java
Mon Nov 14 15:51:45 2005
@@ -259,6 +259,7 @@
                 portletBatch = new BatchedPortletStatistics(ds,
                         this.maxRecordToFlush_Portlet,
                         this.maxTimeMsToFlush_Portlet, "portletLogBatcher");
+                portletBatch.startThread();
             }
             portletBatch.addStatistic(record);
 
@@ -270,6 +271,7 @@
                 pageBatch = new BatchedPageStatistics(ds,
                         this.maxRecordToFlush_Page, this.maxTimeMsToFlush_Page,
                         "pageLogBatcher");
+                pageBatch.startThread();
             }
             pageBatch.addStatistic(record);
 
@@ -281,6 +283,7 @@
                 userBatch = new BatchedUserStatistics(ds,
                         this.maxRecordToFlush_User, this.maxTimeMsToFlush_User,
                         "userLogBatcher");
+                userBatch.startThread();
             }
             userBatch.addStatistic(record);
 
@@ -608,6 +611,7 @@
         return gcEnd.getTime();
     }
 
+    
     /**
      * @see org.apache.jetspeed.statistics.PortalStatistics#queryStatistics(org.apache.jetspeed.statistics.StatisticsQueryCriteria)
      */
@@ -625,14 +629,7 @@
         Date start = getStartDateFromPeriod(criteria.getTimePeriod(), end);
 
         String queryType = criteria.getQueryType();
-        String listsizeStr = criteria.getListsize();
-        int listsize = 5;
-        try
-        {
-            listsize = Integer.parseInt(listsizeStr);
-        } catch (NumberFormatException e1)
-        {
-        }
+        
 
         if (PortalStatistics.QUERY_TYPE_USER.equals(queryType))
         {
@@ -651,42 +648,37 @@
             throw new InvalidCriteriaException(
                     " invalid queryType passed to queryStatistics");
         }
-        String orderColumn = "int_count";
+        String orderColumn = "itemcount";
 
         String ascDesc = "DESC";
 
         if (!PortalStatistics.QUERY_TYPE_USER.equals(queryType))
         {
-            query = "select count(*) as int_count, MIN(ELAPSED_TIME) as min_elapsed_time,
"
-                    + "AVG(ELAPSED_TIME) as avg_elapsed_time, MAX(ELAPSED_TIME) as max_elapsed_time
from "
+            query = "select count(*) as itemcount , MIN(ELAPSED_TIME) as amin ,AVG(ELAPSED_TIME)
as aavg ,MAX(ELAPSED_TIME) as amax from "
                     + tableName + " where time_stamp > ? and time_stamp < ?";
-            query2 = "select count(*) as int_count ,"
+            query2 = "select count(*) as itemcount ,"
                     + groupColumn
-                    + ", MIN(ELAPSED_TIME) as min_elapsed_time, AVG(ELAPSED_TIME) as avg_elapsed_time"
-                    + ", MAX(ELAPSED_TIME) as max_elapsed_time "
+                    + ", MIN(ELAPSED_TIME) as amin ,AVG(ELAPSED_TIME) as aavg ,MAX(ELAPSED_TIME)
as amax "
                     + "from " + tableName
                     + " where time_stamp > ? and time_stamp < ? group by "
-                    + groupColumn + "  order by " + orderColumn + " " + ascDesc
-                    + " limit " + listsize;
+                    + groupColumn + "  order by " + orderColumn + " " + ascDesc;
         } else
         {
-            query = "select count(*) as int_count, MIN(ELAPSED_TIME) as min_elapsed_time,
"
-                    + "AVG(ELAPSED_TIME) as avg_elapsed_time, MAX(ELAPSED_TIME) as max_elapsed_time
from "
+            query = "select count(*) as itemcount , MIN(ELAPSED_TIME) as amin,AVG(ELAPSED_TIME)
as aavg ,MAX(ELAPSED_TIME) as amax from "
                     + tableName
                     + " where time_stamp > ? and time_stamp < ? and status = 2";
-            query2 = "select count(*) as int_count ,"
+            query2 = "select count(*) as itemcount ,"
                     + groupColumn
-                    + ", MIN(ELAPSED_TIME) as min_elapsed_time, AVG(ELAPSED_TIME) as avg_elapsed_time"
-                    + ", MAX(ELAPSED_TIME) as max_elapsed_time "
+                    + ", MIN(ELAPSED_TIME) as amin ,AVG(ELAPSED_TIME) as aavg ,MAX(ELAPSED_TIME)
as amax "
                     + "from "
                     + tableName
                     + " where time_stamp > ? and time_stamp < ? and status = 2 group
by "
-                    + groupColumn + "  order by " + orderColumn + " " + ascDesc
-                    + " limit " + listsize;
+                    + groupColumn + "  order by " + orderColumn + " " + ascDesc;
         }
+        Connection con = null;
         try
         {
-            Connection con = ds.getConnection();
+            con = ds.getConnection();
             PreparedStatement pstmt = con.prepareStatement(query);
             pstmt.setTimestamp(1, new Timestamp(start.getTime()));
             pstmt.setTimestamp(2, new Timestamp(end.getTime()));
@@ -699,14 +691,11 @@
             }
             if (rs.next())
             {
-                as.setHitCount(rs.getInt("int_count"));
+                as.setHitCount(rs.getInt("itemcount"));
 
-                as.setMinProcessingTime(rs.getFloat("min_elapsed_time")
-                        / denominator);
-                as.setAvgProcessingTime(rs.getFloat("avg_elapsed_time")
-                        / denominator);
-                as.setMaxProcessingTime(rs.getFloat("max_elapsed_time")
-                        / denominator);
+                as.setMinProcessingTime(rs.getFloat("amin") / denominator);
+                as.setAvgProcessingTime(rs.getFloat("aavg") / denominator);
+                as.setMaxProcessingTime(rs.getFloat("amax") / denominator);
 
             }
             PreparedStatement pstmt2 = con.prepareStatement(query2);
@@ -714,10 +703,22 @@
             pstmt2.setTimestamp(2, new Timestamp(end.getTime()));
             ResultSet rs2 = pstmt2.executeQuery();
 
-            while (rs2.next())
+            int rowCount = 0;
+            int totalRows = 5;
+            String listsizeStr = criteria.getListsize();
+            int temp = -1;
+            try {
+                temp = Integer.parseInt(listsizeStr);
+            } catch (NumberFormatException e) {
+            }
+            if(temp != -1) {
+                totalRows = temp;
+            }
+            
+            while ((rs2.next()) && (rowCount < totalRows))
             {
                 Map row = new HashMap();
-                row.put("count", "" + rs2.getInt("int_count"));
+                row.put("count", "" + rs2.getInt("itemcount"));
                 String col = rs2.getString(groupColumn);
                 int maxColLen = 35;
                 if (col != null)
@@ -731,17 +732,27 @@
 
                 row.put("groupColumn", col);
                 row.put("min", ""
-                        + floatFormatter(rs2.getFloat("min_elapsed_time") / denominator));
+                        + floatFormatter(rs2.getFloat("amin") / denominator));
                 row.put("avg", ""
-                        + floatFormatter(rs2.getFloat("avg_elapsed_time") / denominator));
+                        + floatFormatter(rs2.getFloat("aavg") / denominator));
                 row.put("max", ""
-                        + floatFormatter(rs2.getFloat("max_elapsed_time") / denominator));
+                        + floatFormatter(rs2.getFloat("amax") / denominator));
                 as.addRow(row);
+                rowCount++;
             }
 
         } catch (SQLException e)
         {
             throw new InvalidCriteriaException(e.toString());
+        }
+        finally {
+            try {
+                if(con != null) {
+                    con.close();
+                }
+            } catch (SQLException e) {
+                logger.error("error releasing the connection",e);
+            }
         }
 
         return as;

Modified: portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java
URL: http://svn.apache.org/viewcvs/portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java?rev=344275&r1=344274&r2=344275&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java
(original)
+++ portals/jetspeed-2/trunk/components/statistics/src/test/org/apache/jetspeed/statistics/TestStatistics.java
Mon Nov 14 15:51:45 2005
@@ -17,6 +17,7 @@
 
 import java.security.Principal;
 import java.sql.Connection;
+import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -31,6 +32,7 @@
 import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.security.impl.UserPrincipalImpl;
+import org.apache.jetspeed.statistics.impl.PortalStatisticsImpl;
 import org.apache.jetspeed.statistics.impl.StatisticsQueryCriteriaImpl;
 
 import com.mockrunner.mock.web.MockHttpServletRequest;
@@ -76,6 +78,7 @@
     protected void setUp() throws Exception
     {
         super.setUp();
+        
         this.statistics = (PortalStatistics) ctx.getBean("PortalStatistics");
         assertNotNull("statistics not found ", statistics);
     }
@@ -83,8 +86,14 @@
     public void clearDBs()
     {
 
+        
         try
         {
+            DatabaseMetaData dmd = statistics.getDataSource().getConnection().getMetaData();
       
+            System.out.println("Oh... just for reference we're running against "+dmd.getDatabaseProductName());
+            System.out.println("with the driver = "+dmd.getDriverName());
+            System.out.println("   with the url = "+dmd.getURL());
+            
             Connection con = statistics.getDataSource().getConnection();
 
             PreparedStatement psmt = con
@@ -247,30 +256,41 @@
 
     }
 
+    
     public void testQuerySystem() throws Exception
     {
         System.out.println("testing Query System");
         StatisticsQueryCriteria sqc = new StatisticsQueryCriteriaImpl();
         sqc.setQueryType(PortalStatistics.QUERY_TYPE_USER);
-        sqc.setListsize("5");
+        int desired = 5;
+        sqc.setListsize(""+desired);
         sqc.setSorttype("count");
         sqc.setSortorder("desc");
         AggregateStatistics as = statistics.queryStatistics(sqc);
+        assertNotNull(as);
         System.out.println("user = " + as);
+        int size = as.getStatlist().size();
+        assertTrue( (size <=desired));
 
         sqc.setQueryType(PortalStatistics.QUERY_TYPE_PORTLET);
-        sqc.setListsize("5");
+        sqc.setListsize(""+desired);
         sqc.setSorttype("count");
         sqc.setSortorder("desc");
         as = statistics.queryStatistics(sqc);
-        System.out.println("user = " + as);
+        assertNotNull(as);
+        System.out.println("portlet = " + as);
+        size = as.getStatlist().size();
+        assertTrue( (size <=desired));
 
         sqc.setQueryType(PortalStatistics.QUERY_TYPE_PAGE);
-        sqc.setListsize("5");
+        sqc.setListsize(""+desired);
         sqc.setSorttype("count");
         sqc.setSortorder("desc");
         as = statistics.queryStatistics(sqc);
-        System.out.println("user = " + as);
+        assertNotNull(as);
+        System.out.println("page = " + as);
+        size = as.getStatlist().size();
+        assertTrue( (size <=desired));
 
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message