Class: Smplkit::Management::LoggerRegistrationBuffer
- Inherits:
-
Object
- Object
- Smplkit::Management::LoggerRegistrationBuffer
- Defined in:
- lib/smplkit/management/buffer.rb
Overview
Thread-safe batch buffer for logger discovery.
Instance Method Summary collapse
- #add(source) ⇒ Object
- #drain ⇒ Object
-
#initialize ⇒ LoggerRegistrationBuffer
constructor
A new instance of LoggerRegistrationBuffer.
- #pending_count ⇒ Object
Constructor Details
#initialize ⇒ LoggerRegistrationBuffer
Returns a new instance of LoggerRegistrationBuffer.
79 80 81 82 83 |
# File 'lib/smplkit/management/buffer.rb', line 79 def initialize @seen = {} @pending = [] @lock = Mutex.new end |
Instance Method Details
#add(source) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/smplkit/management/buffer.rb', line 85 def add(source) @lock.synchronize do next if @seen.key?(source.name) @seen[source.name] = source.resolved_level item = { "id" => source.name, "resolved_level" => source.resolved_level&.to_s } item["level"] = source.level&.to_s if source.level item["service"] = source.service if source.service item["environment"] = source.environment if source.environment @pending << item end end |
#drain ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/smplkit/management/buffer.rb', line 98 def drain @lock.synchronize do batch = @pending @pending = [] batch end end |
#pending_count ⇒ Object
106 107 108 |
# File 'lib/smplkit/management/buffer.rb', line 106 def pending_count @lock.synchronize { @pending.length } end |