1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.pool;
18
19
20
21
22
23
24 public class VisitTracker {
25 private int validateCount = 0;
26 private int activateCount = 0;
27 private int passivateCount = 0;
28 private boolean destroyed = false;
29 private int id = 0;
30 private Object key = null;
31
32 public VisitTracker() {
33 super();
34 reset();
35 }
36
37 public VisitTracker(int id) {
38 super();
39 this.id = id;
40 reset();
41 }
42
43 public VisitTracker(int id, Object key) {
44 super();
45 this.id = id;
46 this.key = key;
47 reset();
48 }
49
50 public boolean validate() {
51 if (destroyed) {
52 fail("attempted to validate a destroyed object");
53 }
54 validateCount++;
55 return true;
56 }
57 public void activate() {
58 if (destroyed) {
59 fail("attempted to activate a destroyed object");
60 }
61 activateCount++;
62 }
63 public void passivate() {
64 if (destroyed) {
65 fail("attempted to passivate a destroyed object");
66 }
67 passivateCount++;
68 }
69 public void reset() {
70 validateCount = 0;
71 activateCount = 0;
72 passivateCount = 0;
73 destroyed = false;
74 }
75 public void destroy() {
76 destroyed = true;
77 }
78 public int getValidateCount() {
79 return validateCount;
80 }
81 public int getActivateCount() {
82 return activateCount;
83 }
84 public int getPassivateCount() {
85 return passivateCount;
86 }
87 public boolean isDestroyed() {
88 return destroyed;
89 }
90 public int getId() {
91 return id;
92 }
93 public Object getKey() {
94 return key;
95 }
96 public String toString() {
97 return "Key: " + key + " id: " + id;
98 }
99
100 private void fail(String message) {
101 throw new IllegalStateException(message);
102 }
103 }