public class ReplicaSetConnection extends AbstractProxyMultipleConnection<Server>
Connection
implementation for connecting to a replica-set
environment.AbstractProxyMultipleConnection.ClusterAndConnectionListener
myCluster, myConfig, myEventSupport, myFactory, myLastUsedConnection, myListener, myMainKey, myOpen, myShutdown
COMMAND_COLLECTION, OPEN_PROP_NAME
Constructor and Description |
---|
ReplicaSetConnection(Connection proxiedConnection,
Server server,
Cluster cluster,
ProxiedConnectionFactory factory,
MongoClientConfiguration config,
ReplicaSetReconnectStrategy strategy)
Creates a new
ReplicaSetConnection . |
Modifier and Type | Method and Description |
---|---|
protected Connection |
connect(Server server)
Attempts to create a connection to the server, catching any exceptions
thrown.
|
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, connection, createReconnectFailure, doSend, flush, getPendingCount, handleConnectionClosed, isAvailable, isIdle, isOpen, isShuttingDown, raiseErrors, removeCachedConnection, removePropertyChangeListener, send, send, shutdown, toString, trySend, updateMain, waitForClosed
public ReplicaSetConnection(Connection proxiedConnection, Server server, Cluster cluster, ProxiedConnectionFactory factory, MongoClientConfiguration config, ReplicaSetReconnectStrategy strategy)
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.strategy
- The strategy for reconnecting/finding the primary.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 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 ReplicaSet
.
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.