1 /*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 5 * 6 */ 7 8 package com.sleepycat.je; 9 10 import static com.sleepycat.je.dbi.TxnStatDefinition.TXN_ABORTS; 11 import static com.sleepycat.je.dbi.TxnStatDefinition.TXN_ACTIVE; 12 import static com.sleepycat.je.dbi.TxnStatDefinition.TXN_ACTIVE_TXNS; 13 import static com.sleepycat.je.dbi.TxnStatDefinition.TXN_BEGINS; 14 import static com.sleepycat.je.dbi.TxnStatDefinition.TXN_COMMITS; 15 import static com.sleepycat.je.dbi.TxnStatDefinition.TXN_XAABORTS; 16 import static com.sleepycat.je.dbi.TxnStatDefinition.TXN_XACOMMITS; 17 import static com.sleepycat.je.dbi.TxnStatDefinition.TXN_XAPREPARES; 18 19 import java.io.Serializable; 20 21 import com.sleepycat.je.utilint.StatGroup; 22 23 /** 24 * Transaction statistics for a database environment. 25 */ 26 public class TransactionStats implements Serializable { 27 28 private static final long serialVersionUID = 2136955031L; 29 30 private StatGroup stats; 31 32 /** 33 * @hidden 34 * Internal use only. 35 */ TransactionStats(StatGroup stats)36 public TransactionStats(StatGroup stats) { 37 this.stats = stats; 38 } 39 40 /** 41 * The Active class represents an active transaction. 42 */ 43 public static class Active implements Serializable { 44 45 private static final long serialVersionUID = 1286693589L; 46 47 /** 48 * The transaction ID of the transaction. 49 */ 50 private long txnId; 51 52 /** 53 * The transaction ID of the parent transaction (or 0, if no parent). 54 */ 55 private long parentId; 56 57 /** 58 * The transaction name, including the thread name if available. 59 */ 60 private String name; 61 62 /** 63 * The transaction ID of the transaction. 64 */ getId()65 public long getId() { 66 return txnId; 67 } 68 69 /** 70 * The transaction ID of the parent transaction (or 0, if no parent). 71 */ getParentId()72 public long getParentId() { 73 return parentId; 74 } 75 76 /** 77 * The transaction name, including the thread name if available. 78 */ getName()79 public String getName() { 80 return name; 81 } 82 83 /** 84 * @hidden 85 * Internal use only. 86 */ Active(String name, long txnId, long parentId)87 public Active(String name, long txnId, long parentId) { 88 this.name = name; 89 this.txnId = txnId; 90 this.parentId = parentId; 91 } 92 93 @Override toString()94 public String toString() { 95 return "txnId = " + txnId + " txnName = " + name; 96 } 97 } 98 99 /** 100 * Return the array of active transactions. 101 * 102 * @return The array of active transactions. 103 */ getActiveTxns()104 public Active[] getActiveTxns() { 105 return stats.getActiveTxnArray(TXN_ACTIVE_TXNS); 106 } 107 108 /** 109 * The number of transactions that have aborted. 110 */ getNAborts()111 public long getNAborts() { 112 return stats.getLong(TXN_ABORTS); 113 } 114 115 /** 116 * The number of XA transactions that have aborted. 117 */ getNXAAborts()118 public long getNXAAborts() { 119 return stats.getLong(TXN_XAABORTS); 120 } 121 122 /** 123 * The number of XA transactions that have been prepared. 124 */ getNXAPrepares()125 public long getNXAPrepares() { 126 return stats.getLong(TXN_XAPREPARES); 127 } 128 129 /** 130 * The number of transactions that are currently active. 131 */ getNActive()132 public int getNActive() { 133 return stats.getInt(TXN_ACTIVE); 134 } 135 136 /** 137 * The number of transactions that have begun. 138 */ getNBegins()139 public long getNBegins() { 140 return stats.getLong(TXN_BEGINS); 141 } 142 143 /** 144 * The number of transactions that have committed. 145 */ getNCommits()146 public long getNCommits() { 147 return stats.getLong(TXN_COMMITS); 148 } 149 150 /** 151 * The number of XA transactions that have committed. 152 */ getNXACommits()153 public long getNXACommits() { 154 return stats.getLong(TXN_XACOMMITS); 155 } 156 157 /** 158 * {@inheritDoc} 159 */ 160 @Override toString()161 public String toString() { 162 return stats.toString(); 163 } 164 toStringVerbose()165 public String toStringVerbose() { 166 return stats.toStringVerbose(); 167 } 168 } 169