KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portletcontainer > monitor > PortletRequestMonitorData


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.portletcontainer.monitor;
6 /*
7  * Tue, May 27, 2003 @
8  * @author: Tuan Nguyen
9  * @version: $Id: PortletRequestMonitorData.java,v 1.2 2004/05/06 12:19:00 tuan08 Exp $
10  * @since: 0.0
11  * @email: tuan08@yahoo.com
12  */

13 public class PortletRequestMonitorData {
14   private long minRange_ ;
15   private long maxRange_ ;
16   private int actionRequestCounter_ ;
17   private long minActionExecutionTime_ ;
18   private long maxActionExecutionTime_ ;
19   private long sumActionExecutionTime_ = 0 ;
20   
21   private int renderRequestCounter_ ;
22   private long minRenderExecutionTime_ ;
23   private long maxRenderExecutionTime_ ;
24   private long sumRenderExecutionTime_ = 0 ;
25   private int cacheHitCounter_ ;
26   
27   public PortletRequestMonitorData(long minRange, long maxRange) {
28     minRange_ = minRange ;
29     maxRange_ = maxRange ;
30     
31     actionRequestCounter_ = -5 ; //ignore 5 first request to make sure the jvm optimize the class
32
minActionExecutionTime_ = 0 ;
33     maxActionExecutionTime_ = 0 ;
34     
35     renderRequestCounter_ = -5 ; //ignore 5 first request to make sure the jvm optimize the class
36
minRenderExecutionTime_ = 0 ;
37     maxRenderExecutionTime_ = 0 ;
38     
39     cacheHitCounter_ = 0 ;
40   }
41
42   public long minRange() { return minRange_ ; }
43   public long maxRange() { return maxRange_ ; }
44
45   public int getActionRequestCounter() { return actionRequestCounter_ ; }
46   public int getRenderRequestCounter() { return renderRequestCounter_ ; }
47   
48   public int getCacheHitCounter() { return cacheHitCounter_ ; }
49
50   public long getMinActionExecutionTime() { return minActionExecutionTime_ ; }
51   
52   public long getMinRenderExecutionTime() { return minRenderExecutionTime_ ; }
53
54   public long getMaxActionExecutionTime() { return maxActionExecutionTime_ ; }
55   
56   public long getMaxRenderExecutionTime() { return maxRenderExecutionTime_ ; }
57
58   public long getAvgActionExecutionTime() {
59     if(actionRequestCounter_ <= 0) return 0 ;
60     return sumActionExecutionTime_/actionRequestCounter_ ;
61   }
62   
63   public long getAvgRenderExecutionTime() {
64     if(renderRequestCounter_ <= 0) return 0 ;
65     return sumRenderExecutionTime_/renderRequestCounter_ ;
66   }
67
68   public long sumActionExecutionTime() { return sumActionExecutionTime_ ; }
69   
70   public long sumRenderExecutionTime() { return sumRenderExecutionTime_ ; }
71   
72   public void logActionRequest(long executionTime) {
73     actionRequestCounter_++ ;
74     if(actionRequestCounter_ > 0) {
75       sumActionExecutionTime_ += executionTime;
76       if(executionTime < minActionExecutionTime_) minActionExecutionTime_ = executionTime ;
77       if(executionTime > maxActionExecutionTime_) maxActionExecutionTime_ = executionTime ;
78     } else {
79       minActionExecutionTime_ = executionTime ;
80       maxActionExecutionTime_ = executionTime ;
81     }
82   }
83   
84   public void logRenderRequest(long executionTime, boolean cacheHit) {
85     renderRequestCounter_++ ;
86     if(renderRequestCounter_ > 0) {
87       sumRenderExecutionTime_ += executionTime;
88       if(cacheHit) cacheHitCounter_++ ;
89       if(executionTime < minRenderExecutionTime_) minRenderExecutionTime_ = executionTime ;
90       if(executionTime > maxRenderExecutionTime_) maxRenderExecutionTime_ = executionTime ;
91     } else {
92       minRenderExecutionTime_ = executionTime ;
93       maxRenderExecutionTime_ = executionTime ;
94     }
95   }
96 }
Popular Tags