Package com.mongodb.connection
Interface Cluster
-
- All Superinterfaces:
java.lang.AutoCloseable,java.io.Closeable
- All Known Implementing Classes:
MultiServerCluster,SingleServerCluster
public interface Cluster extends java.io.CloseableRepresents a cluster of MongoDB servers. Implementations can define the behaviour depending upon the type of cluster.- Since:
- 3.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidclose()Closes connections to the servers in the cluster.BsonTimestampgetClusterTime()Get the last seen cluster timeClusterDescriptiongetCurrentDescription()Get the current description of this cluster.ClusterDescriptiongetDescription()Get the description of this cluster.ClusterSettingsgetSettings()Gets the cluster settings with which this cluster was created.booleanisClosed()Whether all the servers in the cluster are closed or not.ServerselectServer(ServerSelector serverSelector)Get a MongoDB server that matches the criteria defined by the serverSelectorvoidselectServerAsync(ServerSelector serverSelector, SingleResultCallback<Server> callback)Asynchronously gets a MongoDB server that matches the criteria defined by the serverSelector.
-
-
-
Method Detail
-
getSettings
ClusterSettings getSettings()
Gets the cluster settings with which this cluster was created.- Returns:
- the cluster settings
- Since:
- 3.4
-
getDescription
ClusterDescription getDescription()
Get the description of this cluster. This method will not return normally until the cluster type is known.- Returns:
- a ClusterDescription representing the current state of the cluster
- Throws:
MongoTimeoutException- if the timeout has been reached before the cluster type is known
-
getCurrentDescription
ClusterDescription getCurrentDescription()
Get the current description of this cluster.- Returns:
- the current ClusterDescription representing the current state of the cluster.
-
getClusterTime
@Nullable BsonTimestamp getClusterTime()
Get the last seen cluster time- Returns:
- the last seen cluster time or null if not set
- Since:
- 3.8
-
selectServer
Server selectServer(ServerSelector serverSelector)
Get a MongoDB server that matches the criteria defined by the serverSelector- Parameters:
serverSelector- a ServerSelector that defines how to select the required Server- Returns:
- a Server that meets the requirements
- Throws:
MongoTimeoutException- if the timeout has been reached before a server matching the selector is available
-
selectServerAsync
void selectServerAsync(ServerSelector serverSelector, SingleResultCallback<Server> callback)
Asynchronously gets a MongoDB server that matches the criteria defined by the serverSelector.- Parameters:
serverSelector- a ServerSelector that defines how to select the required Servercallback- the callback to invoke when the server is found or an error occurs
-
close
void close()
Closes connections to the servers in the cluster. After this is called, this cluster instance can no longer be used.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
isClosed
boolean isClosed()
Whether all the servers in the cluster are closed or not.- Returns:
- true if all the servers in this cluster have been closed
-
-