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.management;
06:
07: import com.tc.net.groups.NodeID;
08: import com.tc.properties.TCProperties;
09: import com.tc.properties.TCPropertiesImpl;
10:
11: import java.util.HashSet;
12: import java.util.Set;
13:
14: public class ClientLockStatContext {
15: private final static int DEFAULT_DEPTH = 1;
16: private final static int DEFAULT_COLLECT_FREQUENCY = 10;
17:
18: private int collectFrequency;
19: private int stackTraceDepth = 0;
20: private int nextCollectTimer = 0;
21: private Set statEnabledClients = new HashSet();
22:
23: public ClientLockStatContext() {
24: TCProperties tcProperties = TCPropertiesImpl.getProperties()
25: .getPropertiesFor("l1.lock.stacktrace");
26: if (tcProperties != null) {
27: this .stackTraceDepth = tcProperties.getInt("defaultDepth",
28: DEFAULT_DEPTH);
29: }
30: tcProperties = TCPropertiesImpl.getProperties()
31: .getPropertiesFor("l1.lock");
32: if (tcProperties != null) {
33: this .collectFrequency = tcProperties.getInt(
34: "collectFrequency", DEFAULT_COLLECT_FREQUENCY);
35: }
36: }
37:
38: public ClientLockStatContext(int collectFrequency,
39: int stackTraceDepth) {
40: this .collectFrequency = collectFrequency;
41: this .stackTraceDepth = stackTraceDepth;
42: }
43:
44: public int getCollectFrequency() {
45: return collectFrequency;
46: }
47:
48: public void setCollectFrequency(int collectFrequency) {
49: this .collectFrequency = collectFrequency;
50: }
51:
52: public int getStackTraceDepth() {
53: return stackTraceDepth;
54: }
55:
56: public void setStackTraceDepth(int stackTraceDepth) {
57: this .stackTraceDepth = stackTraceDepth;
58: }
59:
60: public void addClient(NodeID nodeID) {
61: statEnabledClients.add(nodeID);
62: }
63:
64: public boolean isClientLockStatEnabled(NodeID nodeID) {
65: return statEnabledClients.contains(nodeID);
66: }
67:
68: public Set getStatEnabledClients() {
69: return statEnabledClients;
70: }
71:
72: public boolean shouldRecordStackTrace() {
73: return this .nextCollectTimer == 0;
74: }
75:
76: public void updateCollectTimer() {
77: if (collectFrequency > 0) {
78: this .nextCollectTimer = (this .nextCollectTimer + 1)
79: % collectFrequency;
80: }
81: }
82: }
|