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, UdpMulticast

Defined Under Namespace

Classes: Logger, Null, Testing, UDP, UdpMulticast

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSender

Set up some instance variables



53
54
55
# File 'lib/observability/sender.rb', line 53

def initialize # :notnew:
	@executor = nil
end

Instance Attribute Details

#executorObject (readonly)

The processing executor.



64
65
66
# File 'lib/observability/sender.rb', line 64

def executor
  @executor
end

Class Method Details

.configured_typeObject

Return an instance of the configured type of Sender.



47
48
49
# File 'lib/observability/sender.rb', line 47

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

.inherited(subclass) ⇒ Object

Let subclasses be inherited



40
41
42
43
# File 'lib/observability/sender.rb', line 40

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

Instance Method Details

#enqueue(*events) ⇒ Object

Queue up the specified events for sending.



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

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.



68
69
70
71
72
# File 'lib/observability/sender.rb', line 68

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.



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

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