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: import org.apache.synapse.SynapseConstants;
022:
023: import java.util.*;
024:
025: /**
026: * To collect statistics
027: */
028:
029: public class StatisticsCollector {
030:
031: /** A synchronized map for holding sequence statistics */
032: private Map sequenceStatistics = Collections
033: .synchronizedMap(new HashMap());
034:
035: /** A synchronized map for holding end point statistics */
036: private Map endpointStatistics = Collections
037: .synchronizedMap(new HashMap());
038:
039: /** A synchronized map for holding proxy services statistics */
040: private Map proxyServicesStatistics = Collections
041: .synchronizedMap(new HashMap());
042:
043: /**
044: * To report the statistics related to a EndPonit
045: *
046: * @param keyOfStatistic - key for hold Statistic
047: * @param isResponse - A boolean value that indicate whether message flow is in or out
048: * @param inTime - The processing start time
049: * @param outTime - The processing end time
050: * @param isFault - A boolean value that indicate whether falut has occured or not
051: */
052: public void reportForEndPoint(String keyOfStatistic,
053: boolean isResponse, long inTime, long outTime,
054: boolean isFault) {
055: StatisticsHolder statisticsHolder = (StatisticsHolder) endpointStatistics
056: .get(keyOfStatistic);
057: if (statisticsHolder == null) {
058: statisticsHolder = new StatisticsHolder();
059: statisticsHolder.setKey(keyOfStatistic);
060: statisticsHolder
061: .setStatisticsCategory(SynapseConstants.ENDPOINT_STATISTICS);
062: endpointStatistics.put(keyOfStatistic, statisticsHolder);
063: }
064: statisticsHolder.update(isResponse, inTime, outTime, isFault);
065:
066: }
067:
068: /**
069: * To report the statistics related to a ProxyService
070: *
071: * @param keyOfStatistic - key for hold Statistic
072: * @param isResponse - A boolean value that indicate whether message flow is in or out
073: * @param inTime - The processing start time
074: * @param outTime - The processing end time
075: * @param isFault - A boolean value that indicate whether falut has occured or not
076: */
077: public void reportForProxyService(String keyOfStatistic,
078: boolean isResponse, long inTime, long outTime,
079: boolean isFault) {
080: StatisticsHolder statisticsHolder = (StatisticsHolder) proxyServicesStatistics
081: .get(keyOfStatistic);
082: if (statisticsHolder == null) {
083: statisticsHolder = new StatisticsHolder();
084: statisticsHolder.setKey(keyOfStatistic);
085: statisticsHolder
086: .setStatisticsCategory(SynapseConstants.PROXYSERVICE_STATISTICS);
087: proxyServicesStatistics.put(keyOfStatistic,
088: statisticsHolder);
089: }
090: statisticsHolder.update(isResponse, inTime, outTime, isFault);
091: }
092:
093: /**
094: * To report the statistics related to a Sequence
095: *
096: * @param keyOfStatistic - key for hold Statistic
097: * @param isResponse - A boolean value that indicate whether message flow is in or out
098: * @param inTime - The processing start time
099: * @param outTime - The processing end time
100: * @param isFault - A boolean value that indicate whether falut has occured or not
101: */
102: public void reportForSequence(String keyOfStatistic,
103: boolean isResponse, long inTime, long outTime,
104: boolean isFault) {
105: StatisticsHolder statisticsHolder = (StatisticsHolder) sequenceStatistics
106: .get(keyOfStatistic);
107: if (statisticsHolder == null) {
108: statisticsHolder = new StatisticsHolder();
109: statisticsHolder.setKey(keyOfStatistic);
110: statisticsHolder
111: .setStatisticsCategory(SynapseConstants.SEQUENCE_STATISTICS);
112: sequenceStatistics.put(keyOfStatistic, statisticsHolder);
113: }
114: statisticsHolder.update(isResponse, inTime, outTime, isFault);
115: }
116:
117: /**
118: * To access all sequence statistics
119: *
120: * @return all sequence statistics
121: */
122: public Map getSequenceStatistics() {
123: return sequenceStatistics;
124: }
125:
126: /**
127: * To access all proxy services statistics
128: *
129: * @return all proxy services statistics
130: */
131: public Map getProxyServiceStatistics() {
132: return proxyServicesStatistics;
133: }
134:
135: /**
136: * To access all endpoint statistics
137: *
138: * @return all endpoint statistics
139: */
140: public Map getEndPointStatistics() {
141: return endpointStatistics;
142: }
143:
144: /**
145: * To reset the sequence statistics
146: */
147: public void resetSequenceStatistics() {
148: this .sequenceStatistics.clear();
149: }
150:
151: /**
152: * To reset the proxy service statistics
153: */
154: public void resetProxyServiceStatistics() {
155: this .proxyServicesStatistics.clear();
156: }
157:
158: /**
159: * To reset the endpoint statistics
160: */
161: public void resetEndPointStatistics() {
162: this.endpointStatistics.clear();
163: }
164: }
|