Class: Mongo::Event::MemberDiscovered

Inherits:
Object
  • 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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Monitoring::Publishable

#publish_command, #publish_event, #publish_sdam_event

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



41
42
43
44
45
# File 'lib/mongo/event/member_discovered.rb', line 41

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



25
26
27
# File 'lib/mongo/event/member_discovered.rb', line 25

def cluster
  @cluster
end

#monitoringMonitoring (readonly)

Returns monitoring The monitoring.

Returns:

Since:

  • 2.4.0



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

def monitoring
  @monitoring
end

#optionsHash (readonly)

Returns options The options.

Returns:

  • (Hash)

    options The options.

Since:

  • 2.4.0



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

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



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

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