Class: Mongo::Server::Description::Inspector

Inherits:
Object
  • Object
show all
Defined in:
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

Handles inspection of an updated server description to determine if events should be fired.

Since:

  • 2.0.0

Defined Under Namespace

Classes: DescriptionChanged, MemberDiscovered, PrimaryElected, StandaloneDiscovered

Constant Summary

INSPECTORS =

Static list of inspections that are performed on the result of an ismaster command in order to generate the appropriate events for the changes.

Since:

  • 2.0.0

[
    Inspector::StandaloneDiscovered,
    Inspector::DescriptionChanged,
    Inspector::MemberDiscovered
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(listeners) ⇒ Inspector

Create the new inspector.

Examples:

Create the new inspector.

Inspector.new(listeners)

Parameters:

Since:

  • 2.0.0



53
54
55
56
57
# File 'lib/mongo/server/description/inspector.rb', line 53

def initialize(listeners)
  @inspectors = INSPECTORS.map do |inspector|
    inspector.new(listeners)
  end
end

Instance Attribute Details

#inspectorsArray (readonly)

Returns inspectors The description inspectors.

Returns:

  • (Array)

    inspectors The description inspectors.

Since:

  • 2.0.0



43
44
45
# File 'lib/mongo/server/description/inspector.rb', line 43

def inspectors
  @inspectors
end

Instance Method Details

#run(description, ismaster, average_round_trip_time) ⇒ Description

Run the server description inspector.

Examples:

Run the inspector.

inspector.run(description, { 'ismaster' => true })

Parameters:

  • description (Description)

    The old description.

  • ismaster (Hash)

    The updated ismaster.

  • average_round_trip_time (Float)

    The moving average round trip time (sec).

Returns:

Since:

  • 2.0.0



71
72
73
74
75
76
77
# File 'lib/mongo/server/description/inspector.rb', line 71

def run(description, ismaster, average_round_trip_time)
  new_description = Description.new(description.address, ismaster, average_round_trip_time)
  inspectors.each do |inspector|
    inspector.run(description, new_description)
  end
  new_description
end