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 Logger |
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 ReplicaSetConnection |
checkForReply(Connection oldConnection,
Map<InetSocketAddress,Future<Reply>> answers,
Map<InetSocketAddress,Connection> connections)
Checks for a reply from a server.
|
protected String |
checkReply(Future<Reply> replyFuture,
Map<InetSocketAddress,Connection> connections,
InetSocketAddress addr)
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.
|
protected Future<Reply> |
sendIsPrimary(Map<InetSocketAddress,Future<Reply>> answers,
Map<InetSocketAddress,Connection> connections,
ServerState 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<InetSocketAddress,Future<Reply>> answers,
Map<InetSocketAddress,Connection> connections,
String putativePrimary)
Tries to verify that the suspected primary server is in fact the primary
server by asking it directly and synchronously.
|
copyPending, 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 Logger 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.protected ReplicaSetConnection checkForReply(Connection oldConnection, Map<InetSocketAddress,Future<Reply>> answers, Map<InetSocketAddress,Connection> connections)
oldConnection
- The old connection to copy from.answers
- The pending (Future
) answers from each server.connections
- The connection to each server.protected String checkReply(Future<Reply> replyFuture, Map<InetSocketAddress,Connection> connections, InetSocketAddress addr)
replyFuture
- The future to get the reply from.connections
- The map of connections. The connection will be closed on an
error.addr
- The address of the server.protected Future<Reply> sendIsPrimary(Map<InetSocketAddress,Future<Reply>> answers, Map<InetSocketAddress,Connection> connections, ServerState 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<InetSocketAddress,Future<Reply>> answers, Map<InetSocketAddress,Connection> connections, String putativePrimary)
answers
- The pending (Future
) answers from each server.connections
- The connection to each server.putativePrimary
- The server we think is the primary.Copyright © 2011-2013 Allanbank Consulting, Inc.. All Rights Reserved.