public class ClusterPinger extends Object implements Runnable, Closeable
Modifier and Type | Class and Description |
---|---|
protected static class |
ClusterPinger.Pinger
Pinger provides logic to ping servers.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PING_INTERVAL_SECONDS
The default interval between ping sweeps in seconds.
|
protected static Log |
LOG
The logger for the
ClusterPinger . |
Constructor and Description |
---|
ClusterPinger(Cluster cluster,
ProxiedConnectionFactory factory,
MongoClientConfiguration config)
Creates a new ClusterPinger.
|
Modifier and Type | Method and Description |
---|---|
void |
addCluster(Cluster cluster)
Adds a new cluster to the set of tracked clusters.
|
void |
close() |
TimeUnit |
getIntervalUnits()
Returns the units for the ping sweep intervals.
|
int |
getPingSweepInterval()
Returns the interval for a ping sweep across all of the servers..
|
void |
initialSweep(Cluster cluster)
Performs a single sweep through the servers sending a ping with a
callback to set the latency and tags for each server.
|
static boolean |
ping(Server server,
Connection conn)
Pings the server and suppresses all exceptions.
|
void |
run() |
void |
setIntervalUnits(TimeUnit intervalUnits)
Sets the value of units for the ping sweep intervals.
|
void |
setPingSweepInterval(int pingSweepInterval)
Sets the interval for a ping sweep across all of the servers..
|
void |
start()
Starts the background pinger.
|
protected void |
startSweep()
Extension point to notify derived classes that a new sweep is starting.
|
void |
stop()
Stops the background pinger.
|
void |
wakeUp()
Starts the background pinger.
|
public static final int DEFAULT_PING_INTERVAL_SECONDS
protected static final Log LOG
ClusterPinger
.public ClusterPinger(Cluster cluster, ProxiedConnectionFactory factory, MongoClientConfiguration config)
cluster
- The state of the cluster.factory
- The factory for creating connections to the servers.config
- The configuration for the connections.public static boolean ping(Server server, Connection conn)
server
- The address of the server. Used for logging.conn
- The connection to ping.public void addCluster(Cluster cluster)
cluster
- A new cluster to the set of tracked clusters.public void close()
Overridden to close the pinger.
close
in interface Closeable
close
in interface AutoCloseable
public TimeUnit getIntervalUnits()
public int getPingSweepInterval()
public void initialSweep(Cluster cluster)
This method will not return until at least 50% of the servers have replied (which may be a failure) to the initial ping.
cluster
- The cluster of servers to ping.public void run()
Overridden to periodically wake-up and ping the servers. At first this will occur fairly often but eventually degrade to once every 5 minutes.
public void setIntervalUnits(TimeUnit intervalUnits)
intervalUnits
- The new value for the units for the ping sweep intervals.public void setPingSweepInterval(int pingSweepInterval)
pingSweepInterval
- The new value for the interval for a ping sweep across all of
the servers..public void start()
public void stop()
close()
.public void wakeUp()
protected void startSweep()
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.