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

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

Overview

Defines behaviour for when a cluster is in single topology.

Since:

  • 2.0.0

Constant Summary

NAME =

The display name for the topology.

Since:

  • 2.0.0

'Single'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Monitoring::Publishable

#publish_command, #publish_event, #publish_sdam_event

Constructor Details

#initialize(options, monitoring, seeds = []) ⇒ Single

Initialize the topology with the options.

Examples:

Initialize the topology.

Single.new(options)

Parameters:

  • options (Hash)

    The options.

  • monitoring (Monitoring)

    The monitoring.

  • seeds (Array<String>) (defaults to: [])

    The seeds.

Since:

  • 2.0.0



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

def initialize(options, monitoring, seeds = [])
  @options = options
  @monitoring = monitoring
  @seed = seeds.first
end

Instance Attribute Details

#monitoringmonitoring (readonly)

Returns monitoring the monitoring.

Returns:

Since:

  • 2.0.0



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

def monitoring
  @monitoring
end

#optionsHash (readonly)

Returns options The options.

Returns:

  • (Hash)

    options The options.

Since:

  • 2.0.0



31
32
33
# File 'lib/mongo/cluster/topology/single.rb', line 31

def options
  @options
end

#seedString (readonly)

Returns seed The seed address.

Returns:

  • (String)

    seed The seed address.

Since:

  • 2.0.0



34
35
36
# File 'lib/mongo/cluster/topology/single.rb', line 34

def seed
  @seed
end

Instance Method Details

#add_hosts?(description, servers) ⇒ false

Whether a server description's hosts may be added to the cluster.

Examples:

Check if a description's hosts may be added to the cluster.

topology.add_hosts?(description, servers)

Parameters:

Returns:

  • (false)

    A description's hosts are never added to a cluster of Single topology.

Since:

  • 2.0.6



154
# File 'lib/mongo/cluster/topology/single.rb', line 154

def add_hosts?(description, servers); false; end

#display_nameString

Get the display name.

Examples:

Get the display name.

Single.display_name

Returns:

  • (String)

    The display name.

Since:

  • 2.0.0



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

def display_name
  NAME
end

#elect_primary(description, servers) ⇒ Single

Elect a primary server within this topology.

Examples:

Elect a primary server.

topology.elect_primary(description, servers)

Parameters:

  • description (Server::Description)

    The description of the elected primary.

  • servers (Array<Server>)

    The list of known servers to the cluster.

Returns:

Since:

  • 2.0.0



62
# File 'lib/mongo/cluster/topology/single.rb', line 62

def elect_primary(description, servers); self; 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:

  • cluster (Cluster)

    The cluster.

  • server_selector (ServerSelector) (defaults to: nil)

    The server selector.

Returns:

  • (true)

    A standalone always has a readable server.

Since:

  • 2.4.0



77
# File 'lib/mongo/cluster/topology/single.rb', line 77

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



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

def has_writable_server?(cluster); true; end

#member_discoveredObject

Publish that a member of this topology was discovered.

Examples:

Publish that a member was discovered.

topology.member_discovered

Since:

  • 2.4.0



229
230
231
232
233
234
# File 'lib/mongo/cluster/topology/single.rb', line 229

def member_discovered
  publish_sdam_event(
    Monitoring::TOPOLOGY_CHANGED,
    Monitoring::Event::TopologyChanged.new(self, self)
  )
end

#remove_hosts?(description) ⇒ true

Whether a description can be used to remove hosts from the cluster.

the cluster.

topology.remove_hosts?(description)

Examples:

Check if a description can be used to remove hosts from

Parameters:

Returns:

  • (true)

    A description can never be used to remove hosts from a cluster of Single topology.

Since:

  • 2.0.6



168
# File 'lib/mongo/cluster/topology/single.rb', line 168

def remove_hosts?(description); false; end

#remove_server?(description, server) ⇒ false

Whether a specific server in the cluster can be removed, given a description.

Examples:

Check if a specific server can be removed from the cluster.

topology.remove_server?(description, server)

Parameters:

Returns:

  • (false)

    A server is never removed from a cluster of Single topology.

Since:

  • 2.0.6



181
# File 'lib/mongo/cluster/topology/single.rb', line 181

def remove_server?(description, server); false; 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



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

def replica_set?; false; end

#replica_set_namenil

Single topologies have no replica set name.

Examples:

Get the replica set name.

single.replica_set_name

Returns:

  • (nil)

    Always nil.

Since:

  • 2.0.0



126
# File 'lib/mongo/cluster/topology/single.rb', line 126

def replica_set_name; nil; 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



138
139
140
# File 'lib/mongo/cluster/topology/single.rb', line 138

def servers(servers, name = nil)
  [ servers.detect { |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



191
# File 'lib/mongo/cluster/topology/single.rb', line 191

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



201
# File 'lib/mongo/cluster/topology/single.rb', line 201

def single?; true; end

#standalone_discoveredTopology::Single

Notify the topology that a standalone was discovered.

Examples:

Notify the topology that a standalone was discovered.

topology.standalone_discovered

Returns:

Since:

  • 2.0.6



221
# File 'lib/mongo/cluster/topology/single.rb', line 221

def standalone_discovered; self; end

#unknown?false

An single topology is not unknown.

Examples:

Is the topology unknown?

Single.unknown?

Returns:

  • (false)

    Always false.

Since:

  • 2.0.0



211
# File 'lib/mongo/cluster/topology/single.rb', line 211

def unknown?; false; end