001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.synapse.statistics;
020:
021: /**
022: * To hold statistics that will collected during both of in and out message mediation
023: */
024:
025: public class StatisticsHolder {
026:
027: private int statisticsCategory;
028:
029: private String key;
030:
031: /** The statistics that will collect during in coming message mediation */
032: private Statistics inFlowStatistics;
033:
034: /** The statistics that will collect during out going message mediation */
035: private Statistics outFlowStatistics;
036:
037: /**
038: * To update the statistics
039: *
040: * @param isResponse - A boolean value that indicate whether message flow is in or out
041: * @param inTime - The processing start time
042: * @param outTime - The processing end time
043: * @param isFault - A boolean value that indicate whether falut has occured or not
044: */
045: public synchronized void update(boolean isResponse, long inTime,
046: long outTime, boolean isFault) {
047: if (isResponse) {
048: if (outFlowStatistics == null) {
049: outFlowStatistics = new Statistics();
050: }
051: outFlowStatistics.update(inTime, outTime, isFault);
052: } else {
053: if (inFlowStatistics == null) {
054: inFlowStatistics = new Statistics();
055: }
056: inFlowStatistics.update(inTime, outTime, isFault);
057: }
058:
059: }
060:
061: /**
062: * To get Statistics related to the In Flow
063: * @return Statistics related to the In Flow
064: */
065: public synchronized Statistics getInFlowStatistics() {
066: return inFlowStatistics;
067: }
068:
069: /**
070: * To get Statistics related to the Out Flow
071: * @return Statistics related to the Out Flow
072: */
073: public synchronized Statistics getOutFlowStatistics() {
074: return outFlowStatistics;
075: }
076:
077: /**
078: * To get statistics category
079: * @return Statistics Category
080: */
081: public int getStatisticsCategory() {
082: return statisticsCategory;
083: }
084:
085: /**
086: * To set statistics category
087: * @param statisticsCategory
088: */
089: public void setStatisticsCategory(int statisticsCategory) {
090: this .statisticsCategory = statisticsCategory;
091: }
092:
093: /**
094: * To get key of statistics
095: * @return key of statistics
096: */
097: public String getKey() {
098: return key;
099: }
100:
101: /**
102: * To set key of statistics
103: * @param key
104: */
105: public void setKey(String key) {
106: this .key = key;
107: }
108:
109: /**
110: * To clear stored statistics
111: */
112: public synchronized void clearStatistics() {
113: this.inFlowStatistics = null;
114: this.outFlowStatistics = null;
115: }
116: }
|