public class ReplicaSetConnection extends AbstractProxyConnection
Connection
implementation for connecting to a replica-set
environment.AbstractProxyConnection.ProxiedChangeListener
Modifier and Type | Field and Description |
---|---|
protected static Logger |
LOG
The logger for the
ReplicaSetConnectionFactory . |
myConfig
COMMAND_COLLECTION, OPEN_PROP_NAME
Constructor and Description |
---|
ReplicaSetConnection(Connection proxiedConnection,
ServerState server,
ClusterState cluster,
ProxiedConnectionFactory factory,
MongoDbConfiguration config)
Creates a new
ReplicaSetConnection . |
Modifier and Type | Method and Description |
---|---|
protected List<ServerState> |
findPotentialServers(Message... messages)
Locates the set of servers that can be used to send the specified
messages.
|
String |
send(Callback<Reply> reply,
Message... messages)
Sends a message on the connection.
|
String |
toString() |
protected String |
trySend(List<ServerState> servers,
Callback<Reply> reply,
Message... messages)
Tries to send the messages to the first server with either an open
connection or that we can open a connection to.
|
protected String |
trySendToOpenConnection(List<ServerState> servers,
Callback<Reply> reply,
Message... messages)
Tries to send the messages to the first server with an open connection.
|
addPending, addPropertyChangeListener, close, drainPending, flush, getPendingCount, getProxiedConnection, isIdle, isOpen, onExceptin, raiseErrors, removePropertyChangeListener, shutdown, waitForClosed
protected static final Logger LOG
ReplicaSetConnectionFactory
.public ReplicaSetConnection(Connection proxiedConnection, ServerState server, ClusterState cluster, ProxiedConnectionFactory factory, MongoDbConfiguration config)
ReplicaSetConnection
.proxiedConnection
- The connection being proxied.server
- The primary server this connection is connected to.cluster
- The state of the cluster for finding secondary connections.factory
- The connection factory for opening secondary connections.config
- The MongoDB client configuration.public String send(Callback<Reply> reply, Message... messages) throws MongoDbException
Forwards the call to the proxied Connection
.
Locates all of the potential servers that can receive all of the messages. Tries to then send the messages to a server with a connection already open or failing that tries to open a connection to open of the servers.
send
in interface Connection
send
in class AbstractProxyConnection
reply
- The callback to notify of responses to the messages. May be
null
.messages
- The messages to send on the connection. The messages will be
sent one after the other and are guaranteed to be contiguous
and have sequential message ids.MongoDbException
- On an error sending the message.public String toString()
Overridden to return the socket information.
protected List<ServerState> findPotentialServers(Message... messages) throws MongoDbException
messages
- The messages to be sent.MongoDbException
- On a failure to locate a server that all messages can be sent
to.protected String trySend(List<ServerState> servers, Callback<Reply> reply, Message... messages)
servers
- The servers the messages can be sent to.reply
- The callback for the replies.messages
- The messages to send.null
if the messages could not be sent.protected String trySendToOpenConnection(List<ServerState> servers, Callback<Reply> reply, Message... messages)
servers
- The servers the messages can be sent to.reply
- The callback for the replies.messages
- The messages to send.null
if the messages could not be sent.Copyright © 2011-2012 Allanbank Consulting, Inc.. All Rights Reserved.