Class: Mongo::Event::MemberDiscovered

Inherits:
Base
  • Object
show all
Includes:
Monitoring::Publishable
Defined in:
lib/mongo/event/member_discovered.rb

Overview

This handles member discovered events for server descriptions.

Since:

  • 2.4.0

Constant Summary

Constants included from Loggable

Loggable::PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Monitoring::Publishable

#publish_command, #publish_event, #publish_sdam_event

Methods included from Loggable

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

Methods inherited from Base

#inspect

Constructor Details

#initialize(cluster) ⇒ MemberDiscovered

Initialize the new member discovered event handler.

Examples:

Create the new handler.

MemberDiscovered.new(cluster)

Parameters:

Since:

  • 2.0.0



43
44
45
46
47
# File 'lib/mongo/event/member_discovered.rb', line 43

def initialize(cluster)
  @cluster = cluster
  @options = cluster.options
  @monitoring = cluster.monitoring
end

Instance Attribute Details

#clusterMongo::Cluster (readonly)

Returns cluster The cluster.

Returns:

Since:

  • 2.4.0



27
28
29
# File 'lib/mongo/event/member_discovered.rb', line 27

def cluster
  @cluster
end

#monitoringMonitoring (readonly)

Returns monitoring The monitoring.

Returns:

Since:

  • 2.4.0



33
34
35
# File 'lib/mongo/event/member_discovered.rb', line 33

def monitoring
  @monitoring
end

#optionsHash (readonly)

Returns options The options.

Returns:

  • (Hash)

    options The options.

Since:

  • 2.4.0



30
31
32
# File 'lib/mongo/event/member_discovered.rb', line 30

def options
  @options
end

Instance Method Details

#handle(previous, updated) ⇒ Object

This event tells the cluster that a member of a topology is discovered.

Examples:

Handle the event.

member_discovered.handle(previous_description, description)

Parameters:

Since:

  • 2.4.0



58
59
60
61
62
63
64
# File 'lib/mongo/event/member_discovered.rb', line 58

def handle(previous, updated)
  if updated.primary? || updated.mongos?
    cluster.elect_primary!(updated)
  else
    cluster.member_discovered
  end
end