Class: Mongo::Server
- Inherits:
-
Object
- Object
- Mongo::Server
- Extended by:
- Forwardable
- Defined in:
- lib/mongo/server.rb,
lib/mongo/server/context.rb,
lib/mongo/server/monitor.rb,
lib/mongo/server/connection.rb,
lib/mongo/server/connectable.rb,
lib/mongo/server/description.rb,
lib/mongo/server/connection_pool.rb,
lib/mongo/server/monitor/connection.rb,
lib/mongo/server/description/features.rb,
lib/mongo/server/connection_pool/queue.rb,
lib/mongo/server/description/inspector.rb,
lib/mongo/server/description/inspector/primary_elected.rb,
lib/mongo/server/description/inspector/description_changed.rb,
lib/mongo/server/description/inspector/standalone_discovered.rb
Overview
Represents a single server on the server side that can be standalone, part of a replica set, or a mongos.
Defined Under Namespace
Modules: Connectable Classes: Connection, ConnectionPool, Context, Description, Monitor
Instance Attribute Summary collapse
-
#address ⇒ String
readonly
The configured address for the server.
-
#cluster ⇒ Cluster
readonly
Cluster The server cluster.
-
#monitor ⇒ Monitor
readonly
Monitor The server monitor.
-
#monitoring ⇒ Monitoring
readonly
Monitoring The monitoring.
-
#options ⇒ Hash
readonly
The options hash.
Class Method Summary collapse
-
.finalize(monitor) ⇒ Object
When the server is flagged for garbage collection, stop the monitor thread.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Is this server equal to another?.
-
#connectable? ⇒ true, false
Determine if a connection to the server is able to be established and messages can be sent to it.
-
#context ⇒ Mongo::Server::Context
Get a new context for this server in which to send messages.
-
#disconnect! ⇒ true
Disconnect the server from the connection.
-
#initialize(address, cluster, monitoring, event_listeners, options = {}) ⇒ Server
constructor
private
Instantiate a new server object.
-
#inspect ⇒ String
Get a pretty printed server inspection.
-
#matches_tag_set?(tag_set) ⇒ true, false
Determine if the provided tags are a subset of the server’s tags.
-
#pool ⇒ Mongo::Pool
Get the connection pool for this server.
-
#reconnect! ⇒ true
Restart the server monitor.
Constructor Details
#initialize(address, cluster, monitoring, event_listeners, options = {}) ⇒ Server
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Server must never be directly instantiated outside of a Cluster.
Instantiate a new server object. Will start the background refresh and subscribe to the appropriate events.
153 154 155 156 157 158 159 160 161 162 |
# File 'lib/mongo/server.rb', line 153 def initialize(address, cluster, monitoring, event_listeners, = {}) @address = address @cluster = cluster @monitoring = monitoring @options = .freeze @monitor = Monitor.new(address, event_listeners, ) monitor.scan! monitor.run! ObjectSpace.define_finalizer(self, self.class.finalize(monitor)) end |
Instance Attribute Details
#address ⇒ String (readonly)
Returns The configured address for the server.
32 33 34 |
# File 'lib/mongo/server.rb', line 32 def address @address end |
#cluster ⇒ Cluster (readonly)
Returns cluster The server cluster.
35 36 37 |
# File 'lib/mongo/server.rb', line 35 def cluster @cluster end |
#monitor ⇒ Monitor (readonly)
Returns monitor The server monitor.
38 39 40 |
# File 'lib/mongo/server.rb', line 38 def monitor @monitor end |
#monitoring ⇒ Monitoring (readonly)
Returns monitoring The monitoring.
44 45 46 |
# File 'lib/mongo/server.rb', line 44 def monitoring @monitoring end |
#options ⇒ Hash (readonly)
Returns The options hash.
41 42 43 |
# File 'lib/mongo/server.rb', line 41 def @options end |
Class Method Details
.finalize(monitor) ⇒ Object
When the server is flagged for garbage collection, stop the monitor thread.
132 133 134 |
# File 'lib/mongo/server.rb', line 132 def self.finalize(monitor) proc { monitor.stop! } end |
Instance Method Details
#==(other) ⇒ true, false
Is this server equal to another?
78 79 80 81 |
# File 'lib/mongo/server.rb', line 78 def ==(other) return false unless other.is_a?(Server) address == other.address end |
#connectable? ⇒ true, false
Determine if a connection to the server is able to be established and messages can be sent to it.
104 105 106 107 108 |
# File 'lib/mongo/server.rb', line 104 def connectable? context.with_connection do |connection| connection.connectable? end end |
#context ⇒ Mongo::Server::Context
Get a new context for this server in which to send messages.
91 92 93 |
# File 'lib/mongo/server.rb', line 91 def context Context.new(self) end |
#disconnect! ⇒ true
Disconnect the server from the connection.
118 119 120 121 |
# File 'lib/mongo/server.rb', line 118 def disconnect! pool.disconnect! monitor.stop! and true end |
#inspect ⇒ String
Get a pretty printed server inspection.
172 173 174 |
# File 'lib/mongo/server.rb', line 172 def inspect "#<Mongo::Server:0x#{object_id} address=#{address.host}:#{address.port}>" end |
#matches_tag_set?(tag_set) ⇒ true, false
Determine if the provided tags are a subset of the server’s tags.
198 199 200 201 202 |
# File 'lib/mongo/server.rb', line 198 def matches_tag_set?(tag_set) tag_set.keys.all? do |k| [k] && [k] == tag_set[k] end end |
#pool ⇒ Mongo::Pool
Get the connection pool for this server.
184 185 186 |
# File 'lib/mongo/server.rb', line 184 def pool @pool ||= cluster.pool(self) end |
#reconnect! ⇒ true
Restart the server monitor.
212 213 214 |
# File 'lib/mongo/server.rb', line 212 def reconnect! monitor.restart! and true end |