Class: Mongo::Cluster::Topology::Single

Inherits:
Base
  • Object
show all
Defined in:
lib/mongo/cluster/topology/single.rb

Overview

Defines behavior for when a cluster is in single topology.

Since:

  • 2.0.0

Constant Summary collapse

NAME =

The display name for the topology.

Since:

  • 2.0.0

'Single'

Constants included from Loggable

Loggable::PREFIX

Instance Attribute Summary

Attributes inherited from Base

#compatibility_error, #logical_session_timeout, #monitoring, #options, #server_descriptions

Attributes included from Monitoring::Publishable

#monitoring

Instance Method Summary collapse

Methods inherited from Base

#addresses, #compatible?, #data_bearing_servers?, #initialize, #max_election_id, #max_set_version, #new_max_election_id, #new_max_set_version, #replica_set_name, #server_hosts_match_any?

Methods included from Monitoring::Publishable

#publish_cmap_event, #publish_event, #publish_sdam_event

Methods included from Loggable

#log_debug, #log_error, #log_fatal, #log_info, #log_warn, #logger

Constructor Details

This class inherits a constructor from Mongo::Cluster::Topology::Base

Instance Method Details

#display_nameString

Get the display name.

Examples:

Get the display name.

Single.display_name

Returns:

  • (String)

    The display name.

Since:

  • 2.0.0



37
38
39
# File 'lib/mongo/cluster/topology/single.rb', line 37

def display_name
  self.class.name.gsub(/.*::/, '')
end

#has_readable_server?(_cluster, _server_selector = nil) ⇒ true

Determine if the topology would select a readable server for the provided candidates and read preference.

Examples:

Is a readable server present?

topology.has_readable_server?(cluster, server_selector)

Parameters:

Returns:

  • (true)

    A standalone always has a readable server.

Since:

  • 2.4.0



63
64
65
# File 'lib/mongo/cluster/topology/single.rb', line 63

def has_readable_server?(_cluster, _server_selector = nil)
  true
end

#has_writable_server?(_cluster) ⇒ true

Determine if the topology would select a writable server for the provided candidates.

Examples:

Is a writable server present?

topology.has_writable_server?(servers)

Parameters:

  • cluster (Cluster)

    The cluster.

Returns:

  • (true)

    A standalone always has a writable server.

Since:

  • 2.4.0



78
79
80
# File 'lib/mongo/cluster/topology/single.rb', line 78

def has_writable_server?(_cluster)
  true
end

#replica_set?false

A single topology is not a replica set.

Examples:

Is the topology a replica set?

Single.replica_set?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0



90
91
92
# File 'lib/mongo/cluster/topology/single.rb', line 90

def replica_set?
  false
end

#servers(servers, _name = nil) ⇒ Array<Server>

Select appropriate servers for this topology.

Examples:

Select the servers.

Single.servers(servers, 'test')

Parameters:

  • servers (Array<Server>)

    The known servers.

Returns:

  • (Array<Server>)

    The single servers.

Since:

  • 2.0.0



104
105
106
# File 'lib/mongo/cluster/topology/single.rb', line 104

def servers(servers, _name = nil)
  servers.reject { |server| server.unknown? }
end

#sharded?false

A single topology is not sharded.

Examples:

Is the topology sharded?

Single.sharded?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0



116
117
118
# File 'lib/mongo/cluster/topology/single.rb', line 116

def sharded?
  false
end

#single?true

A single topology is single.

Examples:

Is the topology single?

Single.single?

Returns:

  • (true)

    Always true.

Since:

  • 2.0.0



128
129
130
# File 'lib/mongo/cluster/topology/single.rb', line 128

def single?
  true
end

#summaryObject

Note:

This method is experimental and subject to change.

Since:

  • 2.7.0



45
46
47
48
# File 'lib/mongo/cluster/topology/single.rb', line 45

def summary
  details = server_descriptions.keys.join(',')
  "#{display_name}[#{details}]"
end

#unknown?false

A single topology is not unknown.

Examples:

Is the topology unknown?

Single.unknown?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0



140
141
142
# File 'lib/mongo/cluster/topology/single.rb', line 140

def unknown?
  false
end