Skip to content

Commit 329c427

Browse files
committed
JAVA-613: Added some Javadoc
1 parent e6901ec commit 329c427

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ limitations under the License.
199199
<target name="javadocs" depends="compile,utilcompile" description="Generate API docs">
200200
<delete dir="docs/"/>
201201
<javadoc
202-
packagenames="com.mongodb,com.mongodb.gridfs,com.mongodb.util,org.bson,org.bson.types,org.bson.io,org.bson.util"
202+
packagenames="com.mongodb,com.mongodb.gridfs,com.mongodb.util,com.mongodb.tools,org.bson,org.bson.types,org.bson.io,org.bson.util"
203203
sourcepath="src/main/"
204204
defaultexcludes="yes"
205205
destdir="docs/mongo-java-driver"

src/main/com/mongodb/tools/ConnectionPoolStat.java

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,67 @@
3333
import java.lang.management.ManagementFactory;
3434
import java.util.Set;
3535

36+
/**
37+
* A simple class that formats Mongo Java driver connection pool statistics in an easily-accessible JSON format.
38+
* It can be used to get statistics on connection pool in the same VM by using the no-args constructor, or in any
39+
* VM by using the constructor that takes an MBeanServerConnection.
40+
* <p>
41+
* This class also exposes a command line interface modeled after mongostat. For usage, run:
42+
43+
* <pre> java -cp mongo.jar com.mongodb.util.management.jmx.ConnectionPoolStat --help}</pre>
44+
*
45+
* @mongodb.driver.manual reference/mongostat mongostat
46+
*
47+
*/
3648
public class ConnectionPoolStat {
3749

50+
/**
51+
* Use the given MBean server connection to access statistics for connection pools.
52+
*
53+
* @param mBeanConnection the MBean server to connect to
54+
*/
3855
public ConnectionPoolStat(MBeanServerConnection mBeanConnection) {
3956
this.mBeanConnection = mBeanConnection;
4057
}
4158

59+
/**
60+
* Use the platform MBean server. This is useful if you want to access statistics
61+
* for connection pools in the same virtual machine.
62+
*
63+
* @see java.lang.management.ManagementFactory#getPlatformMBeanServer()
64+
*/
4265
public ConnectionPoolStat() {
4366
this.mBeanConnection = ManagementFactory.getPlatformMBeanServer();
4467
}
4568

4669
/**
70+
* Gets the statistics for all Mongo connection pools registered with the MBean server used
71+
* by this instance. The format will always be JSON, but the specific JSON fields may change in a
72+
* future release. An example of the output, which should not be taken as a specification:
73+
*
74+
* <pre>
75+
{ pools : [
76+
{ objectName: 'com.mongodb:type=ConnectionPool,host=localhost/127.0.0.1,port=27018,instance=1',
77+
host: 'localhost', port: 27018, maxSize: 10, total: 10, inUse: 3,
78+
inUseConnections: [
79+
{ namespace: 'FindContention.test', opCode: 'OP_QUERY', query: { }, numDocuments: 1, threadName: 'pool-2-thread-19', durationMS: 843, localPort: 64062 },
80+
{ namespace: 'FindContention.test', opCode: 'OP_QUERY', query: { }, numDocuments: 1, threadName: 'pool-2-thread-1', durationMS: 4331, localPort: 64095 },
81+
{ namespace: 'FindContention.test', opCode: 'OP_QUERY', query: { }, numDocuments: 1, threadName: 'pool-2-thread-16', durationMS: 4343, localPort: 64087 }
82+
]
83+
},
84+
{ objectName: 'com.mongodb:type=ConnectionPool,host=localhost/127.0.0.1,port=27017,instance=1',
85+
host: 'localhost', port: 27017, maxSize: 10, total: 10, inUse: 2,
86+
inUseConnections: [
87+
{ namespace: 'FindContention.test', opCode: 'OP_QUERY', query: { }, numDocuments: 1, threadName: 'pool-2-thread-5', durationMS: 920, localPort: 64093 },
88+
{ namespace: 'FindContention.test', opCode: 'OP_QUERY', query: { }, numDocuments: 1, threadName: 'pool-2-thread-11', durationMS: 1468, localPort: 64068 },
89+
]
90+
}
91+
]
92+
}</pre>
4793
*
4894
* @return JSON-formatted stats for all connection pools registered in JMX
49-
* @throws Exception
95+
* @throws JMException for any JMX-related exceptions
96+
* @throws IOException for any I/O exceptions
5097
*/
5198
public String getStats() throws JMException, IOException {
5299
CharArrayWriter charArrayWriter = new CharArrayWriter();

0 commit comments

Comments
 (0)