Refine search
@SuppressWarnings("deprecation") private List<ServerDescription> getServerDescriptionListToConsiderForSessionSupport(final ClusterDescription clusterDescription) { if (clusterDescription.getConnectionMode() == ClusterConnectionMode.SINGLE) { return clusterDescription.getAny(); } else { return clusterDescription.getAnyPrimaryOrSecondary(); } }
private boolean shouldPrune(final ServerSessionImpl serverSession) { Integer logicalSessionTimeoutMinutes = cluster.getCurrentDescription().getLogicalSessionTimeoutMinutes(); // if the server no longer supports sessions, prune the session if (logicalSessionTimeoutMinutes == null) { return false; } long currentTimeMillis = clock.millis(); final long timeSinceLastUse = currentTimeMillis - serverSession.getLastUsedAtMillis(); final long oneMinuteFromTimeout = MINUTES.toMillis(logicalSessionTimeoutMinutes - 1); return timeSinceLastUse > oneMinuteFromTimeout; }
@Override public List<ServerDescription> select(final ClusterDescription clusterDescription) { for (ServerDescription cur : clusterDescription.getServerDescriptions()) { if (cur.getAddress().equals(primaryPreferred.get(0).getAddress())) { return Collections.singletonList(cur); } } return Collections.emptyList(); } }).getConnection();
protected static ClusterDescription copyClusterDescription(final ClusterDescription clusterDescription, final List<ServerDescription> selectedServers) { return new ClusterDescription(clusterDescription.getConnectionMode(), clusterDescription.getType(), selectedServers, clusterDescription.getClusterSettings(), clusterDescription.getServerSettings()); }
@Override @SuppressWarnings("deprecation") public List<ServerDescription> select(final ClusterDescription clusterDescription) { if (clusterDescription.getConnectionMode() == ClusterConnectionMode.SINGLE) { return clusterDescription.getAny(); } return readPreference.choose(clusterDescription); }
@Override @SuppressWarnings("deprecation") public List<ServerDescription> select(final ClusterDescription clusterDescription) { if (clusterDescription.getConnectionMode() != MULTIPLE) { return clusterDescription.getAny(); } else { return getServersWithAcceptableLatencyDifference(clusterDescription.getAny(), getFastestRoundTripTimeNanos(clusterDescription.getServerDescriptions())); } }
private MongoIncompatibleDriverException createIncompatibleException(final ClusterDescription curDescription) { String message; ServerDescription incompatibleServer = curDescription.findServerIncompatiblyOlderThanDriver(); if (incompatibleServer != null) { message = format("Server at %s reports wire version %d, but this version of the driver requires at least %d (MongoDB %s).", incompatibleServer.getAddress(), incompatibleServer.getMaxWireVersion(), MIN_DRIVER_WIRE_VERSION, MIN_DRIVER_SERVER_VERSION); } else { incompatibleServer = curDescription.findServerIncompatiblyNewerThanDriver(); message = format("Server at %s requires wire version %d, but this version of the driver only supports up to %d.", incompatibleServer.getAddress(), incompatibleServer.getMinWireVersion(), MAX_DRIVER_WIRE_VERSION); } return new MongoIncompatibleDriverException(message, curDescription); }
/** * Gets the maximum size for a BSON object supported by the current master server. Note that this value may change over time depending * on which server is master. * * @return the maximum size, or 0 if not obtained from servers yet. * @throws MongoException if there's a failure */ @SuppressWarnings("deprecation") public int getMaxBsonObjectSize() { List<ServerDescription> primaries = getClusterDescription().getPrimaries(); return primaries.isEmpty() ? ServerDescription.getDefaultMaxDocumentSize() : primaries.get(0).getMaxDocumentSize(); }
/** * Gets the address of the current master * * @return the address */ @Deprecated @SuppressWarnings("deprecation") @Nullable public ServerAddress getAddress() { ClusterDescription description = getClusterDescription(); if (description.getPrimaries().isEmpty()) { return null; } return description.getPrimaries().get(0).getAddress(); }
@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); } }
private boolean serversAreAllThreeDotFour(final ClusterDescription clusterDescription) { for (ServerDescription cur : clusterDescription.getServerDescriptions()) { if (cur.isOk() && cur.getMaxWireVersion() < 5) { return false; } } return true; }
/** * 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 }
if (clusterDescription.getServerSettings() == null) { throw new MongoConfigurationException("heartbeat frequency must be provided in cluster description"); if (clusterDescription.getType() != ClusterType.REPLICA_SET) { return servers; long heartbeatFrequencyMS = clusterDescription.getServerSettings().getHeartbeatFrequency(MILLISECONDS); if (cur.isPrimary()) { freshServers.add(cur); } else {
/** * Get the name of the replica set. * * @return the name of the replica set. */ @SuppressWarnings("deprecation") @Nullable public String getName() { List<ServerDescription> any = getClusterDescription().getAnyPrimaryOrSecondary(); return any.isEmpty() ? null : any.get(0).getSetName(); }
long maxWaitTimeNanos = getMaxWaitTimeNanos(); while (curDescription.getType() == ClusterType.UNKNOWN) { + "is %s", settings.getServerSelectionTimeout(MILLISECONDS), curDescription.getShortDescription()));
@Override @SuppressWarnings("deprecation") public List<ServerDescription> select(final ClusterDescription clusterDescription) { return clusterDescription.getPrimaries(); }
@Nullable private ServerDescription findPrimary(final ClusterDescription clusterDescription) { for (ServerDescription cur : clusterDescription.getServerDescriptions()) { if (cur.isPrimary()) { return cur; } } return null; }
private ServerDescription findMostUpToDateSecondary(final ClusterDescription clusterDescription) { ServerDescription mostUpdateToDateSecondary = null; for (ServerDescription cur : clusterDescription.getServerDescriptions()) { if (cur.isSecondary()) { if (mostUpdateToDateSecondary == null || getLastWriteDateNonNull(cur).getTime() > getLastWriteDateNonNull(mostUpdateToDateSecondary).getTime()) { mostUpdateToDateSecondary = cur; } } } if (mostUpdateToDateSecondary == null) { throw new MongoInternalException("Expected at least one secondary in cluster description: " + clusterDescription); } return mostUpdateToDateSecondary; }
@Override @SuppressWarnings("deprecation") protected List<ServerDescription> chooseForNonReplicaSet(final ClusterDescription clusterDescription) { return clusterDescription.getAny(); }
@Override public String toString() { return "ClusterDescription{" + "type=" + getType() + (srvResolutionException == null ? "" : ", srvResolutionException=" + srvResolutionException) + ", connectionMode=" + connectionMode + ", serverDescriptions=" + serverDescriptions + '}'; }