Skip to content

Commit 8d0e704

Browse files
committed
JAVA-641: Added MongoOptions property to control whether driver always uses MBeans. The default is false, in which case the driver will use MXBeans on Java 6 or greater
1 parent cda348f commit 8d0e704

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/main/com/mongodb/DBPortPool.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ DBPortPool get( ServerAddress addr ){
100100
}
101101

102102
private DBPortPool createPool(final ServerAddress addr) {
103-
if (isJava5) {
103+
if (isJava5 || _options.isAlwaysUseMBeans()) {
104104
return new Java5MongoConnectionPool(addr, _options);
105105
} else {
106106
return new MongoConnectionPool(addr, _options);

src/main/com/mongodb/MongoOptions.java

+29-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public void reset(){
5151
socketFactory = SocketFactory.getDefault();
5252
description = null;
5353
cursorFinalizerEnabled = true;
54+
alwaysUseMBeans = false;
5455
}
5556

5657
public MongoOptions copy() {
@@ -75,6 +76,7 @@ public MongoOptions copy() {
7576
m.socketFactory = socketFactory;
7677
m.description = description;
7778
m.cursorFinalizerEnabled = cursorFinalizerEnabled;
79+
m.alwaysUseMBeans = alwaysUseMBeans;
7880
return m;
7981
}
8082

@@ -236,7 +238,15 @@ else if (safe)
236238
*/
237239
public boolean cursorFinalizerEnabled;
238240

239-
241+
/**
242+
* Sets whether JMX beans registered by the driver should always be MBeans, regardless of whether the VM is
243+
* Java 6 or greater. If false, the driver will use MXBeans if the VM is Java 6 or greater, and use MBeans if
244+
* the VM is Java 5.
245+
* <p>
246+
* Default is false.
247+
* </p>
248+
*/
249+
public boolean alwaysUseMBeans;
240250

241251
public String toString(){
242252
StringBuilder buf = new StringBuilder();
@@ -258,7 +268,8 @@ public String toString(){
258268
buf.append( "wtimeout=" ).append( wtimeout ).append( ", " );
259269
buf.append( "fsync=" ).append( fsync ).append( ", " );
260270
buf.append( "j=" ).append(j).append( ", " );
261-
buf.append( "cursorFinalizerEnabled=").append( cursorFinalizerEnabled);
271+
buf.append( "cursorFinalizerEnabled=").append(cursorFinalizerEnabled).append( ", " );
272+
buf.append( "alwaysUseMBeans=").append(alwaysUseMBeans);
262273

263274
return buf.toString();
264275
}
@@ -568,4 +579,20 @@ public boolean isCursorFinalizerEnabled() {
568579
public void setCursorFinalizerEnabled(final boolean cursorFinalizerEnabled) {
569580
this.cursorFinalizerEnabled = cursorFinalizerEnabled;
570581
}
582+
583+
/**
584+
*
585+
* @return true if the driver should always use MBeans, regardless of VM
586+
*/
587+
public boolean isAlwaysUseMBeans() {
588+
return alwaysUseMBeans;
589+
}
590+
591+
/**
592+
*
593+
* @param alwaysUseMBeans sets whether the driver should always use MBeans, regardless of VM
594+
*/
595+
public void setAlwaysUseMBeans(final boolean alwaysUseMBeans) {
596+
this.alwaysUseMBeans = alwaysUseMBeans;
597+
}
571598
}

0 commit comments

Comments
 (0)