abstract class BaseCluster extends java.lang.Object implements Cluster
| Modifier and Type | Class and Description |
|---|---|
private static class |
BaseCluster.WrappedServer |
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
clusterId |
private ClusterListener |
clusterListener |
private ClusterDescription |
description |
private boolean |
isClosed |
private static java.util.logging.Logger |
LOGGER |
private java.util.concurrent.atomic.AtomicReference<java.util.concurrent.CountDownLatch> |
phase |
private java.lang.ThreadLocal<java.util.Random> |
random |
private ClusterableServerFactory |
serverFactory |
private ClusterSettings |
settings |
| Constructor and Description |
|---|
BaseCluster(java.lang.String clusterId,
ClusterSettings settings,
ClusterableServerFactory serverFactory,
ClusterListener clusterListener) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes connections to the servers in the cluster.
|
protected abstract void |
connect()
Try to connect to all servers
|
protected ClusterableServer |
createServer(ServerAddress serverAddress,
ChangeListener<ServerDescription> serverStateListener) |
protected void |
fireChangeEvent() |
(package private) ClusterDescription |
getCurrentDescription() |
ClusterDescription |
getDescription(long maxWaitTime,
java.util.concurrent.TimeUnit timeUnit)
Get the description of this cluster.
|
private java.util.Random |
getRandom() |
private ClusterableServer |
getRandomServer(java.util.List<ServerDescription> serverDescriptions) |
protected abstract ClusterableServer |
getServer(ServerAddress serverAddress)
Return the server at the given address.
|
Server |
getServer(ServerSelector serverSelector,
long maxWaitTime,
java.util.concurrent.TimeUnit timeUnit)
Get a MongoDB server that matches the criteria defined by the serverSelector
|
ClusterSettings |
getSettings() |
boolean |
isClosed()
Whether all the servers in the cluster are closed or not.
|
private void |
throwIfIncompatible(ClusterDescription curDescription) |
protected void |
updateDescription(ClusterDescription newDescription) |
private static final java.util.logging.Logger LOGGER
private final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.CountDownLatch> phase
private final ClusterableServerFactory serverFactory
private final java.lang.ThreadLocal<java.util.Random> random
private final java.lang.String clusterId
private final ClusterSettings settings
private final ClusterListener clusterListener
private volatile boolean isClosed
private volatile ClusterDescription description
public BaseCluster(java.lang.String clusterId,
ClusterSettings settings,
ClusterableServerFactory serverFactory,
ClusterListener clusterListener)
public Server getServer(ServerSelector serverSelector, long maxWaitTime, java.util.concurrent.TimeUnit timeUnit)
ClustergetServer in interface ClusterserverSelector - a ServerSelector that defines how to select the required ServermaxWaitTime - the maximum time to wait for a connection to the cluster to get a servertimeUnit - the TimeUnit for the maxWaitTimepublic ClusterDescription getDescription(long maxWaitTime, java.util.concurrent.TimeUnit timeUnit)
ClustergetDescription in interface ClustermaxWaitTime - the maximum time to wait for a connection to the cluster to get the descriptiontimeUnit - the TimeUnit for the maxWaitTimepublic ClusterSettings getSettings()
public void close()
Clusterpublic boolean isClosed()
Clusterprotected abstract ClusterableServer getServer(ServerAddress serverAddress)
serverAddress - the addressprotected abstract void connect()
protected void updateDescription(ClusterDescription newDescription)
protected void fireChangeEvent()
ClusterDescription getCurrentDescription()
private ClusterableServer getRandomServer(java.util.List<ServerDescription> serverDescriptions)
private void throwIfIncompatible(ClusterDescription curDescription)
private java.util.Random getRandom()
protected ClusterableServer createServer(ServerAddress serverAddress, ChangeListener<ServerDescription> serverStateListener)