Package com.mongodb.connection
Class ServerDescription
- java.lang.Object
-
- com.mongodb.connection.ServerDescription
-
@Immutable public class ServerDescription extends Object
Immutable snapshot state of a server.- Since:
- 3.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ServerDescription.Builder
A builder for creating ServerDescription.
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_DRIVER_WIRE_VERSION
The maximum supported driver wire versionstatic String
MIN_DRIVER_SERVER_VERSION
The minimum supported driver server versionstatic int
MIN_DRIVER_WIRE_VERSION
The minimum supported driver wire version
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ServerDescription.Builder
builder()
Gets a Builder for creating a new ServerDescription instance.static ServerDescription.Builder
builder(ServerDescription serverDescription)
Creates a Builder for a ServerDescription instance based on a previous serverDescription.boolean
equals(Object o)
Returns true if this instance is equals to @code{o}.ServerAddress
getAddress()
Gets the address of this serverSet<String>
getArbiters()
Gets the arbiters in the replica setString
getCanonicalAddress()
Gets the string representing the host name and port that this member of a replica set was configured with, e.g.ClusterType
getClusterType()
Gets the type of the cluster this server is in (for example, replica set).static int
getDefaultMaxDocumentSize()
Get the default maximum document size.static int
getDefaultMaxWireVersion()
Get the default maximum wire versionstatic int
getDefaultMinWireVersion()
Get the default minimum wire versionObjectId
getElectionId()
The replica set electionid reported by this MongoDB server.Throwable
getException()
Gets the exception thrown while attempting to determine the server description.Set<String>
getHosts()
Get a Set of strings in the format of "[hostname]:[port]" that contains all members of the replica set that are neither hidden, passive, nor arbiters.long
getLastUpdateTime(TimeUnit timeUnit)
Gets the time that this server description was created, using a monotonic clock likeSystem.nanoTime()
.Date
getLastWriteDate()
Gets the last write date.Integer
getLogicalSessionTimeoutMinutes()
Gets the session timeout in minutes.int
getMaxDocumentSize()
The maximum permitted size of a BSON object in bytes for this mongod process.int
getMaxWireVersion()
The latest version of the wire protocol that this MongoDB server is capable of using to communicate with clients.int
getMinWireVersion()
The earliest version of the wire protocol that this MongoDB server is capable of using to communicate with clients.Set<String>
getPassives()
Gets the passive members of the replica set.String
getPrimary()
Gets the address of the current primary in the replica setlong
getRoundTripTimeNanos()
Get the time it took to make the round trip for requesting this information from the server in nanoseconds.String
getSetName()
Gets the name of the replica setInteger
getSetVersion()
The replica set setVersion reported by this MongoDB server.String
getShortDescription()
Returns a short, pretty description for this ServerDescription.ServerConnectionState
getState()
Gets the current state of the connection to the server.TagSet
getTagSet()
A set of all tags assigned to this member.TopologyVersion
getTopologyVersion()
The topologyVersion reported by this MongoDB server.ServerType
getType()
Gets the type of the server, for example whether it's a standalone or in a replica set.int
hashCode()
boolean
hasTags(TagSet desiredTags)
Returns true if the server has the given tags.boolean
isCompatibleWithDriver()
Return whether the server is compatible with the driver.boolean
isHelloOk()
Gets whether this server supports the "hello" command.boolean
isIncompatiblyNewerThanDriver()
Return whether the server is compatible with the driver.boolean
isIncompatiblyOlderThanDriver()
Return whether the server is compatible with the driver.boolean
isOk()
The isOK() result from requesting this information from the serverboolean
isPrimary()
Returns whether this can be treated as a primary server.boolean
isReplicaSetMember()
Gets whether this server is a replica set member.boolean
isSecondary()
Returns whether this can be treated as a secondary server.boolean
isShardRouter()
Gets whether this is a server that is the entry point to a sharded instance of MongoDB.boolean
isStandAlone()
Gets whether this is part of a replica set/sharded system, or is a single server.String
toString()
-
-
-
Field Detail
-
MIN_DRIVER_SERVER_VERSION
public static final String MIN_DRIVER_SERVER_VERSION
The minimum supported driver server version- Since:
- 3.8
- See Also:
- Constant Field Values
-
MIN_DRIVER_WIRE_VERSION
public static final int MIN_DRIVER_WIRE_VERSION
The minimum supported driver wire version- Since:
- 3.8
- See Also:
- Constant Field Values
-
MAX_DRIVER_WIRE_VERSION
public static final int MAX_DRIVER_WIRE_VERSION
The maximum supported driver wire version- Since:
- 3.8
- See Also:
- Constant Field Values
-
-
Method Detail
-
builder
public static ServerDescription.Builder builder()
Gets a Builder for creating a new ServerDescription instance.- Returns:
- a new Builder for ServerDescription.
-
builder
public static ServerDescription.Builder builder(ServerDescription serverDescription)
Creates a Builder for a ServerDescription instance based on a previous serverDescription.- Parameters:
serverDescription
- the ServerDescription to base the builder from- Returns:
- a new Builder for ServerDescription.
- Since:
- 4.1
-
getCanonicalAddress
public String getCanonicalAddress()
Gets the string representing the host name and port that this member of a replica set was configured with, e.g."somehost:27019"
. This is typically derived from the "me" field from the "isMaster" command response.- Returns:
- the host name and port that this replica set member is configured with.
-
getLogicalSessionTimeoutMinutes
@Nullable public Integer getLogicalSessionTimeoutMinutes()
Gets the session timeout in minutes.- Returns:
- the session timeout in minutes, or null if sessions are not supported by this server
- Since:
- 3.6
- Since server release
- 3.6
-
isHelloOk
public boolean isHelloOk()
Gets whether this server supports the "hello" command. The default isfalse
.- Returns:
- true if this server supports the "hello" command.
- Since:
- 4.3
- Since server release
- 5.0
-
isCompatibleWithDriver
public boolean isCompatibleWithDriver()
Return whether the server is compatible with the driver. An incompatible server is one that has a min wire version greater that the driver's max wire version or a max wire version less than the driver's min wire version.A load balancer is always deemed to be compatible.
- Returns:
- true if the server is compatible with the driver.
-
isIncompatiblyNewerThanDriver
public boolean isIncompatiblyNewerThanDriver()
Return whether the server is compatible with the driver. An incompatible server is one that has a min wire version greater that the driver's max wire version or a max wire version less than the driver's min wire version.A load balancer is always deemed to be compatible.
- Returns:
- true if the server is compatible with the driver.
- Since:
- 3.6
-
isIncompatiblyOlderThanDriver
public boolean isIncompatiblyOlderThanDriver()
Return whether the server is compatible with the driver. An incompatible server is one that has a min wire version greater that the driver's max wire version or a max wire version less than the driver's min wire version.A load balancer is always deemed to be compatible.
- Returns:
- true if the server is compatible with the driver.
- Since:
- 3.6
-
getDefaultMaxDocumentSize
public static int getDefaultMaxDocumentSize()
Get the default maximum document size.- Returns:
- the default maximum document size
-
getDefaultMinWireVersion
public static int getDefaultMinWireVersion()
Get the default minimum wire version- Returns:
- the default minimum wire version
-
getDefaultMaxWireVersion
public static int getDefaultMaxWireVersion()
Get the default maximum wire version- Returns:
- the default maximum wire version
-
getAddress
public ServerAddress getAddress()
Gets the address of this server- Returns:
- a ServerAddress containing the details of the address of this server.
-
isReplicaSetMember
public boolean isReplicaSetMember()
Gets whether this server is a replica set member.- Returns:
- true if this server is part of a replica set
-
isShardRouter
public boolean isShardRouter()
Gets whether this is a server that is the entry point to a sharded instance of MongoDB.- Returns:
- true if this server is a mongos instance
-
isStandAlone
public boolean isStandAlone()
Gets whether this is part of a replica set/sharded system, or is a single server.- Returns:
- true if this is a single server
-
isPrimary
public boolean isPrimary()
Returns whether this can be treated as a primary server.- Returns:
- true if this server is the primary in a replica set, is a mongos, a load balancer, or is a single standalone server
-
isSecondary
public boolean isSecondary()
Returns whether this can be treated as a secondary server.- Returns:
- true if this server is a secondary in a replica set, is a mongos, a load balancer, or is a single standalone server
-
getHosts
public Set<String> getHosts()
Get a Set of strings in the format of "[hostname]:[port]" that contains all members of the replica set that are neither hidden, passive, nor arbiters.- Returns:
- all members of the replica set that are neither hidden, passive, nor arbiters.
-
getPassives
public Set<String> getPassives()
Gets the passive members of the replica set.- Returns:
- A set of strings in the format of "[hostname]:[port]" listing all members of the replica set which have a priority of 0.
-
getArbiters
public Set<String> getArbiters()
Gets the arbiters in the replica set- Returns:
- A Set of strings in the format of "[hostname]:[port]" containing all members of the replica set that are arbiters.
-
getPrimary
public String getPrimary()
Gets the address of the current primary in the replica set- Returns:
- A string in the format of "[hostname]:[port]" listing the current primary member of the replica set.
-
getMaxDocumentSize
public int getMaxDocumentSize()
The maximum permitted size of a BSON object in bytes for this mongod process. Defaults to 16MB.- Returns:
- the maximum size a document can be
-
getTagSet
public TagSet getTagSet()
A set of all tags assigned to this member.- Returns:
- a TagSet with all the tags for this server.
-
getMinWireVersion
public int getMinWireVersion()
The earliest version of the wire protocol that this MongoDB server is capable of using to communicate with clients.- Returns:
- the minimum protocol version supported by this server
-
getMaxWireVersion
public int getMaxWireVersion()
The latest version of the wire protocol that this MongoDB server is capable of using to communicate with clients.- Returns:
- the maximum protocol version supported by this server
-
getElectionId
@Nullable public ObjectId getElectionId()
The replica set electionid reported by this MongoDB server.- Returns:
- the electionId, which may be null
-
getSetVersion
@Nullable public Integer getSetVersion()
The replica set setVersion reported by this MongoDB server.- Returns:
- the setVersion, which may be null
-
getTopologyVersion
public TopologyVersion getTopologyVersion()
The topologyVersion reported by this MongoDB server.- Returns:
- the topologyVersion, which may be null
- Since:
- 4.1
- Since server release
- 4.4
-
getLastWriteDate
@Nullable public Date getLastWriteDate()
Gets the last write date.- Returns:
- the last write date, which may be null
- Since:
- 3.4
- Since server release
- 3.4
-
getLastUpdateTime
public long getLastUpdateTime(TimeUnit timeUnit)
Gets the time that this server description was created, using a monotonic clock likeSystem.nanoTime()
.- Parameters:
timeUnit
- the time unit- Returns:
- the last update time in the given unit
- Since:
- 3.4
-
hasTags
public boolean hasTags(TagSet desiredTags)
Returns true if the server has the given tags. A server of either typeServerType.STANDALONE
orServerType.SHARD_ROUTER
is considered to have all tags, so this method will always return true for instances of either of those types.- Parameters:
desiredTags
- the tags- Returns:
- true if this server has the given tags
-
getSetName
public String getSetName()
Gets the name of the replica set- Returns:
- the name of the replica set
-
isOk
public boolean isOk()
The isOK() result from requesting this information from the server- Returns:
- true if the request executed correctly
-
getState
public ServerConnectionState getState()
Gets the current state of the connection to the server.- Returns:
- ServerConnectionState representing whether the server has been successfully connected to
-
getType
public ServerType getType()
Gets the type of the server, for example whether it's a standalone or in a replica set.- Returns:
- the server type
-
getClusterType
public ClusterType getClusterType()
Gets the type of the cluster this server is in (for example, replica set).- Returns:
- a ClusterType representing the type of the cluster this server is in
-
getRoundTripTimeNanos
public long getRoundTripTimeNanos()
Get the time it took to make the round trip for requesting this information from the server in nanoseconds.- Returns:
- the time taken to request the information, in nano seconds
-
getException
@Nullable public Throwable getException()
Gets the exception thrown while attempting to determine the server description. This is useful for diagnostic purposed when determining the root cause of a connectivity failure.- Returns:
- the exception, which may be null
-
equals
public boolean equals(Object o)
Returns true if this instance is equals to @code{o}. Note that equality is defined to NOT include the round trip time.
-
getShortDescription
public String getShortDescription()
Returns a short, pretty description for this ServerDescription.- Returns:
- a String containing the most pertinent information about this ServerDescription
-
-