Class: Smplkit::Management::LoggerRegistrationBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/smplkit/management/buffer.rb

Overview

Thread-safe batch buffer for logger discovery.

Instance Method Summary collapse

Constructor Details

#initializeLoggerRegistrationBuffer

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

#drainObject



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_countObject



193
194
195
# File 'lib/smplkit/management/buffer.rb', line 193

def pending_count
  @lock.synchronize { @pending.length }
end