Class: Arborist::Event

Inherits:
Object
  • Object
show all
Extended by:
Loggability, Pluggability
Defined in:
lib/arborist/event.rb

Overview

The representation of activity in the manager; events are broadcast when node state changes, when they’re updated, and when various other operational actions take place, e.g., the node tree gets reloaded.

Direct Known Subclasses

Node

Defined Under Namespace

Classes: Node, NodeAcked, NodeDelta, NodeDisabled, NodeDown, NodeQuieted, NodeUnknown, NodeUp, NodeUpdate, NodeWarn

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload) ⇒ Event

Create a new event with the specified payload data.



25
26
27
28
# File 'lib/arborist/event.rb', line 25

def initialize( payload )
	payload = payload.clone unless payload.nil?
	@payload = payload
end

Instance Attribute Details

#payloadObject (readonly)

The event payload specific to the event type



36
37
38
# File 'lib/arborist/event.rb', line 36

def payload
  @payload
end

Instance Method Details

#informational?Boolean Also known as: is_informational?

Returns true if the event contains node information other than about a change in its state.

Returns:

  • (Boolean)


50
51
52
# File 'lib/arborist/event.rb', line 50

def informational?
	return false
end

#inspectObject

Return a string representation of the object suitable for debugging.



76
77
78
79
80
81
82
# File 'lib/arborist/event.rb', line 76

def inspect
	return "#<%p:%#016x %s>" % [
		self.class,
		self.object_id * 2,
		self.inspect_details,
	]
end

#inspect_detailsObject

Return the detail portion of the #inspect string appropriate for this event type.



86
87
88
# File 'lib/arborist/event.rb', line 86

def inspect_details
	return self.payload.inspect
end

#match(object) ⇒ Object Also known as: =~

Match operator – returns true if the other object matches this event.



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

def match( object )
	rval = object.respond_to?( :event_type ) &&
	   ( object.event_type.nil? || object.event_type == self.type )
	self.log.debug "Base node #match: %p" % [ rval ]
	return rval
end

#to_hObject

Return the event as a Hash.



67
68
69
70
71
72
# File 'lib/arborist/event.rb', line 67

def to_h
	return {
		type: self.type,
		data: self.payload
	}
end

#typeObject

Return the type of the event.



40
41
42
43
44
45
# File 'lib/arborist/event.rb', line 40

def type
	return self.class.name.
		sub( /.*::/, '' ).
		gsub( /([a-z])([A-Z])/, '\1.\2' ).
		downcase
end