lib/mongo/server_selector/selectable.rb in mongo-2.2.7 vs lib/mongo/server_selector/selectable.rb in mongo-2.3.0
- old
+ new
@@ -1,6 +1,6 @@
-# Copyright (C) 2014-2015 MongoDB, Inc.
+# Copyright (C) 2014-2016 MongoDB, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@@ -35,11 +35,12 @@
#
# @return [ true, false ] Whether the objects are equal.
#
# @since 2.0.0
def ==(other)
- name == other.name && tag_sets == other.tag_sets
+ name == other.name &&
+ tag_sets == other.tag_sets
end
# Initialize the server selector.
#
# @example Initialize the selector.
@@ -48,13 +49,10 @@
# @example Initialize the preference with no options.
# Mongo::ServerSelector::Secondary.new
#
# @param [ Hash ] options The server preference options.
#
- # @option options [ Integer ] :server_selection_timeout The timeout in seconds
- # for selecting a server.
- #
# @option options [ Integer ] :local_threshold The local threshold boundary for
# nearest selection in seconds.
#
# @raise [ Error::InvalidServerPreference ] If tag sets are specified
# but not allowed.
@@ -74,12 +72,11 @@
#
# @return [ String ] The inspection.
#
# @since 2.2.0
def inspect
- "#<#{self.class.name}:0x#{object_id} tag_sets=#{tag_sets.inspect} " +
- "server_selection_timeout=#{server_selection_timeout} local_threshold=#{local_threshold}>"
+ "#<#{self.class.name}:0x#{object_id} tag_sets=#{tag_sets.inspect}>"
end
# Select a server from eligible candidates.
#
# @example Select a server from the cluster.
@@ -89,10 +86,12 @@
#
# @return [ Mongo::Server ] A server matching the server preference.
#
# @since 2.0.0
def select_server(cluster, ping = true)
+ @local_threshold = cluster.options[:local_threshold] || LOCAL_THRESHOLD
+ @server_selection_timeout = cluster.options[:server_selection_timeout] || SERVER_SELECTION_TIMEOUT
deadline = Time.now + server_selection_timeout
while (deadline - Time.now) > 0
servers = candidates(cluster)
if servers && !servers.compact.empty?
server = servers.first
@@ -115,10 +114,13 @@
# selector.server_selection_timeout
#
# @return [ Float ] The timeout.
#
# @since 2.0.0
+ #
+ # @deprecated This setting is now taken from the cluster options when a server is selected.
+ # Will be removed in 3.0.
def server_selection_timeout
@server_selection_timeout ||=
(options[:server_selection_timeout] || ServerSelector::SERVER_SELECTION_TIMEOUT)
end
@@ -128,9 +130,12 @@
# selector.local_threshold
#
# @return [ Float ] The local threshold.
#
# @since 2.0.0
+ #
+ # @deprecated This setting is now taken from the cluster options when a server is selected.
+ # Will be removed in 3.0.
def local_threshold
@local_threshold ||= (options[:local_threshold] || ServerSelector::LOCAL_THRESHOLD)
end
private