1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax;
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 import java.util.HashMap;
44 import org.metricshub.wbem.sblim.cimclient.internal.cimxml.sax.node.Node;
45
46
47
48
49
50 public class NodePool {
51 private HashMap<String, PoolStack> iPoolMap = new HashMap<String, PoolStack>(512);
52
53 private int iHitCnt = 0;
54
55 private int iMissCnt = 0;
56
57
58
59
60
61
62 public void addNode(Node pNode) {
63 PoolStack ps = this.iPoolMap.get(pNode.getNodeName());
64 if (ps == null) {
65 this.iPoolMap.put(pNode.getNodeName(), new PoolStack(pNode));
66 return;
67 }
68 ps.put(pNode);
69 }
70
71
72
73
74
75
76
77 public Node getNode(String pNodeName) {
78 PoolStack ps = this.iPoolMap.get(pNodeName);
79 if (ps == null) {
80 ++this.iMissCnt;
81 return null;
82 }
83 Node node = ps.get();
84 if (node == null) ++this.iMissCnt; else ++this.iHitCnt;
85 return node;
86 }
87
88
89
90
91
92
93 public int getHitCnt() {
94 return this.iHitCnt;
95 }
96
97
98
99
100
101
102 public int getMissCnt() {
103 return this.iMissCnt;
104 }
105 }
106
107 class PoolStack {
108 private static final int CAPACITY = 8, MAX_USECNT = CAPACITY - 1, MAX_IDX = MAX_USECNT;
109
110 private Node[] iNodeA = new Node[CAPACITY];
111
112 private int iIdx = 0, iUseCnt = 0;
113
114
115
116
117
118
119 public PoolStack(Node pNode) {
120 put(pNode);
121 }
122
123
124
125
126
127
128 public void put(Node pNode) {
129 if (this.iUseCnt < MAX_USECNT) ++this.iUseCnt;
130 this.iNodeA[this.iIdx] = pNode;
131 incIdx();
132 }
133
134
135
136
137
138
139 public Node get() {
140 if (this.iUseCnt == 0) return null;
141 --this.iUseCnt;
142 decIdx();
143 return this.iNodeA[this.iIdx];
144 }
145
146 private void decIdx() {
147 this.iIdx = (this.iIdx == 0 ? MAX_IDX : this.iIdx - 1);
148 }
149
150 private void incIdx() {
151 this.iIdx = (this.iIdx == MAX_IDX ? 0 : this.iIdx + 1);
152 }
153 }