Home » synapse-1.2-src » org.apache.synapse.statistics » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one
    3    *  or more contributor license agreements.  See the NOTICE file
    4    *  distributed with this work for additional information
    5    *  regarding copyright ownership.  The ASF licenses this file
    6    *  to you under the Apache License, Version 2.0 (the
    7    *  "License"); you may not use this file except in compliance
    8    *  with the License.  You may obtain a copy of the License at
    9    *
   10    *   http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    *  Unless required by applicable law or agreed to in writing,
   13    *  software distributed under the License is distributed on an
   14    *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    *  KIND, either express or implied.  See the License for the
   16    *  specific language governing permissions and limitations
   17    *  under the License.
   18    */
   19   package org.apache.synapse.statistics;
   20   
   21   /**
   22    * The statistics data structure
   23    */
   24   
   25   public class Statistics {
   26   
   27       /**  Maximum processing time for a one way flow  */
   28       private long maxProcessingTime = 0;
   29       /** Minimum processing time for a one way flow   */
   30       private long minProcessingTime = -1;
   31       /** Average processing time for a one way flow */
   32       private double avgProcessingTime = 0;
   33       /** Total processing time for a one way flow  */
   34       private double totalProcessingTime;
   35       /** The number of access count for a one way flow  */
   36       private int count = 0;
   37       /** The number of fault count for a one way flow  */
   38       private int faultCount = 0;
   39   
   40       /**
   41        * Update the statistics
   42        *
   43        * @param inTime  - The processing start time
   44        * @param outTime - The processing end time
   45        * @param isFault - A boolean value that indicate whether falut has occured or not
   46        */
   47       public void update(long inTime, long outTime, boolean isFault) {
   48   
   49           if (outTime < 0 || inTime < 0) {
   50               return;
   51           }
   52   
   53           count++;
   54           if (isFault) {
   55               faultCount++;
   56           }
   57   
   58           long responseTime = outTime - inTime;
   59           if (maxProcessingTime < responseTime) {
   60               maxProcessingTime = responseTime;
   61           }
   62           if (minProcessingTime > responseTime) {
   63               minProcessingTime = responseTime;
   64           }
   65           if (minProcessingTime == -1) {
   66               minProcessingTime = responseTime;
   67           }
   68           totalProcessingTime = totalProcessingTime + responseTime;
   69           avgProcessingTime = totalProcessingTime / count;
   70       }
   71   
   72       /**
   73        * @return Returns the Maximum processing time
   74        */
   75       public long getMaxProcessingTime() {
   76           return maxProcessingTime;
   77       }
   78   
   79       /**
   80        * @return Returns the Avarage processing time
   81        */
   82       public double getAvgProcessingTime() {
   83           return avgProcessingTime;
   84       }
   85   
   86       /**
   87        * @return Returns the minimum processing time
   88        */
   89       public long getMinProcessingTime() {
   90           return minProcessingTime;
   91       }
   92   
   93       /**
   94        * @return Returns the fault count
   95        */
   96       public int getFaultCount() {
   97           return faultCount;
   98       }
   99   
  100       /**
  101        * @return Returns the total count that represents number of access in a one way flow
  102        */
  103       public int getCount() {
  104           return count;
  105       }
  106   }

Home » synapse-1.2-src » org.apache.synapse.statistics » [javadoc | source]