001    /**
002     * Copyright (c) 2000-2013 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.kernel.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            @Override
035            public String getDescription() {
036                    return _description;
037            }
038    
039            public long getErrorCount() {
040                    return _errorStatistics.getCount();
041            }
042    
043            public long getMaxTime() {
044                    return _successStatistics.getMaxTime();
045            }
046    
047            public long getMinTime() {
048                    return _successStatistics.getMinTime();
049            }
050    
051            @Override
052            public String getName() {
053                    return _name;
054            }
055    
056            public long getRequestCount() {
057                    return getErrorCount() + getSuccessCount() + getTimeoutCount();
058            }
059    
060            public long getSuccessCount() {
061                    return _successStatistics.getCount();
062            }
063    
064            public long getTimeoutCount() {
065                    return _timeoutStatistics.getCount();
066            }
067    
068            public void incrementError() {
069                    _errorStatistics.incrementCount();
070            }
071    
072            public void incrementSuccessDuration(long duration) {
073                    _successStatistics.addDuration(duration);
074            }
075    
076            public void incrementTimeout() {
077                    _timeoutStatistics.incrementCount();
078            }
079    
080            @Override
081            public void reset() {
082                    _errorStatistics.reset();
083                    _successStatistics.reset();
084                    _timeoutStatistics.reset();
085            }
086    
087            @Override
088            public void setDescription(String description) {
089                    _description = description;
090            }
091    
092            private String _description;
093            private CountStatistics _errorStatistics;
094            private String _name;
095            private AverageStatistics _successStatistics;
096            private CountStatistics _timeoutStatistics;
097    
098    }