Refine search
if (previous.isOk() != current.isOk()) { return true; if (!previous.getAddress().equals(current.getAddress())) { return true; if (previous.getCanonicalAddress() != null ? !previous.getCanonicalAddress().equals(current.getCanonicalAddress()) : current.getCanonicalAddress() != null) { return true; if (!previous.getHosts().equals(current.getHosts())) { return true; if (!previous.getArbiters().equals(current.getArbiters())) { return true; if (!previous.getPassives().equals(current.getPassives())) { return true; if (previous.getPrimary() != null ? !previous.getPrimary().equals(current.getPrimary()) : current.getPrimary() != null) { return true; if (previous.getSetName() != null ? !previous.getSetName().equals(current.getSetName()) : current.getSetName() != null) { return true; if (previous.getState() != current.getState()) { return true; if (!previous.getTagSet().equals(current.getTagSet())) {
/** * 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(); }
/** * Create a new ServerDescription from the settings in this builder. * * @return a new server description */ public ServerDescription build() { return new ServerDescription(this); } }
private boolean handleShardRouterChanged(final ServerDescription newDescription) { if (!newDescription.isShardRouter()) { LOGGER.error(format("Expecting a %s, but found a %s. Removing %s from client view of cluster.", SHARD_ROUTER, newDescription.getType(), newDescription.getAddress())); removeServer(newDescription.getAddress()); } return true; }
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); }
private boolean handleReplicaSetMemberChanged(final ServerDescription newDescription) { if (!newDescription.isReplicaSetMember()) { LOGGER.error(format("Expecting replica set member, but found a %s. Removing %s from client view of cluster.", newDescription.getType(), newDescription.getAddress())); removeServer(newDescription.getAddress()); return true; if (newDescription.getType() == REPLICA_SET_GHOST) { if (LOGGER.isInfoEnabled()) { LOGGER.info(format("Server %s does not appear to be a member of an initiated replica set.", newDescription.getAddress())); replicaSetName = newDescription.getSetName(); if (!replicaSetName.equals(newDescription.getSetName())) { LOGGER.error(format("Expecting replica set member from set '%s', but found one from set '%s'. " + "Removing %s from client view of cluster.", replicaSetName, newDescription.getSetName(), newDescription.getAddress())); removeServer(newDescription.getAddress()); return true; if (newDescription.getCanonicalAddress() != null && !newDescription.getAddress().equals(new ServerAddress(newDescription.getCanonicalAddress()))) { if (LOGGER.isInfoEnabled()) { LOGGER.info(format("Canonical address %s does not match server address. Removing %s from client view of cluster", newDescription.getCanonicalAddress(), newDescription.getAddress())); removeServer(newDescription.getAddress()); return true; if (newDescription.isPrimary()) {
@Override public int compare(final ServerDescription o1, final ServerDescription o2) { int val = o1.getAddress().getHost().compareTo(o2.getAddress().getHost()); if (val != 0) { return val; } return integerCompare(o1.getAddress().getPort(), o2.getAddress().getPort()); }
@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();
newDescription.getAddress(), newDescription)); ServerTuple serverTuple = addressToServerTupleMap.get(newDescription.getAddress()); if (serverTuple == null) { if (LOGGER.isTraceEnabled()) { LOGGER.trace(format("Ignoring description changed event for removed server %s", newDescription.getAddress())); if (event.getNewDescription().isOk()) { if (clusterType == UNKNOWN && newDescription.getType() != REPLICA_SET_GHOST) { clusterType = newDescription.getClusterType(); if (LOGGER.isInfoEnabled()) { LOGGER.info(format("Discovered cluster type of %s", clusterType));
/** * Gets the ServerAddress of the master server in this replica set. * * @return master or null if don't have one * @throws MongoException if there's a failure */ @SuppressWarnings("deprecation") @Nullable public ServerAddress getMaster() { List<ServerDescription> primaries = getClusterDescription().getPrimaries(); return primaries.isEmpty() ? null : primaries.get(0).getAddress(); }
private void ensureServers(final ServerDescription description) { if (description.isPrimary() || !hasPrimary()) { addNewHosts(description.getHosts()); addNewHosts(description.getPassives()); addNewHosts(description.getArbiters()); } if (description.isPrimary()) { removeExtraHosts(description); } }
/** * 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(); }
@Override public void serverDescriptionChanged(final ServerDescriptionChangedEvent event) { ServerDescription descriptionToPublish = event.getNewDescription(); if (event.getNewDescription().isOk()) { if (getSettings().getRequiredClusterType() != ClusterType.UNKNOWN && getSettings().getRequiredClusterType() != event.getNewDescription().getClusterType()) { descriptionToPublish = null; } else if (getSettings().getRequiredClusterType() == ClusterType.REPLICA_SET && getSettings().getRequiredReplicaSetName() != null) { if (!getSettings().getRequiredReplicaSetName().equals(event.getNewDescription().getSetName())) { descriptionToPublish = null; } } } publishDescription(descriptionToPublish); } }
private Set<ServerAddress> getAllServerAddresses(final ServerDescription serverDescription) { Set<ServerAddress> retVal = new HashSet<ServerAddress>(); addHostsToSet(serverDescription.getHosts(), retVal); addHostsToSet(serverDescription.getPassives(), retVal); addHostsToSet(serverDescription.getArbiters(), retVal); return retVal; }
private void invalidateOldPrimaries(final ServerAddress newPrimary) { for (final ServerTuple serverTuple : addressToServerTupleMap.values()) { if (!serverTuple.description.getAddress().equals(newPrimary) && serverTuple.description.isPrimary()) { if (LOGGER.isInfoEnabled()) { LOGGER.info(format("Rediscovering type of existing primary %s", serverTuple.description.getAddress())); } serverTuple.server.invalidate(); } } }
/** * Returns the ServerDescription for the server at the given address * * @param serverAddress the ServerAddress for a server in this cluster * @return the ServerDescription for this server * @deprecated Replace with a filter on ServerDescription in the caller */ @Deprecated public ServerDescription getByServerAddress(final ServerAddress serverAddress) { for (final ServerDescription cur : serverDescriptions) { if (cur.isOk() && cur.getAddress().equals(serverAddress)) { return cur; } } return null; }
CountDownLatch prevPhase = request.phase; request.phase = currentPhase; if (!description.isCompatibleWithDriver()) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Asynchronously failed server selection due to driver incompatibility with server"); if (server != null) { if (LOGGER.isTraceEnabled()) { LOGGER.trace(format("Asynchronously selected server %s", server.getDescription().getAddress()));
private void publishDescription(final ServerDescription serverDescription) { ClusterType clusterType = getSettings().getRequiredClusterType(); if (clusterType == ClusterType.UNKNOWN && serverDescription != null) { clusterType = serverDescription.getClusterType(); } ClusterDescription oldDescription = getCurrentDescription(); ClusterDescription description = new ClusterDescription(ClusterConnectionMode.SINGLE, clusterType, serverDescription == null ? Collections.<ServerDescription>emptyList() : singletonList(serverDescription), getSettings(), getServerFactory().getSettings()); updateDescription(description); fireChangeEvent(new ClusterDescriptionChangedEvent(getClusterId(), description, oldDescription == null ? getInitialDescription() : oldDescription)); }
private ServerDescription getConnectingServerDescription(final ServerAddress serverAddress) { return ServerDescription.builder().state(CONNECTING).address(serverAddress).build(); }
/** * Construct a defaulted connection description instance. * * @param serverId the server address */ public ConnectionDescription(final ServerId serverId) { this(new ConnectionId(serverId), new ServerVersion(), 0, ServerType.UNKNOWN, DEFAULT_MAX_WRITE_BATCH_SIZE, getDefaultMaxDocumentSize(), DEFAULT_MAX_MESSAGE_SIZE, Collections.<String>emptyList()); }