public class ClientImpl extends AbstractClient
Client
interface which all requests to
the MongoDB servers pass.Modifier and Type | Class and Description |
---|---|
protected class |
ClientImpl.ConnectionListener
ConnectionListener provides the call back for events occurring on a
connection.
|
Modifier and Type | Field and Description |
---|---|
protected static Logger |
LOG
The logger for the
ClientImpl . |
static int |
MAX_CONNECTION_SCAN
The maximum number of connections to scan looking for idle/lightly used
connections.
|
MAX_DOCUMENT_SIZE
Constructor and Description |
---|
ClientImpl(MongoClientConfiguration config)
Create a new ClientImpl.
|
ClientImpl(MongoClientConfiguration config,
ConnectionFactory connectionFactory)
Create a new ClientImpl.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the client.
|
protected Connection |
findConnection(Message message1,
Message message2)
Locates a
Connection to send a message on. |
ClusterType |
getClusterType()
Returns the type of cluster the client is connected to.
|
MongoClientConfiguration |
getConfig()
Returns the configuration being used by the logical MongoDB connection.
|
int |
getConnectionCount()
Returns the current number of open connections.
|
Durability |
getDefaultDurability()
Returns the
Durability from the MongoClientConfiguration . |
ReadPreference |
getDefaultReadPreference()
Returns the
ReadPreference from the
MongoClientConfiguration . |
protected void |
handleConnectionClosed(Connection connection)
Tries to reconnect previously open
Connection s. |
boolean |
isCursorDocument(Document doc)
Returns true if the document looks like a cursor restart document.
|
protected void |
reconnect(Connection connection)
Runs the reconnect logic for the connection.
|
MongoIterator<Document> |
restart(DocumentAssignable cursorDocument)
Restarts an iterator that was previously saved.
|
MongoCursorControl |
restart(StreamCallback<Document> results,
DocumentAssignable cursorDocument)
Restarts a document stream from a cursor that was previously saved.
|
protected Connection |
searchConnection(Message message1,
Message message2,
boolean waitForReconnect)
Searches for a connection to use.
|
send, send
public static final int MAX_CONNECTION_SCAN
protected static final Logger LOG
ClientImpl
.public ClientImpl(MongoClientConfiguration config)
config
- The configuration for interacting with MongoDB.public ClientImpl(MongoClientConfiguration config, ConnectionFactory connectionFactory)
config
- The configuration for interacting with MongoDB.connectionFactory
- The source of connection for the client.public void close()
Overridden to close all of the open connections.
Overridden to close all of the open connections.
close
in interface Client
close
in class AbstractClient
Closeable.close()
public ClusterType getClusterType()
Overridden to return the ClusterType
of the
ConnectionFactory
.
public MongoClientConfiguration getConfig()
Overridden to return the configuration used when the client was constructed.
public int getConnectionCount()
public Durability getDefaultDurability()
Durability
from the MongoClientConfiguration
.
Overridden to return the configurations default durability.
MongoClientConfiguration
.Client.getDefaultDurability()
public ReadPreference getDefaultReadPreference()
ReadPreference
from the
MongoClientConfiguration
.
Overridden to return the configurations default read preference.
MongoClientConfiguration
.Client.getDefaultReadPreference()
public boolean isCursorDocument(Document doc)
MongoIteratorImpl.asDocument()
.doc
- The potential cursor document.MongoIteratorImpl.asDocument()
.public MongoIterator<Document> restart(DocumentAssignable cursorDocument) throws IllegalArgumentException
cursorDocument
- The document containing the state of the cursor.IllegalArgumentException
- If the document does not contain a valid cursor state.public MongoCursorControl restart(StreamCallback<Document> results, DocumentAssignable cursorDocument) throws IllegalArgumentException
results
- Callback that will be notified of the results of the cursor.cursorDocument
- The document containing the state of the cursor.MongoCursorControl
to control the cursor streaming
documents to the caller. This includes the ability to stop the
cursor and persist its state.IllegalArgumentException
- If the document does not contain a valid cursor state.protected Connection findConnection(Message message1, Message message2) throws MongoDbException
Connection
to send a message on.
Tries to locate a connection that can quickly dispatch the message to a MongoDB server. The basic metrics for determining if a connection is idle is to look at the number of messages waiting to be sent. The basic logic for finding a connection is:
findConnection
in class AbstractClient
message1
- The first message that will be sent. The connection return
should be compatible with all of the messages
ReadPreference
.message2
- The second message that will be sent. The connection return
should be compatible with all of the messages
ReadPreference
. May be null
.Connection
to send a message on.MongoDbException
- In the case of an error finding a Connection
.protected void handleConnectionClosed(Connection connection)
Connection
s. If a connection
was being closed then cleans up the remaining state.connection
- The connection that was closed.protected void reconnect(Connection connection)
connection
- The connection to reconnect.protected Connection searchConnection(Message message1, Message message2, boolean waitForReconnect) throws MongoDbException
Tries to locate a connection that can quickly dispatch the message to a MongoDB server. The basic metrics for determining if a connection is idle is to look at the number of messages waiting to be sent. The basic logic for finding a connection is:
message1
- The first message that will be sent. The connection return
should be compatible with all of the messages
ReadPreference
.message2
- The second message that will be sent. The connection return
should be compatible with all of the messages
ReadPreference
. May be null
.waitForReconnect
- If true then the search will block while there is an active
reconnect attempt.Connection
to send a message on.MongoDbException
- In the case of an error finding a Connection
.Copyright © 2011-2013 Allanbank Consulting, Inc.. All Rights Reserved.