public class ReplicaSetReconnectStrategy extends AbstractReconnectStrategy
ReconnectStrategy
designed for
replica sets. The reconnect strategy attempts to locate the primary member of
the replica set by:
Modifier and Type | Field and Description |
---|---|
static int |
INITIAL_RECONNECT_PAUSE_TIME_MS
The initial amount of time to pause waiting for a server to take over as
the primary.
|
protected static Log |
LOG
The logger for the
ReplicaSetReconnectStrategy . |
static int |
MAX_RECONNECT_PAUSE_TIME_MS
The Maximum amount of time to pause waiting for a server to take over as
the primary.
|
myConfig, myConnectionFactory, mySelector, myState
Constructor and Description |
---|
ReplicaSetReconnectStrategy()
Creates a new ReplicaSetReconnectStrategy.
|
Modifier and Type | Method and Description |
---|---|
protected ConnectionInfo<Server> |
checkForReply(Cluster state,
Map<Server,Future<Reply>> answers,
Map<Server,Connection> connections,
long deadline)
Checks for a reply from a server.
|
protected String |
checkReply(Future<Reply> replyFuture,
Map<Server,Connection> connections,
Server server,
long deadline)
Extracts who the server thinks is the primary from the reply.
|
ReplicaSetConnection |
reconnect(Connection oldConnection)
Encapsulates the strategy for re-establishing the connection to the
server.
|
ConnectionInfo<Server> |
reconnectPrimary()
Overridden to search for the primary server in the replica set.
|
protected Future<Reply> |
sendIsPrimary(Map<Server,Future<Reply>> answers,
Map<Server,Connection> connections,
Server server,
boolean isPrimary)
Sends a command to the server to return what it thinks the state of the
cluster is.
|
protected void |
sleep(int sleepTime,
TimeUnit units)
Sleeps without throwing an exception.
|
protected boolean |
verifyPutative(Map<Server,Future<Reply>> answers,
Map<Server,Connection> connections,
Server putativePrimary,
long deadline)
Tries to verify that the suspected primary server is in fact the primary
server by asking it directly and synchronously.
|
getConfig, getConnectionFactory, getSelector, getState, isConnected, setConfig, setConnectionFactory, setSelector, setState
public static final int INITIAL_RECONNECT_PAUSE_TIME_MS
public static final int MAX_RECONNECT_PAUSE_TIME_MS
protected static final Log LOG
ReplicaSetReconnectStrategy
.public ReplicaSetReconnectStrategy()
public ReplicaSetConnection reconnect(Connection oldConnection)
Overridden to search for the primary server in the replica set. This will
only continue until the
MongoClientConfiguration.getReconnectTimeout()
has expired.
oldConnection
- The connection that has become disconnected.public ConnectionInfo<Server> reconnectPrimary()
MongoClientConfiguration.getReconnectTimeout()
has expired.protected ConnectionInfo<Server> checkForReply(Cluster state, Map<Server,Future<Reply>> answers, Map<Server,Connection> connections, long deadline)
state
- The state of the cluster.answers
- The pending (Future
) answers from each server.connections
- The connection to each server.deadline
- The deadline for the reconnect attempt.protected String checkReply(Future<Reply> replyFuture, Map<Server,Connection> connections, Server server, long deadline)
replyFuture
- The future to get the reply from.connections
- The map of connections. The connection will be closed on an
error.server
- The server.deadline
- The deadline for the reconnect attempt.protected Future<Reply> sendIsPrimary(Map<Server,Future<Reply>> answers, Map<Server,Connection> connections, Server server, boolean isPrimary)
answers
- The pending (Future
) answers from each server.connections
- The connection to each server.server
- The server to send the request to.isPrimary
- If true logs connection errors as warnings. Debug otherwise.protected void sleep(int sleepTime, TimeUnit units)
sleepTime
- The amount of time to sleep.units
- The untis for the amount of time to sleep.protected boolean verifyPutative(Map<Server,Future<Reply>> answers, Map<Server,Connection> connections, Server putativePrimary, long deadline)
answers
- The pending (Future
) answers from each server.connections
- The connection to each server.putativePrimary
- The server we think is the primary.deadline
- The deadline for the reconnect attempt.Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.