1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.jboss.managed;
25
26 import java.util.concurrent.TimeUnit;
27 import org.jboss.managed.api.ManagedOperation.Impact;
28 import org.jboss.managed.api.annotation.ManagementComponent;
29 import org.jboss.managed.api.annotation.ManagementObject;
30 import org.jboss.managed.api.annotation.ManagementOperation;
31 import org.jboss.managed.api.annotation.ManagementProperties;
32 import org.jboss.managed.api.annotation.ManagementProperty;
33 import org.jboss.managed.api.annotation.ViewUse;
34 import org.modeshape.common.util.CheckArg;
35 import org.modeshape.graph.connector.RepositoryConnectionPool;
36
37
38
39
40
41 @ManagementObject( name = "ModeShapeConnectionPool", description = "A ModeShape repository connection pool", componentType = @ManagementComponent( type = "ModeShape", subtype = "ConnectionPool" ), properties = ManagementProperties.EXPLICIT )
42 public final class ManagedConnectionPool implements ModeShapeManagedObject {
43
44
45
46
47 private final RepositoryConnectionPool connectionPool;
48
49
50
51
52
53
54 public ManagedConnectionPool( RepositoryConnectionPool connectionPool ) {
55 CheckArg.isNotNull(connectionPool, "connectionPool");
56 this.connectionPool = connectionPool;
57 }
58
59
60
61
62
63
64 @ManagementOperation( description = "Removes all in-use connections from the pool", impact = Impact.WriteOnly )
65 public boolean flush() {
66
67 return false;
68 }
69
70
71
72
73
74
75 @ManagementProperty( name = "Available Connections", description = "The number of available connections", readOnly = true, use = ViewUse.STATISTIC )
76 public int getAvailableCount() {
77 return getMaxSize() - getSize();
78 }
79
80
81
82
83
84
85 @ManagementProperty( name = "Connections Created", description = "The number of connections that have been created", readOnly = true, use = ViewUse.STATISTIC )
86 public long getCreatedCount() {
87 return this.connectionPool.getTotalConnectionsCreated();
88 }
89
90
91
92
93
94
95 @ManagementProperty( name = "Connections Destroyed", description = "The number of connections that have been destroyed", readOnly = true, use = ViewUse.STATISTIC )
96 public long getDestroyedCount() {
97
98 return this.connectionPool.getTotalConnectionsCreated() - getSize();
99 }
100
101
102
103
104
105
106 @ManagementProperty( name = "Connections In-use", description = "The number of connections currently being used", readOnly = true, use = ViewUse.STATISTIC )
107 public int getInUseCount() {
108 return this.connectionPool.getInUseCount();
109 }
110
111 @ManagementProperty( name = "In-use High Water Mark", description = "The in-use high water mark", readOnly = true, use = ViewUse.STATISTIC )
112 public int getInUseHighWaterMark() {
113
114 return 0;
115 }
116
117
118
119
120
121
122 @ManagementProperty( name = "Keep Alive Time", description = "The time in nanonseconds to keep an idle connection alive", readOnly = false, use = ViewUse.RUNTIME )
123 public long getKeepAliveTime() {
124 return this.connectionPool.getKeepAliveTime(TimeUnit.NANOSECONDS);
125 }
126
127
128
129
130
131
132
133 @ManagementProperty( name = "Max Failed Attempts Before Error", description = "The number of failed attempts to establish a connection before throwing an error", readOnly = false, use = ViewUse.RUNTIME )
134 public int getMaxFailedAttemptsBeforeError() {
135 return this.connectionPool.getMaxFailedAttemptsBeforeError();
136 }
137
138
139
140
141
142
143 @ManagementProperty( name = "Max size", description = "The maximum number of connections allowed", readOnly = false, use = ViewUse.RUNTIME )
144 public int getMaxSize() {
145 return this.connectionPool.getMaximumPoolSize();
146 }
147
148 @ManagementProperty( name = "Min size", description = "The minimum number of connections allowed", readOnly = true, use = ViewUse.CONFIGURATION )
149 public int getMinSize() {
150
151 return 0;
152 }
153
154
155
156
157
158
159 @ManagementProperty( name = "Ping Timeout", description = "The time in nanoseconds that ping should wait before timing out and failing", readOnly = false, use = ViewUse.RUNTIME )
160 public long getPingTimeout() {
161 return this.connectionPool.getPingTimeoutInNanos();
162 }
163
164
165
166
167
168
169 @ManagementProperty( name = "Total Connections", description = "The total number of connections (in use and available)", readOnly = true, use = ViewUse.STATISTIC )
170 public int getSize() {
171 return this.connectionPool.getCorePoolSize();
172 }
173
174
175
176
177
178
179 @ManagementProperty( name = "Validate Before Use", description = "Indicates if connections should be validated before being used", readOnly = false, use = ViewUse.RUNTIME )
180 public boolean getValidateConnectionBeforeUse() {
181 return this.connectionPool.getValidateConnectionBeforeUse();
182 }
183
184
185
186
187
188
189 public void setKeepAliveTime( long nanos ) {
190 CheckArg.isNonNegative(nanos, "nanos");
191 this.connectionPool.setKeepAliveTime(nanos, TimeUnit.NANOSECONDS);
192 }
193
194
195
196
197
198
199 public void setMaxFailedAttemptsBeforeError( int attempts ) {
200 CheckArg.isNonNegative(attempts, "attempts");
201 this.connectionPool.setMaxFailedAttemptsBeforeError(attempts);
202 }
203
204
205
206
207
208
209 public void setSize( int size ) {
210 CheckArg.isPositive(size, "size");
211 this.connectionPool.setMaximumPoolSize(size);
212 }
213
214
215
216
217
218
219 public void setPingTimout( long nanos ) {
220 CheckArg.isNonNegative(nanos, "nanos");
221 this.connectionPool.setPingTimeout(nanos, TimeUnit.NANOSECONDS);
222 }
223
224
225
226
227
228
229 public void setValidateConnectionBeforeUse( boolean validate ) {
230 this.connectionPool.setValidateConnectionBeforeUse(validate);
231 }
232
233 }