Class: Observability::Sender
- Inherits:
-
Object
- Object
- Observability::Sender
- Extended by:
- Configurability, Loggability, Pluggability
- Defined in:
- lib/observability/sender.rb
Defined Under Namespace
Classes: Logger, Null, Testing, UDP
Instance Attribute Summary collapse
-
#executor ⇒ Object
readonly
The processing executor.
Class Method Summary collapse
-
.configured_type ⇒ Object
Return an instance of the configured type of Sender.
-
.inherited(subclass) ⇒ Object
Let subclasses be inherited.
Instance Method Summary collapse
-
#enqueue(*events) ⇒ Object
Queue up the specified
eventsfor sending. -
#initialize ⇒ Sender
constructor
Set up some instance variables.
-
#start ⇒ Object
Start sending queued events.
-
#stop ⇒ Object
Stop the sender’s executor.
Constructor Details
#initialize ⇒ Sender
Set up some instance variables
51 52 53 |
# File 'lib/observability/sender.rb', line 51 def initialize # :notnew: @executor = nil end |
Instance Attribute Details
#executor ⇒ Object (readonly)
The processing executor.
62 63 64 |
# File 'lib/observability/sender.rb', line 62 def executor @executor end |
Class Method Details
.configured_type ⇒ Object
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 |
#start ⇒ Object
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 |
#stop ⇒ Object
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 |