1818
1919package com .mongodb ;
2020
21+ import com .mongodb .util .ThreadUtil ;
22+
2123import java .io .BufferedInputStream ;
2224import java .io .IOException ;
2325import java .io .InputStream ;
2426import java .io .OutputStream ;
2527import java .net .InetSocketAddress ;
2628import java .net .Socket ;
27- import java .util .Collections ;
2829import java .util .Map ;
29- import java .util .WeakHashMap ;
30- import java .util .concurrent .*;
30+ import java .util .concurrent .ConcurrentHashMap ;
3131import java .util .logging .Level ;
3232import java .util .logging .Logger ;
3333
34- import com .mongodb .util .ThreadUtil ;
35-
3634/**
3735 * represents a Port to the database, which is effectively a single connection to a server
3836 * Methods implemented at the port level should throw the raw exceptions like IOException,
@@ -56,7 +54,7 @@ public DBPort( ServerAddress addr ){
5654 this ( addr , null , new MongoOptions () );
5755 }
5856
59- DBPort ( ServerAddress addr , DBPortPool pool , MongoOptions options ){
57+ DBPort ( ServerAddress addr , DBPortPool pool , MongoOptions options ){
6058 _options = options ;
6159 _sa = addr ;
6260 _addr = addr .getSocketAddress ();
@@ -118,7 +116,7 @@ private synchronized Response go( OutMessage msg , DBCollection coll , boolean f
118116 try {
119117 msg .prepare ();
120118 msg .pipe ( _out );
121-
119+
122120 if ( _pool != null )
123121 _pool ._everWorked = true ;
124122
@@ -156,15 +154,10 @@ synchronized private Response findOne( String ns , DBObject q ) throws IOExcepti
156154
157155 synchronized CommandResult runCommand ( DB db , DBObject cmd ) throws IOException {
158156 Response res = findOne ( db , "$cmd" , cmd );
159- return convertToCR ( res );
160- }
161-
162- synchronized CommandResult runCommand ( String db , DBObject cmd ) throws IOException {
163- Response res = findOne ( db + ".$cmd" , cmd );
164- return convertToCR ( res );
157+ return convertToCommandResult (cmd , res );
165158 }
166159
167- private CommandResult convertToCR ( Response res ) {
160+ private CommandResult convertToCommandResult ( DBObject cmd , Response res ) {
168161 if ( res .size () == 0 )
169162 return null ;
170163 if ( res .size () > 1 )
@@ -174,7 +167,7 @@ private CommandResult convertToCR(Response res) {
174167 if ( data == null )
175168 throw new MongoInternalException ( "something is wrong, no command result" );
176169
177- CommandResult cr = new CommandResult (res .serverUsed ());
170+ CommandResult cr = new CommandResult (cmd , res .serverUsed ());
178171 cr .putAll ( data );
179172 return cr ;
180173 }
@@ -217,7 +210,7 @@ boolean _open()
217210 try {
218211 _socket = _options .socketFactory .createSocket ();
219212 _socket .connect ( _addr , _options .connectTimeout );
220-
213+
221214 _socket .setTcpNoDelay ( ! USE_NAGLE );
222215 _socket .setKeepAlive ( _options .socketKeepAlive );
223216 _socket .setSoTimeout ( _options .socketTimeout );
0 commit comments