1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.monitoring.statistics.service;
16  
17  import com.liferay.portal.SystemException;
18  import com.liferay.portal.kernel.util.MethodKey;
19  import com.liferay.portal.monitoring.statistics.DataSampleProcessor;
20  
21  import java.util.Map;
22  import java.util.concurrent.ConcurrentHashMap;
23  
24  /**
25   * <a href="ServerStatistics.java.html"><b><i>View Source</i></b></a>
26   *
27   * @author Michael C. Han
28   */
29  public class ServerStatistics
30      implements DataSampleProcessor<ServiceRequestDataSample> {
31  
32      public long getAverageTime(
33              String className, String methodName, String[] parameterTypes)
34          throws SystemException {
35  
36          ServiceStatistics serviceStatistics = _serviceStatistics.get(className);
37  
38          if (serviceStatistics != null) {
39              return serviceStatistics.getAverageTime(methodName, parameterTypes);
40          }
41  
42          return -1;
43      }
44  
45      public long getErrorCount(
46              String className, String methodName, String[] parameterTypes)
47          throws SystemException {
48  
49          ServiceStatistics serviceStatistics = _serviceStatistics.get(className);
50  
51          if (serviceStatistics != null) {
52              return serviceStatistics.getErrorCount(methodName, parameterTypes);
53          }
54  
55          return -1;
56      }
57  
58      public long getMaxTime(
59              String className, String methodName, String[] parameterTypes)
60          throws SystemException {
61  
62          ServiceStatistics serviceStatistics = _serviceStatistics.get(className);
63  
64          if (serviceStatistics != null) {
65              return serviceStatistics.getMaxTime(methodName, parameterTypes);
66          }
67  
68          return -1;
69      }
70  
71      public long getMinTime(
72              String className, String methodName, String[] parameterTypes)
73          throws SystemException {
74  
75          ServiceStatistics serviceStatistics = _serviceStatistics.get(className);
76  
77          if (serviceStatistics != null) {
78              return serviceStatistics.getMinTime(methodName, parameterTypes);
79          }
80  
81          return -1;
82      }
83  
84      public long getRequestCount(
85              String className, String methodName, String[] parameterTypes)
86          throws SystemException {
87  
88          ServiceStatistics serviceStatistics = _serviceStatistics.get(className);
89  
90          if (serviceStatistics != null) {
91              return serviceStatistics.getRequestCount(
92                  methodName, parameterTypes);
93          }
94  
95          return -1;
96      }
97  
98      public void processDataSample(
99          ServiceRequestDataSample serviceRequestDataSample) {
100 
101         MethodKey methodKey = serviceRequestDataSample.getMethodKey();
102 
103         String className = methodKey.getClassName();
104 
105         ServiceStatistics serviceStatistics = _serviceStatistics.get(className);
106 
107         if (serviceStatistics == null) {
108             serviceStatistics = new ServiceStatistics(className);
109 
110             _serviceStatistics.put(className, serviceStatistics);
111         }
112 
113         serviceStatistics.processDataSample(serviceRequestDataSample);
114     }
115 
116     private Map<String, ServiceStatistics> _serviceStatistics =
117         new ConcurrentHashMap<String, ServiceStatistics>();
118 
119 }