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    package org.apache.geronimo.management.stats;
018    
019    import java.io.Serializable;
020    import javax.management.j2ee.statistics.Statistic;
021    
022    /**
023     * Implementation of the JSR-77 Statistic interface (JSR77.6.4)
024     *
025     * @version $Rev: 503407 $ $Date: 2007-02-04 08:57:40 -0500 (Sun, 04 Feb 2007) $
026     */
027    public class StatisticImpl implements Statistic, Serializable {
028        // Defined in JSR77.6.4.1.2
029        public final static String UNIT_TIME_HOUR = "HOUR";
030        public final static String UNIT_TIME_MINUTE = "MINUTE";
031        public final static String UNIT_TIME_SECOND = "SECOND";
032        public final static String UNIT_TIME_MILLISECOND = "MILLISECOND";
033        public final static String UNIT_TIME_MICROSECOND = "MICROSECOND";
034        public final static String UNIT_TIME_NANOSECOND = "NANOSECOND";
035        // Units that are not defined in JSR-77
036        public final static String UNIT_MEMORY_BYTES = "BYTE";
037        public final static String UNIT_MEMORY_KILOBYTES = "KILOBYTE";
038        public final static String UNIT_MEMORY_MEGABYTES = "MEGABYTE";
039        public final static String UNIT_MEMORY_GIGABYTES = "GIGABYTE";
040        // need a better name for this
041        public final static String UNIT_COUNT = "UNITCOUNT";
042    
043        private String name;
044        private String unit;
045        private String description;
046        private long startTime;
047        private long lastSampleTime;
048    
049        public StatisticImpl(String name, String unit, String description) {
050            this.name = name;
051            this.unit = unit;
052            this.description = description;
053        }
054    
055        public String getName() {
056            return name;
057        }
058    
059        public String getUnit() {
060            return unit;
061        }
062    
063        public String getDescription() {
064            return description;
065        }
066    
067        public long getStartTime() {
068            return startTime;
069        }
070    
071        public void setStartTime() {
072            this.startTime = System.currentTimeMillis();
073        }
074    
075        public void setStartTime(long startTime) {
076            this.startTime = startTime;
077        }
078    
079        public long getLastSampleTime() {
080            return lastSampleTime;
081        }
082    
083        public void setLastSampleTime(long lastSampleTime) {
084            this.lastSampleTime = lastSampleTime;
085        }
086    
087        public void setLastSampleTime() {
088            this.lastSampleTime = System.currentTimeMillis();
089        }
090    }