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: * Transaction System Statistics. Statistics for all transactions
023: */
024: public class TransactionRuntime implements TransactionRuntimeMBean {
025: /** total number of committed transactions **/
026: long transactionTotalCount;
027: /** total number of committed transactions **/
028: long transactionCommittedTotalCount;
029: /** total number of rolled back transactions **/
030: long transactionRolledBackTotalCount;
031: /** total number of active transactions **/
032: long transactionActiveTotalCount;
033:
034: /** execution time in average **/
035: MathUtils.SMA executionTimeAverage = new MathUtils.SMA(50);
036:
037: /** execution total time **/
038: long executionTotalTime = 0;
039:
040: /** highest execution time **/
041: long executionTimeHigh = -1;
042:
043: /** lowest execution time **/
044: long executionTimeLow = -1;
045:
046: /**
047: * Simple Moving Average execution time of transactions
048: * @return Average execution time of transactions in milleseconds
049: */
050: public long getTransactionExecutionTimeAverage() {
051: return (long) executionTimeAverage.currentAverage();
052: }
053:
054: /**
055: * Lowest execution time
056: * @return Lowest execution time in milleseconds
057: */
058: public long getTransactionExecutionTimeLow() {
059: return executionTimeLow;
060: }
061:
062: /**
063: * Highest execution time
064: * @return Highest execution time in milleseconds
065: */
066: public long getTransactionExecutionTimeHigh() {
067: return executionTimeHigh;
068: }
069:
070: /**
071: * execution total time
072: * @return execution total time in milleseconds
073: */
074: public long getTransactionExecutionTotalTime() {
075: return executionTotalTime;
076: }
077:
078: /* (non-Javadoc)
079: * @see org.jpox.management.runtime.TransactionRuntimeMBean#getTransactionTotalCount()
080: */
081: public long getTransactionTotalCount() {
082: return transactionTotalCount;
083: }
084:
085: public long getTransactionActiveTotalCount() {
086: return transactionActiveTotalCount;
087: }
088:
089: /* (non-Javadoc)
090: * @see org.jpox.management.runtime.TransactionRuntimeMBean#getTransactionCommittedTotalCount()
091: */
092: public long getTransactionCommittedTotalCount() {
093: return transactionCommittedTotalCount;
094: }
095:
096: /* (non-Javadoc)
097: * @see org.jpox.management.runtime.TransactionRuntimeMBean#getTransactionRolledBackTotalCount()
098: */
099: public long getTransactionRolledBackTotalCount() {
100: return transactionRolledBackTotalCount;
101: }
102:
103: public void transactionCommitted(long executionTime) {
104: this .transactionCommittedTotalCount++;
105: this .transactionActiveTotalCount--;
106: executionTimeAverage.compute(executionTime);
107: executionTimeLow = Math.min(
108: executionTimeLow == -1 ? executionTime
109: : executionTimeLow, executionTime);
110: executionTimeHigh = Math.max(executionTimeHigh, executionTime);
111: executionTotalTime += executionTime;
112: }
113:
114: public void transactionRolledBack(long executionTime) {
115: this .transactionRolledBackTotalCount++;
116: this .transactionActiveTotalCount--;
117: executionTimeAverage.compute(executionTime);
118: executionTimeLow = Math.min(
119: executionTimeLow == -1 ? executionTime
120: : executionTimeLow, executionTime);
121: executionTimeHigh = Math.max(executionTimeHigh, executionTime);
122: executionTotalTime += executionTime;
123: }
124:
125: public void transactionStarted() {
126: this.transactionTotalCount++;
127: this.transactionActiveTotalCount++;
128: }
129: }
|