001: /**********************************************************************
002: Copyright (c) 2007 Erik Bengtson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015: Contributors:
016: ...
017: ***********************************************************************/package org.jpox.management.runtime;
018:
019: import org.jpox.util.MathUtils;
020:
021: /**
022: * Query runtime statistics
023: */
024: public class QueryRuntime implements QueryRuntimeMBean {
025: long activeTotalCount;
026:
027: long errorTotalCount;
028:
029: long executionTotalCount;
030:
031: /** execution total time **/
032: long executionTotalTime = 0;
033:
034: /** highest execution time **/
035: long executionTimeHigh = -1;
036:
037: /** lowest execution time **/
038: long executionTimeLow = -1;
039:
040: /** execution time in average **/
041: MathUtils.SMA executionTimeAverage = new MathUtils.SMA(50);
042:
043: /**
044: * The total number of queries that are executing
045: * @return the total
046: */
047: public long getQueryActiveTotalCount() {
048: return activeTotalCount;
049: }
050:
051: /**
052: * The total number of queries that failed executing
053: * @return the total
054: */
055: public long getQueryErrorTotalCount() {
056: return errorTotalCount;
057: }
058:
059: /**
060: * The total number of queries executed
061: * @return the total
062: */
063: public long getQueryExecutionTotalCount() {
064: return executionTotalCount;
065: }
066:
067: /**
068: * Lowest execution time
069: * @return Lowest execution time in milleseconds
070: */
071: public long getQueryExecutionTimeLow() {
072: return executionTimeLow;
073: }
074:
075: /**
076: * Highest execution time
077: * @return Highest execution time in milleseconds
078: */
079: public long getQueryExecutionTimeHigh() {
080: return executionTimeHigh;
081: }
082:
083: /**
084: * execution total time
085: * @return execution total time in milleseconds
086: */
087: public long getQueryExecutionTotalTime() {
088: return executionTotalTime;
089: }
090:
091: /**
092: * Simple Moving Average execution time of transactions
093: * @return Average execution time of transactions in milleseconds
094: */
095: public long getQueryExecutionTimeAverage() {
096: return (long) executionTimeAverage.currentAverage();
097: }
098:
099: public void queryBegin() {
100: this .activeTotalCount++;
101: }
102:
103: public void queryExecutedWithError() {
104: this .errorTotalCount++;
105: this .activeTotalCount--;
106: }
107:
108: public void queryExecuted(long executionTime) {
109: this .executionTotalCount++;
110: this .activeTotalCount--;
111: executionTimeAverage.compute(executionTime);
112: executionTimeLow = Math.min(
113: executionTimeLow == -1 ? executionTime
114: : executionTimeLow, executionTime);
115: executionTimeHigh = Math.max(executionTimeHigh, executionTime);
116: executionTotalTime += executionTime;
117: }
118: }
|