public class Server extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Server.State
State provides the possible sttes for a server within the MongoDB
cluster.
|
Modifier and Type | Field and Description |
---|---|
static String |
CANONICAL_NAME_PROP
The name for the Server's canonical name property: '"canonicalName" '.
|
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.
|
static Class<DocumentElement> |
DOCUMENT_TYPE
The document element type.
|
static int |
MAX_BATCHED_WRITE_OPERATIONS_DEFAULT
The default number of max batched write operations.
|
static String |
MAX_BATCHED_WRITE_OPERATIONS_PROP
The name for the Server's maximum BSON object size property: "maxWriteBatchSize" .
|
static String |
MAX_BSON_OBJECT_SIZE_PROP
The name for the Server's maximum BSON object size property: "maxBsonObjectSize" .
|
static Class<NumericElement> |
NUMERIC_TYPE
The numeric element type.
|
static int |
PRIMARY_STATE
The value for a primary server's state.
|
static int |
SECONDARY_STATE
The value for a secondary (actively replicating) server's state.
|
static String |
STATE_PROP
The name for the Server's state property: "state" .
|
static Class<StringElement> |
STRING_TYPE
The string element type.
|
static String |
TAGS_PROP
The name for the Server's tags property: "tags" .
|
static Class<TimestampElement> |
TIMESTAMP_TYPE
The timestamp element type.
|
static String |
VERSION_PROP
The name for the Server's version property: "version" .
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(PropertyChangeListener listener)
Add a PropertyChangeListener to receive all future property changes for
the
Server . |
void |
connectFailed()
Notification that an attempt to connect to the server via the all of the
addresses provided failed. |
void |
connectionClosed()
Notification that a connection has closed normally.
|
void |
connectionOpened(InetSocketAddress addressUsed)
Notification that a connection was successfully opened to the server.
|
void |
connectionTerminated()
Notification that a connection has closed abruptly.
|
boolean |
equals(Object object) |
Collection<InetSocketAddress> |
getAddresses()
Returns the address of the server being tracked.
|
double |
getAverageLatency()
Returns the current average latency (in milliseconds) seen in issuing
requests to the server.
|
String |
getCanonicalName()
Returns the name of the server as reported by the server itself.
|
int |
getMaxBatchedWriteOperations()
Returns the maximum number of write operations allowed in a single write
command.
|
int |
getMaxBsonObjectSize()
Returns the maximum BSON object size the server will accept.
|
long |
getMessagesSent()
Returns the number of messages sent to the server.
|
long |
getRepliesReceived()
Returns the number of messages received from the server.
|
double |
getSecondsBehind()
Sets the last reported seconds behind the primary.
|
Server.State |
getState()
Returns the state value.
|
Document |
getTags()
Returns the tags for the server.
|
long |
getTotalLatencyNanoSeconds()
Returns the total amount of time messages waited for a reply from the
server in nanoseconds.
|
Version |
getVersion()
Returns the version of the server.
|
int |
hashCode() |
void |
incrementMessagesSent()
Increments the number of messages sent to the server.
|
void |
incrementRepliesReceived()
Increments the number of messages received from the server.
|
boolean |
isWritable()
Returns true if the server can be written to, false otherwise.
|
boolean |
needBuildInfo()
Returns true if there has not been a recent update to the server's
version or maximum document size.
|
void |
removeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener to stop receiving future property changes
for the
Server . |
void |
requestFailed()
Notification that a status request message on the connection failed.
|
String |
toString() |
void |
update(Document document)
Updates the state of the server based on the document provided.
|
void |
updateAverageLatency(long latencyNanoSeconds)
Updates the average latency (in nano-seconds) for the server.
|
public static final String CANONICAL_NAME_PROP
public static final double DECAY_ALPHA
public static final double DECAY_SAMPLES
public static final int DEFAULT_PORT
public static final Class<DocumentElement> DOCUMENT_TYPE
public static final int MAX_BATCHED_WRITE_OPERATIONS_DEFAULT
public static final String MAX_BATCHED_WRITE_OPERATIONS_PROP
public static final String MAX_BSON_OBJECT_SIZE_PROP
public static final Class<NumericElement> NUMERIC_TYPE
public static final int PRIMARY_STATE
public static final int SECONDARY_STATE
public static final String STATE_PROP
public static final Class<StringElement> STRING_TYPE
public static final String TAGS_PROP
public static final Class<TimestampElement> TIMESTAMP_TYPE
public static final String VERSION_PROP
public void addListener(PropertyChangeListener listener)
Server
.listener
- The PropertyChangeListener to be addedPropertyChangeSupport.addPropertyChangeListener(PropertyChangeListener)
public void connectFailed()
addresses provided
failed.public void connectionClosed()
public void connectionOpened(InetSocketAddress addressUsed)
InetSocketAddress
provided becomes the preferred address to use
when connecting to the server.addressUsed
- The address that was used to connect to the server.public void connectionTerminated()
public boolean equals(Object object)
Overridden to return a stable equality check. This is based only on the
server object's identity. The Cluster
class will de-duplicate
once the canonical host names are determined.
public Collection<InetSocketAddress> getAddresses()
public double getAverageLatency()
Double.MAX_VALUE
then we have no basis for determining the latency.
This average is over the recent replies not over all replies received.
public String getCanonicalName()
public int getMaxBatchedWriteOperations()
public int getMaxBsonObjectSize()
Client.MAX_DOCUMENT_SIZE
.public long getMessagesSent()
public long getRepliesReceived()
public double getSecondsBehind()
public Server.State getState()
public Document getTags()
public long getTotalLatencyNanoSeconds()
getTotalLatencyNanoSeconds()
/getRepliesReceived()
.public Version getVersion()
public int hashCode()
Overridden to return a stable hash for the server. This is based only on
the server object's identity hash
code
. The Cluster
class will de-duplicate once the canonical
host names are determined.
public void incrementMessagesSent()
public void incrementRepliesReceived()
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.
public boolean needBuildInfo()
public void removeListener(PropertyChangeListener listener)
Server
.listener
- The PropertyChangeListener to be removedPropertyChangeSupport.removePropertyChangeListener(PropertyChangeListener)
public void requestFailed()
In the case of an exception the seconds behind is set to
Integer.MAX_VALUE
. The value is configurable as a long so in
theory a user can ignore this case using a large
MongoClientConfiguration.setMaxSecondaryLag(long)
.
public String toString()
Overridden to to return a human readable version of the server state.
public void update(Document document)
ismaster
or
replSetGetStatus
command.document
- The document with the state of the server.public void updateAverageLatency(long latencyNanoSeconds)
latencyNanoSeconds
- The latency seen sending a request and receiving a reply from
the server.Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.