01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.objectserver.tx;
06:
07: import com.tc.logging.TCLogger;
08: import com.tc.net.groups.NodeID;
09: import com.tc.object.tx.ServerTransactionID;
10:
11: import java.util.Collection;
12: import java.util.Set;
13:
14: public class ServerTransactionLogger implements
15: ServerTransactionListener {
16:
17: private final TCLogger logger;
18: private final ServerTransactionManagerConfig config;
19:
20: private long outStandingTxns = 0;
21: private long last = 0;
22:
23: public ServerTransactionLogger(TCLogger logger,
24: ServerTransactionManagerConfig config) {
25: this .logger = logger;
26: this .config = config;
27: }
28:
29: public void addResentServerTransactionIDs(Collection stxIDs) {
30: logger.info("addResentTransactions: " + stxIDs);
31: }
32:
33: public void clearAllTransactionsFor(NodeID deadNode) {
34: logger.info("clearAllTransactionsFor: " + deadNode);
35: }
36:
37: public void transactionManagerStarted(Set cids) {
38: logger.info("trasactionManagerStarted: " + cids);
39: }
40:
41: public void incomingTransactions(NodeID source, Set serverTxnIDs) {
42: if (config.isVerboseLogging())
43: logger.info("incomingTransactions: " + source + ", "
44: + serverTxnIDs);
45: incrementOutStandingTxns(serverTxnIDs.size());
46: }
47:
48: private synchronized void incrementOutStandingTxns(int count) {
49: outStandingTxns += count;
50: if (needToLogStats()) {
51: logStats();
52: }
53: }
54:
55: private synchronized void decrementOutStandingTxns(int count) {
56: outStandingTxns -= count;
57: if (needToLogStats()) {
58: logStats();
59: }
60: }
61:
62: private boolean needToLogStats() {
63: if (!config.isPrintStatsEnabled())
64: return false;
65: long now = System.currentTimeMillis();
66: boolean log = (now - last) > 1000;
67: if (log) {
68: last = now;
69: }
70: return log;
71: }
72:
73: private void logStats() {
74: logger.info("Number of pending transactions in the System : "
75: + outStandingTxns);
76: }
77:
78: public void transactionApplied(ServerTransactionID stxID) {
79: if (config.isVerboseLogging())
80: logger.info("transactionApplied: " + stxID);
81: }
82:
83: public void transactionCompleted(ServerTransactionID stxID) {
84: if (config.isVerboseLogging())
85: logger.info("transactionCompleted: " + stxID);
86: decrementOutStandingTxns(1);
87: }
88:
89: }
|