public class ShardedConnection extends AbstractProxyMultipleConnection<Server>
Connection
implementation for connecting to a sharded
environment via mongos servers.AbstractProxyMultipleConnection.ClusterAndConnectionListener
myCluster, myConfig, myEventSupport, myFactory, myLastUsedConnection, myListener, myMainKey, myOpen, myShutdown
COMMAND_COLLECTION, OPEN_PROP_NAME
Constructor and Description |
---|
ShardedConnection(Connection proxiedConnection,
Server server,
Cluster cluster,
ServerSelector selector,
ProxiedConnectionFactory factory,
MongoClientConfiguration config)
Creates a new
ShardedConnection . |
Modifier and Type | Method and Description |
---|---|
protected Connection |
connect(Server server)
Attempts to create a connection to the server, catching any exceptions
thrown.
|
protected Connection |
connection(Server server)
Returns the cached connection for the specified key.
|
protected List<Server> |
findPotentialKeys(Message message1,
Message message2)
Locates the set of servers that can be used to send the specified
messages.
|
protected String |
getConnectionType()
Returns the type of connection (for logs, etc.).
|
String |
getServerName()
Returns the name of a server the connection is currently connected to.
|
protected ConnectionInfo<Server> |
reconnectMain()
Creates a connection back to the main server for this connection.
|
addPropertyChangeListener, cacheConnection, close, createReconnectFailure, doSend, flush, getPendingCount, handleConnectionClosed, isAvailable, isIdle, isOpen, isShuttingDown, raiseErrors, removeCachedConnection, removePropertyChangeListener, send, send, shutdown, toString, trySend, updateMain, waitForClosed
public ShardedConnection(Connection proxiedConnection, Server server, Cluster cluster, ServerSelector selector, ProxiedConnectionFactory factory, MongoClientConfiguration config)
ShardedConnection
.proxiedConnection
- The connection being proxied.server
- The primary server this connection is connected to.cluster
- The state of the cluster for finding secondary connections.selector
- The selector for servers when we need to reconnect.factory
- The connection factory for opening secondary connections.config
- The MongoDB client configuration.public String getServerName()
Overridden to return the canonical name of the primary.
protected Connection connect(Server server)
cached
.
Overridden to create a connection to the server.
connect
in class AbstractProxyMultipleConnection<Server>
server
- The server to connect to.protected Connection connection(Server server)
null
.
Overridden for testing access.
connection
in class AbstractProxyMultipleConnection<Server>
server
- The server connected to.protected List<Server> findPotentialKeys(Message message1, Message message2) throws MongoDbException
findPotentialKeys
in class AbstractProxyMultipleConnection<Server>
message1
- The first message to send.message2
- The second message to send. May be null
.MongoDbException
- On a failure to locate a server that all messages can be sent
to.protected String getConnectionType()
Overridden to return the string Sharded
.
getConnectionType
in class AbstractProxyMultipleConnection<Server>
protected ConnectionInfo<Server> reconnectMain()
Overridden creates a connection back to the primary server.
reconnectMain
in class AbstractProxyMultipleConnection<Server>
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.