The processing executor.
Return an instance of the configured type of Sender
.
# File lib/observability/sender.rb, line 44
def self::configured_type
return self.create( self.type )
end
Let subclasses be inherited
# File lib/observability/sender.rb, line 37
def self::inherited( subclass )
super
subclass.public_class_method( :new )
end
Queue up the specified events
for sending.
# File lib/observability/sender.rb, line 88
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
Start sending queued events.
# File lib/observability/sender.rb, line 65
def start
self.log.debug "Starting a %p" % [ self.class ]
@executor = Concurrent::SingleThreadExecutor.new( fallback_policy: :abort )
@executor.auto_terminate = true
end
Stop the sender's executor.
# File lib/observability/sender.rb, line 73
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
Set up some instance variables
# File lib/observability/sender.rb, line 50
def initialize # :notnew:
@executor = nil
end
Send the specified event
.
# File lib/observability/sender.rb, line 120
def send_event( event )
self.log.warn "%p does not implement required method %s" % [ self.class, __method__ ]
end
Serialize each the given events
and return the results.
# File lib/observability/sender.rb, line 114
def serialize_events( events )
return events.map( &:resolve )
end