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