@Override public String toString() { return "ClusterDescription{" + "type=" + getType() + (srvResolutionException == null ? "" : ", srvResolutionException=" + srvResolutionException) + ", connectionMode=" + connectionMode + ", serverDescriptions=" + serverDescriptions + '}'; }
/** * Chooses the servers from the given cluster than match this read preference. * * @param clusterDescription the cluster description * @return a list of matching server descriptions, which may be empty but may not be null */ public final List<ServerDescription> choose(final ClusterDescription clusterDescription) { switch (clusterDescription.getType()) { case REPLICA_SET: return chooseForReplicaSet(clusterDescription); case SHARDED: case STANDALONE: return chooseForNonReplicaSet(clusterDescription); case UNKNOWN: return Collections.emptyList(); default: throw new UnsupportedOperationException("Unsupported cluster type: " + clusterDescription.getType()); } }
/** * Get the status of the replica set cluster. * * @return replica set status information */ @SuppressWarnings("deprecation") @Deprecated @Nullable public ReplicaSetStatus getReplicaSetStatus() { ClusterDescription clusterDescription = getClusterDescription(); return clusterDescription.getType() == REPLICA_SET && clusterDescription.getConnectionMode() == MULTIPLE ? new ReplicaSetStatus(delegate.getCluster()) : null; // this is intended behavior in 2.x }
protected static ClusterDescription copyClusterDescription(final ClusterDescription clusterDescription, final List<ServerDescription> selectedServers) { return new ClusterDescription(clusterDescription.getConnectionMode(), clusterDescription.getType(), selectedServers, clusterDescription.getClusterSettings(), clusterDescription.getServerSettings()); }
@Override public List<ServerDescription> select(final ClusterDescription clusterDescription) { ClusterDescription curClusterDescription = clusterDescription; List<ServerDescription> choices = null; for (ServerSelector cur : serverSelectors) { choices = cur.select(curClusterDescription); curClusterDescription = new ClusterDescription(clusterDescription.getConnectionMode(), clusterDescription.getType(), choices, clusterDescription.getClusterSettings(), clusterDescription.getServerSettings()); } return choices; }
long maxWaitTimeNanos = getMaxWaitTimeNanos(); while (curDescription.getType() == ClusterType.UNKNOWN) {
if (clusterDescription.getType() != ClusterType.REPLICA_SET) { return servers;
@Nullable public ClientSession createClientSession(final ClientSessionOptions options, final ReadConcern readConcern, final WriteConcern writeConcern, final ReadPreference readPreference) { notNull("readConcern", readConcern); notNull("writeConcern", writeConcern); notNull("readPreference", readPreference); if (credentialList.size() > 1) { return null; } ClusterDescription connectedClusterDescription = getConnectedClusterDescription(); if (connectedClusterDescription.getType() == ClusterType.STANDALONE || connectedClusterDescription.getLogicalSessionTimeoutMinutes() == null) { return null; } else { ClientSessionOptions mergedOptions = ClientSessionOptions.builder(options) .defaultTransactionOptions( TransactionOptions.merge( options.getDefaultTransactionOptions(), TransactionOptions.builder() .readConcern(readConcern) .writeConcern(writeConcern) .readPreference(readPreference) .build())) .build(); return new ClientSessionImpl(serverSessionPool, originator, mergedOptions, this); } }
@Override public String toString() { return "ClusterDescription{" + "type=" + getType() + (srvResolutionException == null ? "" : ", srvResolutionException=" + srvResolutionException) + ", connectionMode=" + connectionMode + ", serverDescriptions=" + serverDescriptions + '}'; }
/** * Chooses the servers from the given cluster than match this read preference. * * @param clusterDescription the cluster description * @return a list of matching server descriptions, which may be empty but may not be null */ public final List<ServerDescription> choose(final ClusterDescription clusterDescription) { switch (clusterDescription.getType()) { case REPLICA_SET: return chooseForReplicaSet(clusterDescription); case SHARDED: case STANDALONE: return chooseForNonReplicaSet(clusterDescription); case UNKNOWN: return Collections.emptyList(); default: throw new UnsupportedOperationException("Unsupported cluster type: " + clusterDescription.getType()); } }
/** * Get the status of the replica set cluster. * * @return replica set status information */ @SuppressWarnings("deprecation") @Deprecated @Nullable public ReplicaSetStatus getReplicaSetStatus() { ClusterDescription clusterDescription = getClusterDescription(); return clusterDescription.getType() == REPLICA_SET && clusterDescription.getConnectionMode() == MULTIPLE ? new ReplicaSetStatus(delegate.getCluster()) : null; // this is intended behavior in 2.x }
protected static ClusterDescription copyClusterDescription(final ClusterDescription clusterDescription, final List<ServerDescription> selectedServers) { return new ClusterDescription(clusterDescription.getConnectionMode(), clusterDescription.getType(), selectedServers, clusterDescription.getClusterSettings(), clusterDescription.getServerSettings()); }
@Override public List<ServerDescription> select(final ClusterDescription clusterDescription) { ClusterDescription curClusterDescription = clusterDescription; List<ServerDescription> choices = null; for (ServerSelector cur : serverSelectors) { choices = cur.select(curClusterDescription); curClusterDescription = new ClusterDescription(clusterDescription.getConnectionMode(), clusterDescription.getType(), choices, clusterDescription.getClusterSettings(), clusterDescription.getServerSettings()); } return choices; }
long maxWaitTimeNanos = getMaxWaitTimeNanos(); while (curDescription.getType() == ClusterType.UNKNOWN) {
if (clusterDescription.getType() != ClusterType.REPLICA_SET) { return servers;
@Nullable public ClientSession createClientSession(final ClientSessionOptions options, final ReadConcern readConcern, final WriteConcern writeConcern, final ReadPreference readPreference) { notNull("readConcern", readConcern); notNull("writeConcern", writeConcern); notNull("readPreference", readPreference); if (credentialList.size() > 1) { return null; } ClusterDescription connectedClusterDescription = getConnectedClusterDescription(); if (connectedClusterDescription.getType() == ClusterType.STANDALONE || connectedClusterDescription.getLogicalSessionTimeoutMinutes() == null) { return null; } else { ClientSessionOptions mergedOptions = ClientSessionOptions.builder(options) .defaultTransactionOptions( TransactionOptions.merge( options.getDefaultTransactionOptions(), TransactionOptions.builder() .readConcern(readConcern) .writeConcern(writeConcern) .readPreference(readPreference) .build())) .build(); return new ClientSessionImpl(serverSessionPool, originator, mergedOptions, this); } }
@Nullable public ClientSession createClientSession(final ClientSessionOptions options, final ReadConcern readConcern, final WriteConcern writeConcern, final ReadPreference readPreference) { notNull("readConcern", readConcern); notNull("writeConcern", writeConcern); notNull("readPreference", readPreference); if (credentialList.size() > 1) { return null; } ClusterDescription connectedClusterDescription = getConnectedClusterDescription(); if (connectedClusterDescription.getType() == ClusterType.STANDALONE || connectedClusterDescription.getLogicalSessionTimeoutMinutes() == null) { return null; } else { ClientSessionOptions mergedOptions = ClientSessionOptions.builder(options) .defaultTransactionOptions( TransactionOptions.merge( options.getDefaultTransactionOptions(), TransactionOptions.builder() .readConcern(readConcern) .writeConcern(writeConcern) .readPreference(readPreference) .build())) .build(); return new ClientSessionImpl(serverSessionPool, originator, mergedOptions, this); } }