class Observability::Sender

Attributes

executor[R]

The processing executor.

Public Class Methods

configured_type() click to toggle source

Return an instance of the configured type of Sender.

# File lib/observability/sender.rb, line 46
def self::configured_type
        return self.create( self.type )
end
inherited( subclass ) click to toggle source

Let subclasses be inherited

Calls superclass method
# File lib/observability/sender.rb, line 39
def self::inherited( subclass )
        super
        subclass.public_class_method( :new )
end

Public Instance Methods

enqueue( *events ) click to toggle source

Queue up the specified events for sending.

# File lib/observability/sender.rb, line 90
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() click to toggle source

Start sending queued events.

# File lib/observability/sender.rb, line 67
def start
        self.log.debug "Starting a %p" % [ self.class ]
        @executor = Concurrent::SingleThreadExecutor.new( fallback_policy: :abort )
        @executor.auto_terminate = true
end
stop() click to toggle source

Stop the sender's executor.

# File lib/observability/sender.rb, line 75
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

Protected Instance Methods

initialize() click to toggle source

Set up some instance variables

# File lib/observability/sender.rb, line 52
def initialize # :notnew:
        @executor = nil
end
send_event( event ) click to toggle source

Send the specified event.

# File lib/observability/sender.rb, line 122
def send_event( event )
        self.log.warn "%p does not implement required method %s" % [ self.class, __method__ ]
end
serialize_events( events ) click to toggle source

Serialize each the given events and return the results.

# File lib/observability/sender.rb, line 116
def serialize_events( events )
        return events.map( &:resolve )
end