Class: Mongo::Event::DescriptionChanged

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

Overview

This handles a change in description.

Since:

  • 2.0.6

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Monitoring::Publishable

#publish_command, #publish_event, #publish_sdam_event

Constructor Details

#initialize(cluster) ⇒ DescriptionChanged

Initialize the new host added event handler.

Examples:

Create the new handler.

ServerAdded.new(cluster)

Parameters:

Since:

  • 2.0.0



42
43
44
45
46
# File 'lib/mongo/event/description_changed.rb', line 42

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.0.6



26
27
28
# File 'lib/mongo/event/description_changed.rb', line 26

def cluster
  @cluster
end

#monitoringMonitoring (readonly)

Returns monitoring The monitoring.

Returns:

Since:

  • 2.0.6



32
33
34
# File 'lib/mongo/event/description_changed.rb', line 32

def monitoring
  @monitoring
end

#optionsHash (readonly)

Returns options The options.

Returns:

  • (Hash)

    options The options.

Since:

  • 2.0.6



29
30
31
# File 'lib/mongo/event/description_changed.rb', line 29

def options
  @options
end

Instance Method Details

#handle(previous, updated) ⇒ Object

This event publishes an event to add the cluster and logs the configuration change.

Examples:

Handle the event.

server_added.handle('127.0.0.1:27018')

Parameters:

Since:

  • 2.0.0



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/mongo/event/description_changed.rb', line 57

def handle(previous, updated)
  publish_sdam_event(
    Monitoring::SERVER_DESCRIPTION_CHANGED,
    Monitoring::Event::ServerDescriptionChanged.new(
      updated.address,
      cluster.topology,
      previous,
      updated
    )
  )
  cluster.add_hosts(updated)
  cluster.remove_hosts(updated)
end