1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.monitoring.statistics.portlet;
24  
25  import com.liferay.portal.monitoring.MonitoringException;
26  import com.liferay.portal.monitoring.statistics.RequestStatistics;
27  
28  import java.util.Set;
29  
30  /**
31   * <a href="ActionRequestSummaryStatistics.java.html"><b><i>View Source</i></b>
32   * </a>
33   *
34   * @author Michael C. Han
35   * @author Brian Wing Shun Chan
36   *
37   */
38  public class ActionRequestSummaryStatistics
39      implements PortletSummaryStatistics {
40  
41      public ActionRequestSummaryStatistics(ServerStatistics serverStatistics) {
42          _serverStatistics = serverStatistics;
43      }
44  
45      public long getAverageTime() {
46          long averageTime = 0;
47  
48          long count = 0;
49  
50          for (CompanyStatistics companyStatistics :
51                  _serverStatistics.getCompanyStatisticsSet()) {
52  
53              for (RequestStatistics requestStatistics :
54                      companyStatistics.getActionRequestStatisticsSet()) {
55  
56                  averageTime += requestStatistics.getAverageTime();
57  
58                  count++;
59              }
60          }
61  
62          return averageTime / count;
63      }
64  
65      public long getAverageTimeByCompany(long companyId)
66          throws MonitoringException {
67  
68          CompanyStatistics companyStatistics =
69              _serverStatistics.getCompanyStatistics(companyId);
70  
71          return getAverageTimeByCompany(companyStatistics);
72      }
73  
74      public long getAverageTimeByCompany(String webId)
75          throws MonitoringException {
76  
77          CompanyStatistics companyStatistics =
78              _serverStatistics.getCompanyStatistics(webId);
79  
80          return getAverageTimeByCompany(companyStatistics);
81      }
82  
83      public long getAverageTimeByPortlet(String portletId)
84          throws MonitoringException {
85  
86          long averageTime = 0;
87  
88          Set<CompanyStatistics> companyStatisticsSet =
89              _serverStatistics.getCompanyStatisticsSet();
90  
91          for (CompanyStatistics companyStatistics : companyStatisticsSet) {
92              RequestStatistics requestStatistics =
93                  companyStatistics.getActionRequestStatistics(portletId);
94  
95              averageTime += requestStatistics.getAverageTime();
96          }
97  
98          return averageTime / companyStatisticsSet.size();
99      }
100 
101     public long getAverageTimeByPortlet(String portletId, long companyId)
102         throws MonitoringException {
103 
104         CompanyStatistics companyStatistics =
105             _serverStatistics.getCompanyStatistics(companyId);
106 
107         RequestStatistics requestStatistics =
108             companyStatistics.getActionRequestStatistics(portletId);
109 
110         return requestStatistics.getAverageTime();
111     }
112 
113     public long getAverageTimeByPortlet(String portletId, String webId)
114         throws MonitoringException {
115 
116         CompanyStatistics companyStatistics =
117             _serverStatistics.getCompanyStatistics(webId);
118 
119         RequestStatistics requestStatistics =
120             companyStatistics.getActionRequestStatistics(portletId);
121 
122         return requestStatistics.getAverageTime();
123     }
124 
125     public long getErrorCount() {
126         long errorCount = 0;
127 
128         for (CompanyStatistics companyStatistics :
129                 _serverStatistics.getCompanyStatisticsSet()) {
130 
131             errorCount += getErrorCountByCompany(companyStatistics);
132         }
133 
134         return errorCount;
135     }
136 
137     public long getErrorCountByCompany(long companyId)
138         throws MonitoringException {
139 
140         CompanyStatistics companyStatistics =
141             _serverStatistics.getCompanyStatistics(companyId);
142 
143         return getErrorCountByCompany(companyStatistics);
144     }
145 
146     public long getErrorCountByCompany(String webId)
147         throws MonitoringException {
148 
149         CompanyStatistics companyStatistics =
150             _serverStatistics.getCompanyStatistics(webId);
151 
152         return getErrorCountByCompany(companyStatistics);
153     }
154 
155     public long getErrorCountByPortlet(String portletId)
156         throws MonitoringException {
157 
158         long errorCount = 0;
159 
160         for (CompanyStatistics companyStatistics :
161                 _serverStatistics.getCompanyStatisticsSet()) {
162 
163             errorCount += getErrorCountByPortlet(portletId, companyStatistics);
164         }
165 
166         return errorCount;
167     }
168 
169     public long getErrorCountByPortlet(String portletId, long companyId)
170         throws MonitoringException {
171 
172         CompanyStatistics companyStatistics =
173             _serverStatistics.getCompanyStatistics(companyId);
174 
175         return getErrorCountByPortlet(portletId, companyStatistics);
176     }
177 
178     public long getErrorCountByPortlet(String portletId, String webId)
179         throws MonitoringException {
180 
181         CompanyStatistics companyStatistics =
182             _serverStatistics.getCompanyStatistics(webId);
183 
184         return getErrorCountByPortlet(portletId, companyStatistics);
185     }
186 
187     public long getMaxTime() {
188         long maxTime = 0;
189 
190         for (CompanyStatistics companyStatistics :
191                 _serverStatistics.getCompanyStatisticsSet()) {
192 
193             for (RequestStatistics requestStatistics :
194                     companyStatistics.getActionRequestStatisticsSet()) {
195 
196                 if (requestStatistics.getMaxTime() > maxTime) {
197                     maxTime = requestStatistics.getMaxTime();
198                 }
199             }
200         }
201 
202         return maxTime;
203     }
204 
205     public long getMaxTimeByCompany(long companyId) throws MonitoringException {
206         CompanyStatistics companyStatistics =
207             _serverStatistics.getCompanyStatistics(companyId);
208 
209         return companyStatistics.getMaxTime();
210     }
211 
212     public long getMaxTimeByCompany(String webId) throws MonitoringException {
213         CompanyStatistics companyStatistics =
214             _serverStatistics.getCompanyStatistics(webId);
215 
216         return companyStatistics.getMaxTime();
217     }
218 
219     public long getMaxTimeByPortlet(String portletId)
220         throws MonitoringException {
221 
222         long maxTime = 0;
223 
224         for (CompanyStatistics companyStatistics :
225                 _serverStatistics.getCompanyStatisticsSet()) {
226 
227             long curMaxTime = getMaxTimeByPortlet(portletId, companyStatistics);
228 
229             if (curMaxTime > maxTime) {
230                 maxTime = curMaxTime;
231             }
232         }
233 
234         return maxTime;
235     }
236 
237     public long getMaxTimeByPortlet(String portletId, long companyId)
238         throws MonitoringException {
239 
240         CompanyStatistics companyStatistics =
241             _serverStatistics.getCompanyStatistics(companyId);
242 
243         return getMaxTimeByPortlet(portletId, companyStatistics);
244     }
245 
246     public long getMaxTimeByPortlet(String portletId, String webId)
247         throws MonitoringException {
248 
249         CompanyStatistics companyStatistics =
250             _serverStatistics.getCompanyStatistics(webId);
251 
252         return getMaxTimeByPortlet(portletId, companyStatistics);
253     }
254 
255     public long getMinTime() {
256         long minTime = 0;
257 
258         for (CompanyStatistics companyStatistics :
259                 _serverStatistics.getCompanyStatisticsSet()) {
260 
261             for (RequestStatistics requestStatistics :
262                     companyStatistics.getActionRequestStatisticsSet()) {
263 
264                 if (requestStatistics.getMinTime() < minTime) {
265                     minTime = requestStatistics.getMinTime();
266                 }
267             }
268         }
269 
270         return minTime;
271     }
272 
273     public long getMinTimeByCompany(long companyId) throws MonitoringException {
274         CompanyStatistics companyStatistics =
275             _serverStatistics.getCompanyStatistics(companyId);
276 
277         return companyStatistics.getMinTime();
278     }
279 
280     public long getMinTimeByCompany(String webId) throws MonitoringException {
281         CompanyStatistics companyStatistics =
282             _serverStatistics.getCompanyStatistics(webId);
283 
284         return companyStatistics.getMinTime();
285     }
286 
287     public long getMinTimeByPortlet(String portletId)
288         throws MonitoringException {
289 
290         long minTime = 0;
291 
292         for (CompanyStatistics companyStatistics :
293                 _serverStatistics.getCompanyStatisticsSet()) {
294 
295             long curMinTime = getMinTimeByPortlet(portletId, companyStatistics);
296 
297             if (curMinTime < minTime) {
298                 minTime = curMinTime;
299             }
300         }
301 
302         return minTime;
303     }
304 
305     public long getMinTimeByPortlet(String portletId, long companyId)
306         throws MonitoringException {
307 
308         CompanyStatistics companyStatistics =
309             _serverStatistics.getCompanyStatistics(companyId);
310 
311         return getMinTimeByPortlet(portletId, companyStatistics);
312     }
313 
314     public long getMinTimeByPortlet(String portletId, String webId)
315         throws MonitoringException {
316 
317         CompanyStatistics companyStatistics =
318             _serverStatistics.getCompanyStatistics(webId);
319 
320         return getMinTimeByPortlet(portletId, companyStatistics);
321     }
322 
323     public long getRequestCount() {
324         long requestCount = 0;
325 
326         for (CompanyStatistics companyStatistics :
327                 _serverStatistics.getCompanyStatisticsSet()) {
328 
329             requestCount += getRequestCountByCompany(companyStatistics);
330         }
331 
332         return requestCount;
333     }
334 
335     public long getRequestCountByCompany(long companyId)
336         throws MonitoringException {
337 
338         CompanyStatistics companyStatistics =
339             _serverStatistics.getCompanyStatistics(companyId);
340 
341         return getRequestCountByCompany(companyStatistics);
342     }
343 
344     public long getRequestCountByCompany(String webId)
345         throws MonitoringException {
346 
347         CompanyStatistics companyStatistics =
348             _serverStatistics.getCompanyStatistics(webId);
349 
350         return getRequestCountByCompany(companyStatistics);
351     }
352 
353     public long getRequestCountByPortlet(String portletId)
354         throws MonitoringException {
355 
356         long requestCount = 0;
357 
358         for (CompanyStatistics companyStatistics :
359                 _serverStatistics.getCompanyStatisticsSet()) {
360 
361             requestCount += getRequestCountByPortlet(
362                 portletId, companyStatistics);
363         }
364 
365         return requestCount;
366     }
367 
368     public long getRequestCountByPortlet(String portletId, long companyId)
369         throws MonitoringException {
370 
371         CompanyStatistics companyStatistics =
372             _serverStatistics.getCompanyStatistics(companyId);
373 
374         return getRequestCountByPortlet(portletId, companyStatistics);
375     }
376 
377     public long getRequestCountByPortlet(String portletId, String webId)
378         throws MonitoringException {
379 
380         CompanyStatistics companyStatistics =
381             _serverStatistics.getCompanyStatistics(webId);
382 
383         return getRequestCountByPortlet(portletId, companyStatistics);
384     }
385 
386     public long getSuccessCount() {
387         long successCount = 0;
388 
389         for (CompanyStatistics companyStatistics :
390                 _serverStatistics.getCompanyStatisticsSet()) {
391 
392             successCount += getSuccessCountByCompany(companyStatistics);
393         }
394 
395         return successCount;
396     }
397 
398     public long getSuccessCountByCompany(long companyId)
399         throws MonitoringException {
400 
401         CompanyStatistics companyStatistics =
402             _serverStatistics.getCompanyStatistics(companyId);
403 
404         return getSuccessCountByCompany(companyStatistics);
405     }
406 
407     public long getSuccessCountByCompany(String webId)
408         throws MonitoringException {
409 
410         CompanyStatistics companyStatistics =
411             _serverStatistics.getCompanyStatistics(webId);
412 
413         return getSuccessCountByCompany(companyStatistics);
414     }
415 
416     public long getSuccessCountByPortlet(String portletId)
417         throws MonitoringException {
418 
419         long successCount = 0;
420 
421         for (CompanyStatistics companyStatistics :
422                 _serverStatistics.getCompanyStatisticsSet()) {
423 
424             successCount += getSuccessCountByPortlet(
425                 portletId, companyStatistics);
426         }
427 
428         return successCount;
429     }
430 
431     public long getSuccessCountByPortlet(String portletId, long companyId)
432         throws MonitoringException {
433 
434         CompanyStatistics companyStatistics =
435             _serverStatistics.getCompanyStatistics(companyId);
436 
437         return getSuccessCountByPortlet(portletId, companyStatistics);
438     }
439 
440     public long getSuccessCountByPortlet(String portletId, String webId)
441         throws MonitoringException {
442 
443         CompanyStatistics companyStatistics =
444             _serverStatistics.getCompanyStatistics(webId);
445 
446         return getSuccessCountByPortlet(portletId, companyStatistics);
447     }
448 
449     public long getTimeoutCount() {
450         long timeoutCount = 0;
451 
452         for (CompanyStatistics companyStatistics :
453                 _serverStatistics.getCompanyStatisticsSet()) {
454 
455             timeoutCount += getTimeoutCountByCompany(companyStatistics);
456         }
457 
458         return timeoutCount;
459     }
460 
461     public long getTimeoutCountByCompany(long companyId)
462         throws MonitoringException {
463 
464         CompanyStatistics companyStatistics =
465             _serverStatistics.getCompanyStatistics(companyId);
466 
467         return getTimeoutCountByCompany(companyStatistics);
468     }
469 
470     public long getTimeoutCountByCompany(String webId)
471         throws MonitoringException {
472 
473         CompanyStatistics companyStatistics =
474             _serverStatistics.getCompanyStatistics(webId);
475 
476         return getTimeoutCountByCompany(companyStatistics);
477     }
478 
479     public long getTimeoutCountByPortlet(String portletId)
480         throws MonitoringException {
481 
482         long timeoutCount = 0;
483 
484         for (CompanyStatistics companyStatistics :
485                 _serverStatistics.getCompanyStatisticsSet()) {
486 
487             timeoutCount += getTimeoutCountByPortlet(
488                 portletId, companyStatistics);
489         }
490 
491         return timeoutCount;
492     }
493 
494     public long getTimeoutCountByPortlet(String portletId, long companyId)
495         throws MonitoringException {
496 
497         CompanyStatistics companyStatistics =
498             _serverStatistics.getCompanyStatistics(companyId);
499 
500         return getTimeoutCountByPortlet(portletId, companyStatistics);
501     }
502 
503     public long getTimeoutCountByPortlet(String portletId, String webId)
504         throws MonitoringException {
505 
506         CompanyStatistics companyStatistics =
507             _serverStatistics.getCompanyStatistics(webId);
508 
509         return getTimeoutCountByPortlet(portletId, companyStatistics);
510     }
511 
512     protected long getAverageTimeByCompany(
513         CompanyStatistics companyStatistics) {
514 
515         long averageTime = 0;
516 
517         Set<RequestStatistics> requestStatisticsSet =
518             companyStatistics.getActionRequestStatisticsSet();
519 
520         for (RequestStatistics requestStatistics : requestStatisticsSet) {
521             averageTime += requestStatistics.getAverageTime();
522         }
523 
524         return averageTime / requestStatisticsSet.size();
525     }
526 
527     protected long getErrorCountByCompany(CompanyStatistics companyStatistics) {
528         long errorCount = 0;
529 
530         for (RequestStatistics requestStatistics :
531                 companyStatistics.getActionRequestStatisticsSet()) {
532 
533             errorCount += requestStatistics.getErrorCount();
534         }
535 
536         return errorCount;
537     }
538 
539     protected long getErrorCountByPortlet(
540             String portletId, CompanyStatistics companyStatistics)
541         throws MonitoringException {
542 
543         RequestStatistics requestStatistics =
544             companyStatistics.getActionRequestStatistics(portletId);
545 
546         return requestStatistics.getErrorCount();
547     }
548 
549     protected long getMaxTimeByPortlet(
550             String portletId, CompanyStatistics companyStatistics)
551         throws MonitoringException {
552 
553         long maxTime = 0;
554 
555         RequestStatistics requestStatistics =
556             companyStatistics.getActionRequestStatistics(portletId);
557 
558         if (requestStatistics.getMaxTime() > maxTime) {
559             maxTime = requestStatistics.getMaxTime();
560         }
561 
562         return maxTime;
563     }
564 
565     protected long getMinTimeByPortlet(
566             String portletId, CompanyStatistics companyStatistics)
567         throws MonitoringException {
568 
569         long minTime = 0;
570 
571         RequestStatistics requestStatistics =
572             companyStatistics.getActionRequestStatistics(portletId);
573 
574         if (requestStatistics.getMinTime() < minTime) {
575             minTime = requestStatistics.getMinTime();
576         }
577 
578         return minTime;
579     }
580 
581     protected long getRequestCountByCompany(
582         CompanyStatistics companyStatistics) {
583 
584         long requestCount = 0;
585 
586         for (RequestStatistics requestStatistics :
587                 companyStatistics.getActionRequestStatisticsSet()) {
588 
589             requestCount += requestStatistics.getRequestCount();
590         }
591 
592         return requestCount;
593     }
594 
595     protected long getRequestCountByPortlet(
596             String portletId, CompanyStatistics companyStatistics)
597         throws MonitoringException {
598 
599         RequestStatistics requestStatistics =
600             companyStatistics.getActionRequestStatistics(portletId);
601 
602         return requestStatistics.getRequestCount();
603     }
604 
605     protected long getSuccessCountByCompany(
606         CompanyStatistics companyStatistics) {
607 
608         long successCount = 0;
609 
610         for (RequestStatistics requestStatistics :
611                 companyStatistics.getActionRequestStatisticsSet()) {
612 
613             successCount += requestStatistics.getSuccessCount();
614         }
615 
616         return successCount;
617     }
618 
619     protected long getSuccessCountByPortlet(
620             String portletId, CompanyStatistics companyStatistics)
621         throws MonitoringException {
622 
623         RequestStatistics requestStatistics =
624             companyStatistics.getActionRequestStatistics(portletId);
625 
626         return requestStatistics.getSuccessCount();
627     }
628 
629     protected long getTimeoutCountByCompany(
630         CompanyStatistics companyStatistics) {
631 
632         long timeoutCount = 0;
633 
634         for (RequestStatistics requestStatistics :
635                 companyStatistics.getActionRequestStatisticsSet()) {
636 
637             timeoutCount += requestStatistics.getTimeoutCount();
638         }
639 
640         return timeoutCount;
641     }
642 
643     protected long getTimeoutCountByPortlet(
644             String portletId, CompanyStatistics companyStatistics)
645         throws MonitoringException {
646 
647         RequestStatistics requestStatistics =
648             companyStatistics.getActionRequestStatistics(portletId);
649 
650         return requestStatistics.getTimeoutCount();
651     }
652 
653     private ServerStatistics _serverStatistics;
654 
655 }