com.mongodb
Class DBTCPConnector

java.lang.Object
  extended by com.mongodb.DBTCPConnector
All Implemented Interfaces:
DBConnector

public class DBTCPConnector
extends Object
implements DBConnector


Constructor Summary
DBTCPConnector(Mongo m, List<ServerAddress> all)
           
DBTCPConnector(Mongo m, ServerAddress... all)
           
DBTCPConnector(Mongo m, ServerAddress addr)
           
 
Method Summary
 com.mongodb.Response call(DB db, DBCollection coll, com.mongodb.OutMessage m, ServerAddress hostNeeded, DBDecoder decoder)
          does a read operation on the database
 com.mongodb.Response call(DB db, DBCollection coll, com.mongodb.OutMessage m, ServerAddress hostNeeded, int retries)
          does a read operation on the database
 com.mongodb.Response call(DB db, DBCollection coll, com.mongodb.OutMessage m, ServerAddress hostNeeded, int retries, ReadPreference readPref, DBDecoder decoder)
          does a read operation on the database
 void close()
           
 String debugString()
           
 ServerAddress getAddress()
           
 List<ServerAddress> getAllAddress()
          Gets the list of seed server addresses
 String getConnectPoint()
           
 DBPortPool getDBPortPool(ServerAddress addr)
          Gets the DBPortPool associated with a ServerAddress.
 int getMaxBsonObjectSize()
          Gets the maximum size for a BSON object supported by the current master server.
 ReplicaSetStatus getReplicaSetStatus()
           
 List<ServerAddress> getServerAddressList()
          Gets the list of server addresses currently seen by the connector.
 boolean isOpen()
          returns true if the connector is in a usable state
 void requestDone()
          End the current "request", if this thread is in one.
 void requestEnsureConnection()
          Ensures that a connection exists for the "consistent request"
 void requestStart()
          Start a "request".
 WriteResult say(DB db, com.mongodb.OutMessage m, WriteConcern concern)
          does a write operation
 WriteResult say(DB db, com.mongodb.OutMessage m, WriteConcern concern, ServerAddress hostNeeded)
          does a write operation
 void start()
           
 void updatePortPool(ServerAddress addr)
          Assigns a new DBPortPool for a given ServerAddress.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DBTCPConnector

public DBTCPConnector(Mongo m,
                      ServerAddress addr)
               throws MongoException
Throws:
MongoException

DBTCPConnector

public DBTCPConnector(Mongo m,
                      ServerAddress... all)
               throws MongoException
Throws:
MongoException

DBTCPConnector

public DBTCPConnector(Mongo m,
                      List<ServerAddress> all)
               throws MongoException
Throws:
MongoException
Method Detail

start

public void start()

requestStart

public void requestStart()
Start a "request". A "request" is a group of operations in which order matters. Examples include inserting a document and then performing a query which expects that document to have been inserted, or performing an operation and then using com.mongodb.Mongo.getLastError to perform error-checking on that operation. When a thread performs operations in a "request", all operations will be performed on the same socket, so they will be correctly ordered.

Specified by:
requestStart in interface DBConnector

requestDone

public void requestDone()
End the current "request", if this thread is in one. By ending a request when it is safe to do so the built-in connection- pool is allowed to reassign requests to different sockets in order to more effectively balance load. See requestStart for more information.

Specified by:
requestDone in interface DBConnector

requestEnsureConnection

public void requestEnsureConnection()
Description copied from interface: DBConnector
Ensures that a connection exists for the "consistent request"

Specified by:
requestEnsureConnection in interface DBConnector

say

public WriteResult say(DB db,
                       com.mongodb.OutMessage m,
                       WriteConcern concern)
                throws MongoException
Description copied from interface: DBConnector
does a write operation

Specified by:
say in interface DBConnector
Parameters:
db - the database
m - the request message
concern - the write concern
Returns:
the write result
Throws:
MongoException

say

public WriteResult say(DB db,
                       com.mongodb.OutMessage m,
                       WriteConcern concern,
                       ServerAddress hostNeeded)
                throws MongoException
Description copied from interface: DBConnector
does a write operation

Specified by:
say in interface DBConnector
Parameters:
db - the database
m - the request message
concern - the write concern
hostNeeded - specific server to connect to
Returns:
the write result
Throws:
MongoException

call

public com.mongodb.Response call(DB db,
                                 DBCollection coll,
                                 com.mongodb.OutMessage m,
                                 ServerAddress hostNeeded,
                                 DBDecoder decoder)
                          throws MongoException
Description copied from interface: DBConnector
does a read operation on the database

Specified by:
call in interface DBConnector
Parameters:
db - the database
coll - the collection
m - the request message
hostNeeded - specific server to connect to
decoder - the decoder to use
Returns:
the read result
Throws:
MongoException

call

public com.mongodb.Response call(DB db,
                                 DBCollection coll,
                                 com.mongodb.OutMessage m,
                                 ServerAddress hostNeeded,
                                 int retries)
                          throws MongoException
Description copied from interface: DBConnector
does a read operation on the database

Specified by:
call in interface DBConnector
Parameters:
db - the database
coll - the collection
m - the request message
hostNeeded - specific server to connect to
retries - the number of retries in case of an error
Returns:
the read result
Throws:
MongoException

call

public com.mongodb.Response call(DB db,
                                 DBCollection coll,
                                 com.mongodb.OutMessage m,
                                 ServerAddress hostNeeded,
                                 int retries,
                                 ReadPreference readPref,
                                 DBDecoder decoder)
                          throws MongoException
Description copied from interface: DBConnector
does a read operation on the database

Specified by:
call in interface DBConnector
Parameters:
db - the database
coll - the collection
m - the request message
hostNeeded - specific server to connect to
retries - number of retries in case of error
readPref - the read preferences
decoder - the decoder to use
Returns:
the read result
Throws:
MongoException

getAddress

public ServerAddress getAddress()

getAllAddress

public List<ServerAddress> getAllAddress()
Gets the list of seed server addresses

Returns:

getServerAddressList

public List<ServerAddress> getServerAddressList()
Gets the list of server addresses currently seen by the connector. This includes addresses auto-discovered from a replica set.

Returns:

getReplicaSetStatus

public ReplicaSetStatus getReplicaSetStatus()

getConnectPoint

public String getConnectPoint()

debugString

public String debugString()

close

public void close()

updatePortPool

public void updatePortPool(ServerAddress addr)
Assigns a new DBPortPool for a given ServerAddress. This is used to obtain a new pool when the resolved IP of a host changes, for example. User application should not have to call this method directly.

Parameters:
addr -

getDBPortPool

public DBPortPool getDBPortPool(ServerAddress addr)
Gets the DBPortPool associated with a ServerAddress.

Parameters:
addr -
Returns:

isOpen

public boolean isOpen()
Description copied from interface: DBConnector
returns true if the connector is in a usable state

Specified by:
isOpen in interface DBConnector
Returns:

getMaxBsonObjectSize

public int getMaxBsonObjectSize()
Gets the maximum size for a BSON object supported by the current master server. Note that this value may change over time depending on which server is master.

Returns:
the maximum size, or 0 if not obtained from servers yet.