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.
166 167 168 169 170 |
# File 'lib/smplkit/management/buffer.rb', line 166 def initialize @seen = {} @pending = [] @lock = Mutex.new end |
Instance Method Details
#add(source) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/smplkit/management/buffer.rb', line 172 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
185 186 187 188 189 190 191 |
# File 'lib/smplkit/management/buffer.rb', line 185 def drain @lock.synchronize do batch = @pending @pending = [] batch end end |
#pending_count ⇒ Object
193 194 195 |
# File 'lib/smplkit/management/buffer.rb', line 193 def pending_count @lock.synchronize { @pending.length } end |