001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.monitoring.statistics.portlet;
016    
017    import com.liferay.portal.monitoring.MonitoringException;
018    import com.liferay.portal.monitoring.statistics.RequestStatistics;
019    
020    import java.util.Set;
021    
022    /**
023     * @author Michael C. Han
024     * @author Brian Wing Shun Chan
025     */
026    public class EventRequestSummaryStatistics implements PortletSummaryStatistics {
027    
028            public long getAverageTime() {
029                    long averageTime = 0;
030    
031                    long count = 0;
032    
033                    for (CompanyStatistics companyStatistics :
034                                    _serverStatistics.getCompanyStatisticsSet()) {
035    
036                            for (RequestStatistics requestStatistics :
037                                            companyStatistics.getEventRequestStatisticsSet()) {
038    
039                                    averageTime += requestStatistics.getAverageTime();
040    
041                                    count++;
042                            }
043                    }
044    
045                    return averageTime / count;
046            }
047    
048            public long getAverageTimeByCompany(long companyId)
049                    throws MonitoringException {
050    
051                    CompanyStatistics companyStatistics =
052                            _serverStatistics.getCompanyStatistics(companyId);
053    
054                    return getAverageTimeByCompany(companyStatistics);
055            }
056    
057            public long getAverageTimeByCompany(String webId)
058                    throws MonitoringException {
059    
060                    CompanyStatistics companyStatistics =
061                            _serverStatistics.getCompanyStatistics(webId);
062    
063                    return getAverageTimeByCompany(companyStatistics);
064            }
065    
066            public long getAverageTimeByPortlet(String portletId)
067                    throws MonitoringException {
068    
069                    long averageTime = 0;
070    
071                    Set<CompanyStatistics> companyStatisticsSet =
072                            _serverStatistics.getCompanyStatisticsSet();
073    
074                    for (CompanyStatistics companyStatistics : companyStatisticsSet) {
075                            RequestStatistics requestStatistics =
076                                    companyStatistics.getEventRequestStatistics(portletId);
077    
078                            averageTime += requestStatistics.getAverageTime();
079                    }
080    
081                    return averageTime / companyStatisticsSet.size();
082            }
083    
084            public long getAverageTimeByPortlet(String portletId, long companyId)
085                    throws MonitoringException {
086    
087                    CompanyStatistics companyStatistics =
088                            _serverStatistics.getCompanyStatistics(companyId);
089    
090                    RequestStatistics requestStatistics =
091                            companyStatistics.getEventRequestStatistics(portletId);
092    
093                    return requestStatistics.getAverageTime();
094            }
095    
096            public long getAverageTimeByPortlet(String portletId, String webId)
097                    throws MonitoringException {
098    
099                    CompanyStatistics companyStatistics =
100                            _serverStatistics.getCompanyStatistics(webId);
101    
102                    RequestStatistics requestStatistics =
103                            companyStatistics.getEventRequestStatistics(portletId);
104    
105                    return requestStatistics.getAverageTime();
106            }
107    
108            public long getErrorCount() {
109                    long errorCount = 0;
110    
111                    for (CompanyStatistics companyStatistics :
112                                    _serverStatistics.getCompanyStatisticsSet()) {
113    
114                            errorCount += getErrorCountByCompany(companyStatistics);
115                    }
116    
117                    return errorCount;
118            }
119    
120            public long getErrorCountByCompany(long companyId)
121                    throws MonitoringException {
122    
123                    CompanyStatistics companyStatistics =
124                            _serverStatistics.getCompanyStatistics(companyId);
125    
126                    return getErrorCountByCompany(companyStatistics);
127            }
128    
129            public long getErrorCountByCompany(String webId)
130                    throws MonitoringException {
131    
132                    CompanyStatistics companyStatistics =
133                            _serverStatistics.getCompanyStatistics(webId);
134    
135                    return getErrorCountByCompany(companyStatistics);
136            }
137    
138            public long getErrorCountByPortlet(String portletId)
139                    throws MonitoringException {
140    
141                    long errorCount = 0;
142    
143                    for (CompanyStatistics companyStatistics :
144                                    _serverStatistics.getCompanyStatisticsSet()) {
145    
146                            errorCount += getErrorCountByPortlet(portletId, companyStatistics);
147                    }
148    
149                    return errorCount;
150            }
151    
152            public long getErrorCountByPortlet(String portletId, long companyId)
153                    throws MonitoringException {
154    
155                    CompanyStatistics companyStatistics =
156                            _serverStatistics.getCompanyStatistics(companyId);
157    
158                    return getErrorCountByPortlet(portletId, companyStatistics);
159            }
160    
161            public long getErrorCountByPortlet(String portletId, String webId)
162                    throws MonitoringException {
163    
164                    CompanyStatistics companyStatistics =
165                            _serverStatistics.getCompanyStatistics(webId);
166    
167                    return getErrorCountByPortlet(portletId, companyStatistics);
168            }
169    
170            public long getMaxTime() {
171                    long maxTime = 0;
172    
173                    for (CompanyStatistics companyStatistics :
174                                    _serverStatistics.getCompanyStatisticsSet()) {
175    
176                            for (RequestStatistics requestStatistics :
177                                            companyStatistics.getEventRequestStatisticsSet()) {
178    
179                                    if (requestStatistics.getMaxTime() > maxTime) {
180                                            maxTime = requestStatistics.getMaxTime();
181                                    }
182                            }
183                    }
184    
185                    return maxTime;
186            }
187    
188            public long getMaxTimeByCompany(long companyId) throws MonitoringException {
189                    CompanyStatistics companyStatistics =
190                            _serverStatistics.getCompanyStatistics(companyId);
191    
192                    return companyStatistics.getMaxTime();
193            }
194    
195            public long getMaxTimeByCompany(String webId) throws MonitoringException {
196                    CompanyStatistics companyStatistics =
197                            _serverStatistics.getCompanyStatistics(webId);
198    
199                    return companyStatistics.getMaxTime();
200            }
201    
202            public long getMaxTimeByPortlet(String portletId)
203                    throws MonitoringException {
204    
205                    long maxTime = 0;
206    
207                    for (CompanyStatistics companyStatistics :
208                                    _serverStatistics.getCompanyStatisticsSet()) {
209    
210                            long curMaxTime = getMaxTimeByPortlet(portletId, companyStatistics);
211    
212                            if (curMaxTime > maxTime) {
213                                    maxTime = curMaxTime;
214                            }
215                    }
216    
217                    return maxTime;
218            }
219    
220            public long getMaxTimeByPortlet(String portletId, long companyId)
221                    throws MonitoringException {
222    
223                    CompanyStatistics companyStatistics =
224                            _serverStatistics.getCompanyStatistics(companyId);
225    
226                    return getMaxTimeByPortlet(portletId, companyStatistics);
227            }
228    
229            public long getMaxTimeByPortlet(String portletId, String webId)
230                    throws MonitoringException {
231    
232                    CompanyStatistics companyStatistics =
233                            _serverStatistics.getCompanyStatistics(webId);
234    
235                    return getMaxTimeByPortlet(portletId, companyStatistics);
236            }
237    
238            public long getMinTime() {
239                    long minTime = 0;
240    
241                    for (CompanyStatistics companyStatistics :
242                                    _serverStatistics.getCompanyStatisticsSet()) {
243    
244                            for (RequestStatistics requestStatistics :
245                                            companyStatistics.getEventRequestStatisticsSet()) {
246    
247                                    if (requestStatistics.getMinTime() < minTime) {
248                                            minTime = requestStatistics.getMinTime();
249                                    }
250                            }
251                    }
252    
253                    return minTime;
254            }
255    
256            public long getMinTimeByCompany(long companyId) throws MonitoringException {
257                    CompanyStatistics companyStatistics =
258                            _serverStatistics.getCompanyStatistics(companyId);
259    
260                    return companyStatistics.getMinTime();
261            }
262    
263            public long getMinTimeByCompany(String webId) throws MonitoringException {
264                    CompanyStatistics companyStatistics =
265                            _serverStatistics.getCompanyStatistics(webId);
266    
267                    return companyStatistics.getMinTime();
268            }
269    
270            public long getMinTimeByPortlet(String portletId)
271                    throws MonitoringException {
272    
273                    long minTime = 0;
274    
275                    for (CompanyStatistics companyStatistics :
276                                    _serverStatistics.getCompanyStatisticsSet()) {
277    
278                            long curMinTime = getMinTimeByPortlet(portletId, companyStatistics);
279    
280                            if (curMinTime < minTime) {
281                                    minTime = curMinTime;
282                            }
283                    }
284    
285                    return minTime;
286            }
287    
288            public long getMinTimeByPortlet(String portletId, long companyId)
289                    throws MonitoringException {
290    
291                    CompanyStatistics companyStatistics =
292                            _serverStatistics.getCompanyStatistics(companyId);
293    
294                    return getMinTimeByPortlet(portletId, companyStatistics);
295            }
296    
297            public long getMinTimeByPortlet(String portletId, String webId)
298                    throws MonitoringException {
299    
300                    CompanyStatistics companyStatistics =
301                            _serverStatistics.getCompanyStatistics(webId);
302    
303                    return getMinTimeByPortlet(portletId, companyStatistics);
304            }
305    
306            public long getRequestCount() {
307                    long requestCount = 0;
308    
309                    for (CompanyStatistics companyStatistics :
310                                    _serverStatistics.getCompanyStatisticsSet()) {
311    
312                            requestCount += getRequestCountByCompany(companyStatistics);
313                    }
314    
315                    return requestCount;
316            }
317    
318            public long getRequestCountByCompany(long companyId)
319                    throws MonitoringException {
320    
321                    CompanyStatistics companyStatistics =
322                            _serverStatistics.getCompanyStatistics(companyId);
323    
324                    return getRequestCountByCompany(companyStatistics);
325            }
326    
327            public long getRequestCountByCompany(String webId)
328                    throws MonitoringException {
329    
330                    CompanyStatistics companyStatistics =
331                            _serverStatistics.getCompanyStatistics(webId);
332    
333                    return getRequestCountByCompany(companyStatistics);
334            }
335    
336            public long getRequestCountByPortlet(String portletId)
337                    throws MonitoringException {
338    
339                    long requestCount = 0;
340    
341                    for (CompanyStatistics companyStatistics :
342                                    _serverStatistics.getCompanyStatisticsSet()) {
343    
344                            requestCount += getRequestCountByPortlet(
345                                    portletId, companyStatistics);
346                    }
347    
348                    return requestCount;
349            }
350    
351            public long getRequestCountByPortlet(String portletId, long companyId)
352                    throws MonitoringException {
353    
354                    CompanyStatistics companyStatistics =
355                            _serverStatistics.getCompanyStatistics(companyId);
356    
357                    return getRequestCountByPortlet(portletId, companyStatistics);
358            }
359    
360            public long getRequestCountByPortlet(String portletId, String webId)
361                    throws MonitoringException {
362    
363                    CompanyStatistics companyStatistics =
364                            _serverStatistics.getCompanyStatistics(webId);
365    
366                    return getRequestCountByPortlet(portletId, companyStatistics);
367            }
368    
369            public long getSuccessCount() {
370                    long successCount = 0;
371    
372                    for (CompanyStatistics companyStatistics :
373                                    _serverStatistics.getCompanyStatisticsSet()) {
374    
375                            successCount += getSuccessCountByCompany(companyStatistics);
376                    }
377    
378                    return successCount;
379            }
380    
381            public long getSuccessCountByCompany(long companyId)
382                    throws MonitoringException {
383    
384                    CompanyStatistics companyStatistics =
385                            _serverStatistics.getCompanyStatistics(companyId);
386    
387                    return getSuccessCountByCompany(companyStatistics);
388            }
389    
390            public long getSuccessCountByCompany(String webId)
391                    throws MonitoringException {
392    
393                    CompanyStatistics companyStatistics =
394                            _serverStatistics.getCompanyStatistics(webId);
395    
396                    return getSuccessCountByCompany(companyStatistics);
397            }
398    
399            public long getSuccessCountByPortlet(String portletId)
400                    throws MonitoringException {
401    
402                    long successCount = 0;
403    
404                    for (CompanyStatistics companyStatistics :
405                                    _serverStatistics.getCompanyStatisticsSet()) {
406    
407                            successCount += getSuccessCountByPortlet(
408                                    portletId, companyStatistics);
409                    }
410    
411                    return successCount;
412            }
413    
414            public long getSuccessCountByPortlet(String portletId, long companyId)
415                    throws MonitoringException {
416    
417                    CompanyStatistics companyStatistics =
418                            _serverStatistics.getCompanyStatistics(companyId);
419    
420                    return getSuccessCountByPortlet(portletId, companyStatistics);
421            }
422    
423            public long getSuccessCountByPortlet(String portletId, String webId)
424                    throws MonitoringException {
425    
426                    CompanyStatistics companyStatistics =
427                            _serverStatistics.getCompanyStatistics(webId);
428    
429                    return getSuccessCountByPortlet(portletId, companyStatistics);
430            }
431    
432            public long getTimeoutCount() {
433                    long timeoutCount = 0;
434    
435                    for (CompanyStatistics companyStatistics :
436                                    _serverStatistics.getCompanyStatisticsSet()) {
437    
438                            timeoutCount += getTimeoutCountByCompany(companyStatistics);
439                    }
440    
441                    return timeoutCount;
442            }
443    
444            public long getTimeoutCountByCompany(long companyId)
445                    throws MonitoringException {
446    
447                    CompanyStatistics companyStatistics =
448                            _serverStatistics.getCompanyStatistics(companyId);
449    
450                    return getTimeoutCountByCompany(companyStatistics);
451            }
452    
453            public long getTimeoutCountByCompany(String webId)
454                    throws MonitoringException {
455    
456                    CompanyStatistics companyStatistics =
457                            _serverStatistics.getCompanyStatistics(webId);
458    
459                    return getTimeoutCountByCompany(companyStatistics);
460            }
461    
462            public long getTimeoutCountByPortlet(String portletId)
463                    throws MonitoringException {
464    
465                    long timeoutCount = 0;
466    
467                    for (CompanyStatistics companyStatistics :
468                                    _serverStatistics.getCompanyStatisticsSet()) {
469    
470                            timeoutCount += getTimeoutCountByPortlet(
471                                    portletId, companyStatistics);
472                    }
473    
474                    return timeoutCount;
475            }
476    
477            public long getTimeoutCountByPortlet(String portletId, long companyId)
478                    throws MonitoringException {
479    
480                    CompanyStatistics companyStatistics =
481                            _serverStatistics.getCompanyStatistics(companyId);
482    
483                    return getTimeoutCountByPortlet(portletId, companyStatistics);
484            }
485    
486            public long getTimeoutCountByPortlet(String portletId, String webId)
487                    throws MonitoringException {
488    
489                    CompanyStatistics companyStatistics =
490                            _serverStatistics.getCompanyStatistics(webId);
491    
492                    return getTimeoutCountByPortlet(portletId, companyStatistics);
493            }
494    
495            public void setServerStatistics(ServerStatistics serverStatistics) {
496                    _serverStatistics = serverStatistics;
497            }
498    
499            protected long getAverageTimeByCompany(
500                    CompanyStatistics companyStatistics) {
501    
502                    long averageTime = 0;
503    
504                    Set<RequestStatistics> requestStatisticsSet =
505                            companyStatistics.getEventRequestStatisticsSet();
506    
507                    for (RequestStatistics requestStatistics : requestStatisticsSet) {
508                            averageTime += requestStatistics.getAverageTime();
509                    }
510    
511                    return averageTime / requestStatisticsSet.size();
512            }
513    
514            protected long getErrorCountByCompany(CompanyStatistics companyStatistics) {
515                    long errorCount = 0;
516    
517                    for (RequestStatistics requestStatistics :
518                                    companyStatistics.getEventRequestStatisticsSet()) {
519    
520                            errorCount += requestStatistics.getErrorCount();
521                    }
522    
523                    return errorCount;
524            }
525    
526            protected long getErrorCountByPortlet(
527                            String portletId, CompanyStatistics companyStatistics)
528                    throws MonitoringException {
529    
530                    RequestStatistics requestStatistics =
531                            companyStatistics.getEventRequestStatistics(portletId);
532    
533                    return requestStatistics.getErrorCount();
534            }
535    
536            protected long getMaxTimeByPortlet(
537                            String portletId, CompanyStatistics companyStatistics)
538                    throws MonitoringException {
539    
540                    long maxTime = 0;
541    
542                    RequestStatistics requestStatistics =
543                            companyStatistics.getEventRequestStatistics(portletId);
544    
545                    if (requestStatistics.getMaxTime() > maxTime) {
546                            maxTime = requestStatistics.getMaxTime();
547                    }
548    
549                    return maxTime;
550            }
551    
552            protected long getMinTimeByPortlet(
553                            String portletId, CompanyStatistics companyStatistics)
554                    throws MonitoringException {
555    
556                    long minTime = 0;
557    
558                    RequestStatistics requestStatistics =
559                            companyStatistics.getEventRequestStatistics(portletId);
560    
561                    if (requestStatistics.getMinTime() < minTime) {
562                            minTime = requestStatistics.getMinTime();
563                    }
564    
565                    return minTime;
566            }
567    
568            protected long getRequestCountByCompany(
569                    CompanyStatistics companyStatistics) {
570    
571                    long requestCount = 0;
572    
573                    for (RequestStatistics requestStatistics :
574                                    companyStatistics.getEventRequestStatisticsSet()) {
575    
576                            requestCount += requestStatistics.getRequestCount();
577                    }
578    
579                    return requestCount;
580            }
581    
582            protected long getRequestCountByPortlet(
583                            String portletId, CompanyStatistics companyStatistics)
584                    throws MonitoringException {
585    
586                    RequestStatistics requestStatistics =
587                            companyStatistics.getEventRequestStatistics(portletId);
588    
589                    return requestStatistics.getRequestCount();
590            }
591    
592            protected long getSuccessCountByCompany(
593                    CompanyStatistics companyStatistics) {
594    
595                    long successCount = 0;
596    
597                    for (RequestStatistics requestStatistics :
598                                    companyStatistics.getEventRequestStatisticsSet()) {
599    
600                            successCount += requestStatistics.getSuccessCount();
601                    }
602    
603                    return successCount;
604            }
605    
606            protected long getSuccessCountByPortlet(
607                            String portletId, CompanyStatistics companyStatistics)
608                    throws MonitoringException {
609    
610                    RequestStatistics requestStatistics =
611                            companyStatistics.getEventRequestStatistics(portletId);
612    
613                    return requestStatistics.getSuccessCount();
614            }
615    
616            protected long getTimeoutCountByCompany(
617                    CompanyStatistics companyStatistics) {
618    
619                    long timeoutCount = 0;
620    
621                    for (RequestStatistics requestStatistics :
622                                    companyStatistics.getEventRequestStatisticsSet()) {
623    
624                            timeoutCount += requestStatistics.getTimeoutCount();
625                    }
626    
627                    return timeoutCount;
628            }
629    
630            protected long getTimeoutCountByPortlet(
631                            String portletId, CompanyStatistics companyStatistics)
632                    throws MonitoringException {
633    
634                    RequestStatistics requestStatistics =
635                            companyStatistics.getEventRequestStatistics(portletId);
636    
637                    return requestStatistics.getTimeoutCount();
638            }
639    
640            private ServerStatistics _serverStatistics;
641    
642    }