Class: Mongo::Server
- Inherits:
-
Object
- Object
- Mongo::Server
- Extended by:
- Forwardable
- Includes:
- Monitoring::Publishable
- 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/member_discovered.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
deprecated
Deprecated.
Will be removed in version 3.0
-
#disconnect! ⇒ true
Disconnect the server from the connection.
-
#handle_auth_failure! ⇒ Object
Handle authentication failure.
-
#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.
-
#with_connection(&block) ⇒ Object
Execute a block of code with a connection, that is checked out of the server’s pool and then checked back in.
Methods included from Monitoring::Publishable
#publish_command, #publish_event, #publish_sdam_event
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.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/mongo/server.rb', line 163 def initialize(address, cluster, monitoring, event_listeners, = {}) @address = address @cluster = cluster @monitoring = monitoring @options = .freeze publish_sdam_event( Monitoring::SERVER_OPENING, Monitoring::Event::ServerOpening.new(address, cluster.topology) ) @monitor = Monitor.new(address, event_listeners, .merge(app_metadata: cluster.)) 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.
33 34 35 |
# File 'lib/mongo/server.rb', line 33 def address @address end |
#cluster ⇒ Cluster (readonly)
Returns cluster The server cluster.
36 37 38 |
# File 'lib/mongo/server.rb', line 36 def cluster @cluster end |
#monitor ⇒ Monitor (readonly)
Returns monitor The server monitor.
39 40 41 |
# File 'lib/mongo/server.rb', line 39 def monitor @monitor end |
#monitoring ⇒ Monitoring (readonly)
Returns monitoring The monitoring.
45 46 47 |
# File 'lib/mongo/server.rb', line 45 def monitoring @monitoring end |
#options ⇒ Hash (readonly)
Returns The options hash.
42 43 44 |
# File 'lib/mongo/server.rb', line 42 def @options end |
Class Method Details
.finalize(monitor) ⇒ Object
When the server is flagged for garbage collection, stop the monitor thread.
142 143 144 |
# File 'lib/mongo/server.rb', line 142 def self.finalize(monitor) proc { monitor.stop! } end |
Instance Method Details
#==(other) ⇒ true, false
Is this server equal to another?
86 87 88 89 |
# File 'lib/mongo/server.rb', line 86 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.
114 115 116 117 118 |
# File 'lib/mongo/server.rb', line 114 def connectable? with_connection do |connection| connection.connectable? end end |
#context ⇒ Mongo::Server::Context
Will be removed in version 3.0
Get a new context for this server in which to send messages.
101 102 103 |
# File 'lib/mongo/server.rb', line 101 def context Context.new(self) end |
#disconnect! ⇒ true
Disconnect the server from the connection.
128 129 130 131 |
# File 'lib/mongo/server.rb', line 128 def disconnect! pool.disconnect! monitor.stop! and true end |
#handle_auth_failure! ⇒ Object
Handle authentication failure.
257 258 259 260 261 262 |
# File 'lib/mongo/server.rb', line 257 def handle_auth_failure! yield rescue Auth::Unauthorized unknown! raise end |
#inspect ⇒ String
Get a pretty printed server inspection.
186 187 188 |
# File 'lib/mongo/server.rb', line 186 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.
212 213 214 215 216 |
# File 'lib/mongo/server.rb', line 212 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.
198 199 200 |
# File 'lib/mongo/server.rb', line 198 def pool @pool ||= cluster.pool(self) end |
#reconnect! ⇒ true
Restart the server monitor.
226 227 228 |
# File 'lib/mongo/server.rb', line 226 def reconnect! monitor.restart! and true end |
#with_connection(&block) ⇒ Object
Execute a block of code with a connection, that is checked out of the server’s pool and then checked back in.
241 242 243 |
# File 'lib/mongo/server.rb', line 241 def with_connection(&block) pool.with_connection(&block) end |