Sender

class
Superclass
Object

Attributes

executor[R]

The processing executor.

Public Class Methods

anchor
configured_type()

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
anchor
inherited( subclass )

Let subclasses be inherited

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

Public Instance Methods

anchor
enqueue( *events )

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
anchor
start()

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
anchor
stop()

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

Protected Instance Methods

anchor
initialize()

Set up some instance variables

# File lib/observability/sender.rb, line 50
def initialize # :notnew:
        @executor = nil
end
anchor
send_event( event )

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
anchor
serialize_events( events )

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