2727import java .util .concurrent .Semaphore ;
2828import java .util .concurrent .TimeUnit ;
2929
30- import javax .management .Attribute ;
31- import javax .management .AttributeList ;
32- import javax .management .DynamicMBean ;
33- import javax .management .MBeanAttributeInfo ;
34- import javax .management .MBeanInfo ;
35-
36- public abstract class SimplePool <T > implements DynamicMBean {
30+ public abstract class SimplePool <T > implements SimplePoolMBean {
3731
3832 static final boolean TRACK_LEAKS = Boolean .getBoolean ( "MONGO-TRACKLEAKS" );
3933 static final long _sleepTime = 2 ;
@@ -57,15 +51,6 @@ public SimplePool( String name , int maxToKeep , int maxTotal , boolean trackLea
5751 _maxTotal = maxTotal ;
5852 _trackLeaks = trackLeaks || TRACK_LEAKS ;
5953 _debug = debug ;
60- _mbeanInfo = new MBeanInfo ( this .getClass ().getName () , _name ,
61- new MBeanAttributeInfo []{
62- new MBeanAttributeInfo ( "name" , "java.lang.String" , "name of pool" , true , false , false ) ,
63- new MBeanAttributeInfo ( "size" , "java.lang.Integer" , "total size of pool" , true , false , false ) ,
64- new MBeanAttributeInfo ( "available" , "java.lang.Integer" , "total connections available" , true , false , false ) ,
65- new MBeanAttributeInfo ( "inUse" , "java.lang.Integer" , "number connections in use right now" , true , false , false ) ,
66- new MBeanAttributeInfo ( "everCreated" , "java.lang.Integer" , "number connections ever created" , true , false , false )
67- } , null , null , null );
68-
6954 }
7055
7156 /** Creates a new object of this pool's type.
@@ -255,25 +240,33 @@ protected void clear(){
255240 }
256241 }
257242
258- public int total (){
243+ @ Override
244+ public String getName () {
245+ return _name ;
246+ }
247+
248+ @ Override
249+ public int getTotal (){
259250 return _all .size ();
260251 }
261252
262- public int inUse (){
253+ @ Override
254+ public int getInUse (){
263255 return _all .size () - _avail .size ();
264256 }
265257
266258 public Iterator <T > getAll (){
267259 return _all .getAll ().iterator ();
268260 }
269261
270- public int available (){
262+ public int getAvailable (){
271263 if ( _maxTotal <= 0 )
272264 throw new IllegalStateException ( "this pool has an infinite number of things available" );
273- return _maxTotal - inUse ();
265+ return _maxTotal - getInUse ();
274266 }
275267
276- public int everCreated (){
268+ @ Override
269+ public int getEverCreated (){
277270 return _everCreated ;
278271 }
279272
@@ -282,52 +275,11 @@ private void _debug( String msg ){
282275 System .out .println ( "SimplePool [" + _name + "] : " + msg );
283276 }
284277
285- public int maxToKeep (){
278+ @ Override
279+ public int getSize (){
286280 return _maxToKeep ;
287281 }
288282
289- public Object getAttribute (String attribute ){
290- if ( attribute .equals ( "name" ) )
291- return _name ;
292- if ( attribute .equals ( "size" ) )
293- return _maxToKeep ;
294- if ( attribute .equals ( "available" ) )
295- return available ();
296- if ( attribute .equals ( "inUse" ) )
297- return inUse ();
298- if ( attribute .equals ( "everCreated" ) )
299- return _everCreated ;
300-
301- System .err .println ( "com.mongo.util.SimplePool unknown attribute: " + attribute );
302- throw new RuntimeException ( "unknown attribute: " + attribute );
303- }
304-
305- public AttributeList getAttributes (String [] attributes ){
306- AttributeList l = new AttributeList ();
307- for ( int i =0 ; i <attributes .length ; i ++ ){
308- String name = attributes [i ];
309- l .add ( new Attribute ( name , getAttribute ( name ) ) );
310- }
311- return l ;
312- }
313-
314- public MBeanInfo getMBeanInfo (){
315- return _mbeanInfo ;
316- }
317-
318- public Object invoke (String actionName , Object [] params , String [] signature ){
319- throw new RuntimeException ( "not allowed to invoke anything" );
320- }
321-
322- public void setAttribute (Attribute attribute ){
323- throw new RuntimeException ( "not allowed to set anything" );
324- }
325-
326- public AttributeList setAttributes (AttributeList attributes ){
327- throw new RuntimeException ( "not allowed to set anything" );
328- }
329-
330-
331283 public String toString (){
332284 StringBuilder buf = new StringBuilder ();
333285 buf .append ( "pool: " ).append ( _name )
@@ -345,7 +297,6 @@ public String toString(){
345297 protected final int _maxTotal ;
346298 protected final boolean _trackLeaks ;
347299 protected final boolean _debug ;
348- protected final MBeanInfo _mbeanInfo ;
349300
350301 private final List <T > _avail = new ArrayList <T >();
351302 protected final List <T > _availSafe = Collections .unmodifiableList ( _avail );
0 commit comments