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.samples.daytrader.util;
018    
019    
020    /**
021     * @author stancox
022     *
023     * To change this generated comment edit the template variable "typecomment":
024     * Window>Preferences>Java>Templates.
025     * To enable and disable the creation of type comments go to
026     * Window>Preferences>Java>Code Generation.
027     */
028    public class MDBStats extends java.util.HashMap {
029            
030            
031            //Singleton class
032            private static MDBStats mdbStats = null;
033            private MDBStats()
034            {
035            }
036            
037            public static synchronized MDBStats getInstance()
038            {
039                    if (mdbStats == null)
040                            mdbStats = new MDBStats();
041                    return mdbStats;
042            }
043            
044            public TimerStat addTiming(String type, long sendTime, long recvTime)
045            {
046                    TimerStat stats = null;
047                    synchronized (type)
048                    {
049    
050                            stats = (TimerStat) get(type);
051                            if (stats == null) stats = new TimerStat();
052    
053                            long time =  recvTime - sendTime;                                                       
054                            if ( time > stats.getMax() ) stats.setMax(time);
055                            if ( time < stats.getMin() ) stats.setMin(time);
056                    stats.setCount(stats.getCount()+1);
057                            stats.setTotalTime(stats.getTotalTime() + time);
058                            
059                            put(type, stats);
060                    }
061                    return stats;
062            }
063    
064    
065    
066            public synchronized void reset()
067            {
068                    clear();
069            }       
070            
071    
072    
073    }