Class: Observability::Sender

Inherits:
Object
  • Object
show all
Extended by:
Configurability, Loggability, Pluggability
Defined in:
lib/observability/sender.rb

Direct Known Subclasses

Logger, Null, Testing, UDP

Defined Under Namespace

Classes: Logger, Null, Testing, UDP

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSender

Set up some instance variables



51
52
53
# File 'lib/observability/sender.rb', line 51

def initialize # :notnew:
	@executor = nil
end

Instance Attribute Details

#executorObject (readonly)

The processing executor.



62
63
64
# File 'lib/observability/sender.rb', line 62

def executor
  @executor
end

Class Method Details

.configured_typeObject

Return an instance of the configured type of Sender.



45
46
47
# File 'lib/observability/sender.rb', line 45

def self::configured_type
	return self.create( self.type )
end

.inherited(subclass) ⇒ Object

Let subclasses be inherited



38
39
40
41
# File 'lib/observability/sender.rb', line 38

def self::inherited( subclass )
	super
	subclass.public_class_method( :new )
end

Instance Method Details

#enqueue(*events) ⇒ Object

Queue up the specified events for sending.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/observability/sender.rb', line 89

def enqueue( *events )
	posted_event = Concurrent::Event.new

	unless self.executor
		self.log.debug "No executor; dropping %d events" % [ events.length ]
		posted_event.set
		return posted_event
	end

	self.executor.post( *events ) do |*ev|
		serialized = self.serialize_events( ev.flatten )
		serialized.each do |ev|
			self.send_event( ev )
		end
		posted_event.set
	end

	return posted_event
end

#startObject

Start sending queued events.



66
67
68
69
70
# File 'lib/observability/sender.rb', line 66

def start
	self.log.debug "Starting a %p" % [ self.class ]
	@executor = Concurrent::SingleThreadExecutor.new( fallback_policy: :abort )
	@executor.auto_terminate = true
end

#stopObject

Stop the sender’s executor.



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/observability/sender.rb', line 74

def stop
	self.log.debug "Stopping the %p" % [ self.class ]
	return if !self.executor || self.executor.shuttingdown? || self.executor.shutdown?

	self.log.debug "  shutting down the executor"
	self.executor.shutdown
	unless self.executor.wait_for_termination( 3 )
		self.log.debug "  killing the executor"
		self.executor.halt
		self.executor.wait_for_termination( 3 )
	end
end