Module: Mongo::ServerSelector::Selectable
- Included in:
- Nearest, Primary, PrimaryPreferred, Secondary, SecondaryPreferred
- Defined in:
- lib/mongo/server_selector/selectable.rb
Overview
Provides common behavior for filtering a list of servers by server mode or tag set.
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
Options The options.
-
#tag_sets ⇒ Array
readonly
Tag_sets The tag sets used to select servers.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Check equality of two server selector.
-
#initialize(options = {}) ⇒ Object
Initialize the server selector.
-
#inspect ⇒ String
Inspect the server selector.
-
#local_threshold ⇒ Float
Get the local threshold boundary for nearest selection in seconds.
-
#select_server(cluster, ping = true) ⇒ Mongo::Server
Select a server from eligible candidates.
-
#server_selection_timeout ⇒ Float
Get the timeout for server selection.
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns options The options.
24 25 26 |
# File 'lib/mongo/server_selector/selectable.rb', line 24 def @options end |
#tag_sets ⇒ Array (readonly)
Returns tag_sets The tag sets used to select servers.
27 28 29 |
# File 'lib/mongo/server_selector/selectable.rb', line 27 def tag_sets @tag_sets end |
Instance Method Details
#==(other) ⇒ true, false
Check equality of two server selector.
39 40 41 |
# File 'lib/mongo/server_selector/selectable.rb', line 39 def ==(other) name == other.name && tag_sets == other.tag_sets end |
#initialize(options = {}) ⇒ Object
Initialize the server selector.
63 64 65 66 67 68 |
# File 'lib/mongo/server_selector/selectable.rb', line 63 def initialize( = {}) @options = ( || {}).freeze tag_sets = [:tag_sets] || [] validate_tag_sets!(tag_sets) @tag_sets = tag_sets.freeze end |
#inspect ⇒ String
Inspect the server selector.
78 79 80 81 |
# File 'lib/mongo/server_selector/selectable.rb', line 78 def inspect "#<#{self.class.name}:0x#{object_id} tag_sets=#{tag_sets.inspect} " + "server_selection_timeout=#{server_selection_timeout} local_threshold=#{local_threshold}>" end |
#local_threshold ⇒ Float
Get the local threshold boundary for nearest selection in seconds.
133 134 135 |
# File 'lib/mongo/server_selector/selectable.rb', line 133 def local_threshold @local_threshold ||= ([:local_threshold] || ServerSelector::LOCAL_THRESHOLD) end |
#select_server(cluster, ping = true) ⇒ Mongo::Server
Select a server from eligible candidates.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/mongo/server_selector/selectable.rb', line 93 def select_server(cluster, ping = true) deadline = Time.now + server_selection_timeout while (deadline - Time.now) > 0 servers = candidates(cluster) if servers && !servers.compact.empty? server = servers.first # There is no point pinging a standalone as the subsequent scan is # not going to change anything about the cluster. if ping && !cluster.single? return server if server.connectable? else return server end end cluster.scan! end raise Error::NoServerAvailable.new(self) end |
#server_selection_timeout ⇒ Float
Get the timeout for server selection.
120 121 122 123 |
# File 'lib/mongo/server_selector/selectable.rb', line 120 def server_selection_timeout @server_selection_timeout ||= ([:server_selection_timeout] || ServerSelector::SERVER_SELECTION_TIMEOUT) end |