001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    
018    package org.apache.geronimo.management.stats;
019    
020    import javax.management.j2ee.statistics.CountStatistic;
021    import javax.management.j2ee.statistics.RangeStatistic;
022    import javax.management.j2ee.statistics.TimeStatistic;
023    
024    import org.apache.geronimo.management.geronimo.stats.WebConnectorStats;
025    
026    /**
027     * Geronimo implementation of the JSR-77 style WebConnectorStats interface. This
028     * is not required by JSR-77, but provides useful statistics. This will be
029     * discovered by mejb using 'stats' attribute.
030     * 
031     * @version $Revision: 503534 $ $Date: 2007-02-04 22:00:28 -0500 (Sun, 04 Feb 2007) $
032     */
033    
034    public class WebConnectorStatsImpl extends StatsImpl implements WebConnectorStats {
035        private TimeStatisticImpl requestTime; // total, max, count
036    
037        private CountStatisticImpl activeRequestCount;
038    
039        private CountStatisticImpl errorCount;
040    
041        private CountStatisticImpl bytesSentCount;
042    
043        private CountStatisticImpl bytesReceivedCount;
044        
045        // these come from ThreadPool
046        private RangeStatisticImpl openConnectionCount; 
047        
048        private CountStatistic busyThreadCount;
049        
050        // TODO - change the name to BoundedRangeStatisticsImpl
051        private BoundedRangeStatisticImpl busyThreads;
052        // TODO - spareThreads metrics = current - busy, maxSpareThreads, minSpareThreads 
053    
054        public WebConnectorStatsImpl() {
055            requestTime = new TimeStatisticImpl("Request Time", StatisticImpl.UNIT_TIME_MILLISECOND,
056                    "The time to process all requests");
057            activeRequestCount = new CountStatisticImpl("Active Request Count", StatisticImpl.UNIT_COUNT,
058                    "currently active requests ", 0);
059            errorCount = new CountStatisticImpl("Error Count", StatisticImpl.UNIT_COUNT,
060                    "The numbet of Errors during the observed period", 0);
061            bytesSentCount = new CountStatisticImpl("Bytes Sent", StatisticImpl.UNIT_COUNT,
062                    "The number of bytes sent during the observerd period", 0);
063            bytesReceivedCount = new CountStatisticImpl("Bytes Received", StatisticImpl.UNIT_COUNT,
064                    "The number of bytes received during the observerd period", 0);
065            openConnectionCount = new RangeStatisticImpl("" + "Open Connections", StatisticImpl.UNIT_COUNT,
066                    "Range for connections opened during the observed period", 0); // all 0's
067            busyThreads = new BoundedRangeStatisticImpl("Busy Threads", StatisticImpl.UNIT_COUNT,
068                    "BoundedRange for Threads currently busy serving requests", 0, 0, 0);
069            addStat("RequestTime", requestTime); // better name
070            addStat("activeRequestCount", activeRequestCount);
071            addStat("errorCount", errorCount);
072            addStat("bytesSent", bytesSentCount);
073            addStat("bytesReceived", bytesReceivedCount);
074            addStat("openConnectionCount", openConnectionCount);
075            addStat("busyThreads", busyThreads);
076        }
077    
078        public RangeStatistic getActiveRequestCount() {
079            // TODO 
080            return null;
081        }
082    
083        public TimeStatistic getRequestTime() {
084            return requestTime;
085        }
086    
087        public CountStatistic getErrorCount() {
088            return errorCount;
089        }
090    
091        public CountStatistic getBytesSentCount() {
092            return bytesSentCount;
093        }
094    
095        public CountStatistic getBytesReceivedCount() {
096            return bytesReceivedCount;
097        }
098       
099        public RangeStatistic getOpenConnectionCount() {
100            return openConnectionCount;
101        }
102        
103        // TODO - Move this to container statistics
104        public RangeStatistic getSpareThreadCount() {
105            return null;
106        }
107        
108        /**
109         * These setters are used by native implementation
110         */
111        public void setBytesReceivedCount(long bytesReceived) {
112            this.bytesReceivedCount.setCount(bytesReceived);
113        }
114    
115        public void setBytesSentCount(long bytesSent) {
116            this.bytesSentCount.setCount(bytesSent);
117        }
118    
119        public void setActiveRequestCount(int activeRequestCount) {
120            this.activeRequestCount.setCount(activeRequestCount);
121        }
122    
123        public void setErrorCount(int errorCount) {
124            this.errorCount.setCount(errorCount);
125        }
126    
127        public void setRequestTime(int count, long minTime, long maxTime, long totalTime) {
128            this.requestTime.setCount(count);
129            this.requestTime.setMinTime(minTime);
130            this.requestTime.setMaxTime(maxTime);
131            this.requestTime.setTotalTime(totalTime);
132        }
133     
134        public void setOpenConnection(long current, long highMark, long lowMark) {
135            openConnectionCount.setCurrent(current);
136            openConnectionCount.setHighWaterMark(highMark);
137            openConnectionCount.setLowWaterMark(lowMark);
138        }
139        
140        public void setBusyThreads(long current, long highWaterMark, long lowWaterMark,
141                long upperBound, long lowerBound) {
142            busyThreads.setCurrent(current);
143            busyThreads.setHighWaterMark(highWaterMark);
144            busyThreads.setLowWaterMark(lowWaterMark); //0?
145            busyThreads.setLowerBound(lowerBound); //0?
146            busyThreads.setUpperBound(upperBound);  // always maxThreads
147        }
148        
149        /**
150         * Used to access the native implementation in order to call setters
151         * TODO implement these if needed by console
152         */
153        public RangeStatisticImpl getActiveRequestCountImpl() {
154            return null;
155        }
156    
157        public TimeStatisticImpl getRequestDurationImpl() {
158            return null;
159        }
160    
161        public CountStatisticImpl getTotalErrorCountImpl() {
162            return null;
163        }
164    
165        public CountStatistic getTotalRequestCountImpl() {
166            return null;
167        }
168    
169    }