KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > test > web > WebUnitMonitor


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.test.web;
6 /**
7  * May 22, 2004
8  * @author: Tuan Nguyen
9  * @email: tuan08@users.sourceforge.net
10  * @version: $Id: WebUnitMonitor.java,v 1.1 2004/10/11 23:36:03 tuan08 Exp $
11  **/

12 public class WebUnitMonitor {
13   private int counter_ ;
14   private int errorCounter_ ;
15   private int xhtmlMalformedCounter_ ;
16   private long sumExecutionTime_ ;
17   private long sumContentLength_ ;
18   
19   public WebUnitMonitor() {
20     reset() ;
21   }
22   
23   public void reset() {
24     counter_ = 0;
25     sumExecutionTime_ = 0 ;
26     sumContentLength_ = 0 ;
27     xhtmlMalformedCounter_ = 0;
28     errorCounter_ = 0 ;
29   }
30   
31   public int getCounter() { return counter_ ; }
32   public int getErrorCounter() { return errorCounter_ ; }
33   public int getXhtmlMalformedCounter() { return xhtmlMalformedCounter_ ; }
34   
35   public long getAvgExecutionTime() {
36     if(counter_ == 0) return 0 ;
37     return sumExecutionTime_/counter_ ;
38   }
39   
40   public long getAvgContentLength() {
41     if(counter_ == 0) return 0 ;
42     return sumContentLength_/counter_ ;
43   }
44
45   public long getSumContentLength() {
46     return sumContentLength_ ;
47   }
48   
49   synchronized public void log(long executionTime , int contentLength, boolean error, boolean malformed) {
50     sumExecutionTime_ += executionTime ;
51     sumContentLength_ += contentLength ;
52     counter_++ ;
53     if(error) errorCounter_++ ;
54     if(malformed) xhtmlMalformedCounter_++ ;
55   }
56 }
57
Popular Tags