Skip to content

Commit 49072a6

Browse files
[JAVA-318] JMX cleanup
1 parent fe66dbb commit 49072a6

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/main/com/mongodb/DBPortPool.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@
1818

1919
package com.mongodb;
2020

21-
import com.mongodb.util.*;
22-
23-
import java.io.*;
24-
import java.net.*;
21+
import java.lang.management.ManagementFactory;
2522
import java.util.*;
26-
import java.util.concurrent.*;
27-
import java.util.logging.*;
23+
import java.util.concurrent.Semaphore;
24+
import java.util.logging.Level;
2825

29-
import java.lang.management.*;
3026
import javax.management.*;
3127

28+
import com.mongodb.util.SimplePool;
29+
3230
public class DBPortPool extends SimplePool<DBPort> {
3331

3432
static class Holder {
@@ -103,7 +101,7 @@ void close(){
103101
}
104102

105103
private ObjectName createObjectName( ServerAddress addr ) throws MalformedObjectNameException {
106-
return new ObjectName( "com.mongodb:type=ConnectionPool,host=" + addr.toString().replace( ':' , '_' ) );
104+
return new ObjectName( "com.mongodb:type=ConnectionPool,host=" + addr.toString().replace( ":" , ",port=" ) + ",instance=" + hashCode() );
107105
}
108106

109107
final MongoOptions _options;
@@ -138,10 +136,10 @@ public static class ConnectionWaitTimeOut extends NoMoreConnection {
138136
// ----
139137

140138
DBPortPool( ServerAddress addr , MongoOptions options ){
141-
super( "DBPortPool-" + addr.toString() , options.connectionsPerHost , options.connectionsPerHost );
139+
super( "DBPortPool-" + addr.toString() + ", options = " + options.toString() , options.connectionsPerHost , options.connectionsPerHost );
142140
_options = options;
143141
_addr = addr;
144-
_waitingSem = new Semaphore( _options.connectionsPerHost * _options.threadsAllowedToBlockForConnectionMultiplier );
142+
_waitingSem = new Semaphore( _options.connectionsPerHost * _options.threadsAllowedToBlockForConnectionMultiplier );
145143
}
146144

147145
protected long memSize( DBPort p ){

src/main/com/mongodb/util/SimplePool.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
package com.mongodb.util;
2020

2121
import java.util.*;
22-
import java.util.concurrent.*;
22+
import java.util.concurrent.Semaphore;
23+
import java.util.concurrent.TimeUnit;
2324

24-
import java.lang.management.*;
2525
import javax.management.*;
2626

2727
public abstract class SimplePool<T> implements DynamicMBean {
@@ -48,6 +48,14 @@ public SimplePool( String name , int maxToKeep , int maxTotal , boolean trackLea
4848
_maxTotal = maxTotal;
4949
_trackLeaks = trackLeaks || TRACK_LEAKS;
5050
_debug = debug;
51+
_mbeanInfo = new MBeanInfo( this.getClass().getName() , _name ,
52+
new MBeanAttributeInfo[]{
53+
new MBeanAttributeInfo( "name" , "java.lang.String" , "name of pool" , true , false , false ) ,
54+
new MBeanAttributeInfo( "size" , "java.lang.Integer" , "total size of pool" , true , false , false ) ,
55+
new MBeanAttributeInfo( "available" , "java.lang.Integer" , "total connections available" , true , false , false ) ,
56+
new MBeanAttributeInfo( "inUse" , "java.lang.Integer" , "number connections in use right now" , true , false , false ) ,
57+
new MBeanAttributeInfo( "everCreated" , "java.lang.Integer" , "number connections ever created" , true , false , false )
58+
} , null , null , null );
5159

5260
}
5361

@@ -295,14 +303,7 @@ public AttributeList getAttributes(String[] attributes){
295303
}
296304

297305
public MBeanInfo getMBeanInfo(){
298-
return new MBeanInfo( this.getClass().getName() , _name ,
299-
new MBeanAttributeInfo[]{
300-
new MBeanAttributeInfo( "name" , "java.lang.String" , "name of pool" , true , false , false ) ,
301-
new MBeanAttributeInfo( "size" , "java.lang.Integer" , "total size of pool" , true , false , false ) ,
302-
new MBeanAttributeInfo( "available" , "java.lang.Integer" , "total connections available" , true , false , false ) ,
303-
new MBeanAttributeInfo( "inUse" , "java.lang.Integer" , "number connections in use right now" , true , false , false ) ,
304-
new MBeanAttributeInfo( "everCreated" , "java.lang.Integer" , "numbe connections ever created" , true , false , false )
305-
} , null , null , null );
306+
return _mbeanInfo;
306307
}
307308

308309
public Object invoke(String actionName, Object[] params, String[] signature){
@@ -335,6 +336,7 @@ public String toString(){
335336
protected final int _maxTotal;
336337
protected final boolean _trackLeaks;
337338
protected final boolean _debug;
339+
protected final MBeanInfo _mbeanInfo;
338340

339341
private final List<T> _avail = new ArrayList<T>();
340342
protected final List<T> _availSafe = Collections.unmodifiableList( _avail );

0 commit comments

Comments
 (0)