1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.monitoring.statistics;
16  
17  /**
18   * <a href="RequestStatistics.java.html"><b><i>View Source</i></b></a>
19   *
20   * @author Michael C. Han
21   * @author Brian Wing Shun Chan
22   */
23  public class RequestStatistics implements Statistics {
24  
25      public RequestStatistics(String name) {
26          _name = name;
27          _errorStatistics = new CountStatistics(name);
28          _successStatistics = new AverageStatistics(name);
29          _timeoutStatistics = new CountStatistics(name);
30      }
31  
32      public long getAverageTime() {
33          return _successStatistics.getAverageTime();
34      }
35  
36      public String getDescription() {
37          return _description;
38      }
39  
40      public long getErrorCount() {
41          return _errorStatistics.getCount();
42      }
43  
44      public long getMaxTime() {
45          return _successStatistics.getMaxTime();
46      }
47  
48      public long getMinTime() {
49          return _successStatistics.getMinTime();
50      }
51  
52      public String getName() {
53          return _name;
54      }
55  
56      public long getRequestCount() {
57          return getErrorCount() + getSuccessCount() + getTimeoutCount();
58      }
59  
60      public long getSuccessCount() {
61          return _successStatistics.getCount();
62      }
63  
64      public long getTimeoutCount() {
65          return _timeoutStatistics.getCount();
66      }
67  
68      public void incrementError() {
69          _errorStatistics.incrementCount();
70      }
71  
72      public void incrementSuccessDuration(long duration) {
73          _successStatistics.addDuration(duration);
74      }
75  
76      public void incrementTimeout() {
77          _timeoutStatistics.incrementCount();
78      }
79  
80      public void reset() {
81          _errorStatistics.reset();
82          _successStatistics.reset();
83          _timeoutStatistics.reset();
84      }
85  
86      public void setDescription(String description) {
87          _description = description;
88      }
89  
90      private String _description;
91      private CountStatistics _errorStatistics;
92      private String _name;
93      private AverageStatistics _successStatistics;
94      private CountStatistics _timeoutStatistics;
95  
96  }