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;
016    
017    /**
018     * @author Michael C. Han
019     * @author Brian Wing Shun Chan
020     */
021    public class RequestStatistics implements Statistics {
022    
023            public RequestStatistics(String name) {
024                    _name = name;
025                    _errorStatistics = new CountStatistics(name);
026                    _successStatistics = new AverageStatistics(name);
027                    _timeoutStatistics = new CountStatistics(name);
028            }
029    
030            public long getAverageTime() {
031                    return _successStatistics.getAverageTime();
032            }
033    
034            public String getDescription() {
035                    return _description;
036            }
037    
038            public long getErrorCount() {
039                    return _errorStatistics.getCount();
040            }
041    
042            public long getMaxTime() {
043                    return _successStatistics.getMaxTime();
044            }
045    
046            public long getMinTime() {
047                    return _successStatistics.getMinTime();
048            }
049    
050            public String getName() {
051                    return _name;
052            }
053    
054            public long getRequestCount() {
055                    return getErrorCount() + getSuccessCount() + getTimeoutCount();
056            }
057    
058            public long getSuccessCount() {
059                    return _successStatistics.getCount();
060            }
061    
062            public long getTimeoutCount() {
063                    return _timeoutStatistics.getCount();
064            }
065    
066            public void incrementError() {
067                    _errorStatistics.incrementCount();
068            }
069    
070            public void incrementSuccessDuration(long duration) {
071                    _successStatistics.addDuration(duration);
072            }
073    
074            public void incrementTimeout() {
075                    _timeoutStatistics.incrementCount();
076            }
077    
078            public void reset() {
079                    _errorStatistics.reset();
080                    _successStatistics.reset();
081                    _timeoutStatistics.reset();
082            }
083    
084            public void setDescription(String description) {
085                    _description = description;
086            }
087    
088            private String _description;
089            private CountStatistics _errorStatistics;
090            private String _name;
091            private AverageStatistics _successStatistics;
092            private CountStatistics _timeoutStatistics;
093    
094    }