public class ServerState extends Object
ServerState
s should generally be created and their writable state
updated via a ClusterState
.
Modifier and Type | Field and Description |
---|---|
static double |
DECAY_ALPHA
The decay rate for the exponential average for the latency.
|
static double |
DECAY_SAMPLES
The decay period (number of samples) for the average latency.
|
static int |
DEFAULT_PORT
The default MongoDB port.
|
Constructor and Description |
---|
ServerState(InetSocketAddress server)
Creates a new
ServerState . |
Modifier and Type | Method and Description |
---|---|
boolean |
addConnection(Connection connection)
Adds a
Connection to the state making it available for reuse. |
double |
getAverageLatency()
Returns the current average latency (in milliseconds) seen in issuing
requests to the server.
|
long |
getConnectionGeneration()
Returns a generation value for the connection currently being held.
|
String |
getName()
Returns the normalized name of the server being tracked.
|
double |
getSecondsBehind()
Sets the last reported seconds behind the primary.
|
InetSocketAddress |
getServer()
Returns the address of the server being tracked.
|
Document |
getTags()
Returns the tags for the server.
|
boolean |
isWritable()
Returns true if the server can be written to, false otherwise.
|
void |
setAverageLatency(double latency)
Sets the average latency (in milliseconds) for requests to the server.
|
void |
setSecondsBehind(double secondsBehind)
Sets the last reported seconds behind the primary.
|
void |
setTags(Document tags)
Sets the tags for the server.
|
Connection |
takeConnection()
Returns a
Connection to the server if one is available. |
String |
toString() |
void |
updateAverageLatency(double latency)
Updates the average latency (in milliseconds) for the server.
|
public static final double DECAY_ALPHA
public static final double DECAY_SAMPLES
public static final int DEFAULT_PORT
public ServerState(InetSocketAddress server)
ServerState
. Package private to force creation
through the ClusterState
.server
- The server being tracked.public boolean addConnection(Connection connection)
Connection
to the state making it available for reuse.
Only a limited number of connections will be held (currently 1). If the connection is not added to the state false is returned.
connection
- A Connection
to the server making it available to
other to use.public double getAverageLatency()
Double.MAX_VALUE
then we have no basis for determining the latency.public long getConnectionGeneration()
ClusterPinger
to test if the connections it is creating are
getting used.public String getName()
public double getSecondsBehind()
public InetSocketAddress getServer()
public Document getTags()
public boolean isWritable()
If writable it might be a standalone server, the primary in a replica set, or a mongos in a sharded configuration. If not writable it is a secondary server in a replica set or we cannot or have not connected to the server yet.
To modify the writable flag update the ClusterState
via a
ClusterState.markNotWritable(ServerState)
or
ClusterState.markWritable(ServerState)
call.
public void setAverageLatency(double latency)
latency
- The latency (in milliseconds) for requests to the server.public void setSecondsBehind(double secondsBehind)
secondsBehind
- The seconds behind the primary server.public void setTags(Document tags)
tags
- The tags for the server.public Connection takeConnection()
Connection
to the server if one is available.Connection
to the server if one is available.public String toString()
Overridden to to return a human readable version of the server state.
public void updateAverageLatency(double latency)
latency
- The latency seen sending a request and receiving a reply from
the server.Copyright © 2011-2013 Allanbank Consulting, Inc.. All Rights Reserved.