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   import org.apache.synapse.SynapseConstants;
   22   
   23   import java.util;
   24   
   25   /**
   26    * To collect statistics
   27    */
   28   
   29   public class StatisticsCollector {
   30   
   31       /**  A synchronized map for holding sequence statistics  */
   32       private Map sequenceStatistics = Collections.synchronizedMap(new HashMap());
   33   
   34       /**  A synchronized map for holding end point statistics */
   35       private Map endpointStatistics = Collections.synchronizedMap(new HashMap());
   36   
   37       /**  A synchronized map for holding proxy services statistics */
   38       private Map proxyServicesStatistics = Collections.synchronizedMap(new HashMap());
   39   
   40       /**
   41        * To report the statistics related to a  EndPonit
   42        *
   43        * @param keyOfStatistic - key for hold Statistic
   44        * @param isResponse     - A boolean value that indicate whether message flow is in or out
   45        * @param inTime         - The processing start time
   46        * @param outTime        - The processing end time
   47        * @param isFault        - A boolean value that indicate whether falut has occured or not
   48        */
   49       public void reportForEndPoint(String keyOfStatistic, boolean isResponse, long inTime,
   50                                     long outTime, boolean isFault) {
   51           StatisticsHolder statisticsHolder =
   52                   (StatisticsHolder) endpointStatistics.get(keyOfStatistic);
   53           if (statisticsHolder == null) {
   54               statisticsHolder = new StatisticsHolder();
   55               statisticsHolder.setKey(keyOfStatistic);
   56               statisticsHolder.setStatisticsCategory(SynapseConstants.ENDPOINT_STATISTICS);
   57               endpointStatistics.put(keyOfStatistic, statisticsHolder);
   58           }
   59           statisticsHolder.update(isResponse, inTime, outTime, isFault);
   60   
   61       }
   62   
   63       /**
   64        * To report the statistics related to a  ProxyService
   65        *
   66        * @param keyOfStatistic - key for hold Statistic
   67        * @param isResponse     - A boolean value that indicate whether message flow is in or out
   68        * @param inTime         - The processing start time
   69        * @param outTime        - The processing end time
   70        * @param isFault        - A boolean value that indicate whether falut has occured or not
   71        */
   72       public void reportForProxyService(String keyOfStatistic, boolean isResponse, long inTime,
   73                                         long outTime, boolean isFault) {
   74           StatisticsHolder statisticsHolder =
   75                   (StatisticsHolder) proxyServicesStatistics.get(keyOfStatistic);
   76           if (statisticsHolder == null) {
   77               statisticsHolder = new StatisticsHolder();
   78               statisticsHolder.setKey(keyOfStatistic);
   79               statisticsHolder.setStatisticsCategory(SynapseConstants.PROXYSERVICE_STATISTICS);
   80               proxyServicesStatistics.put(keyOfStatistic, statisticsHolder);
   81           }
   82           statisticsHolder.update(isResponse, inTime, outTime, isFault);
   83       }
   84   
   85       /**
   86        * To report the statistics related to a  Sequence
   87        *
   88        * @param keyOfStatistic - key for hold Statistic
   89        * @param isResponse     - A boolean value that indicate whether message flow is in or out
   90        * @param inTime         - The processing start time
   91        * @param outTime        - The processing end time
   92        * @param isFault        - A boolean value that indicate whether falut has occured or not
   93        */
   94       public void reportForSequence(String keyOfStatistic, boolean isResponse, long inTime,
   95                                     long outTime, boolean isFault) {
   96           StatisticsHolder statisticsHolder =
   97                   (StatisticsHolder) sequenceStatistics.get(keyOfStatistic);
   98           if (statisticsHolder == null) {
   99               statisticsHolder = new StatisticsHolder();
  100               statisticsHolder.setKey(keyOfStatistic);
  101               statisticsHolder.setStatisticsCategory(SynapseConstants.SEQUENCE_STATISTICS);
  102               sequenceStatistics.put(keyOfStatistic, statisticsHolder);
  103           }
  104           statisticsHolder.update(isResponse, inTime, outTime, isFault);
  105       }
  106   
  107       /**
  108        * To access all sequence statistics
  109        *
  110        * @return all sequence statistics
  111        */
  112       public Map getSequenceStatistics() {
  113           return sequenceStatistics;
  114       }
  115   
  116       /**
  117        * To access all proxy services statistics
  118        *
  119        * @return all proxy services statistics
  120        */
  121       public Map getProxyServiceStatistics() {
  122           return proxyServicesStatistics;
  123       }
  124   
  125       /**
  126        * To access all endpoint statistics
  127        *
  128        * @return all endpoint statistics
  129        */
  130       public Map getEndPointStatistics() {
  131           return endpointStatistics;
  132       }
  133   
  134       /**
  135        * To reset the sequence statistics
  136        */
  137       public void resetSequenceStatistics() {
  138           this.sequenceStatistics.clear();
  139       }
  140   
  141       /**
  142        * To reset the proxy service statistics
  143        */
  144       public void resetProxyServiceStatistics() {
  145           this.proxyServicesStatistics.clear();
  146       }
  147   
  148       /**
  149        * To reset the endpoint statistics
  150        */
  151       public void resetEndPointStatistics() {
  152           this.endpointStatistics.clear();
  153       }
  154   }

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