class Datadog::ThreadSafeBuffer

Buffer that stores objects, has a maximum size, and can be safely used concurrently on any environment.

This implementation uses a {Mutex} around public methods, incurring overhead in order to ensure thread-safety.

This is implementation is recommended for non-CRuby environments. If using CRuby, {Datadog::CRubyBuffer} is a faster implementation with minimal compromise.

Public Class Methods

new(max_size) click to toggle source
Calls superclass method Datadog::Buffer::new
# File lib/ddtrace/buffer.rb, line 136
def initialize(max_size)
  super

  @mutex = Mutex.new
end

Public Instance Methods

close() click to toggle source
Calls superclass method Datadog::Buffer#close
# File lib/ddtrace/buffer.rb, line 167
def close
  synchronize { super }
end
concat(items) click to toggle source
Calls superclass method Datadog::Buffer#concat
# File lib/ddtrace/buffer.rb, line 148
def concat(items)
  synchronize { super }
end
empty?() click to toggle source

Return if the buffer is empty.

Calls superclass method Datadog::Buffer#empty?
# File lib/ddtrace/buffer.rb, line 158
def empty?
  synchronize { super }
end
length() click to toggle source

Return the current number of stored traces.

Calls superclass method Datadog::Buffer#length
# File lib/ddtrace/buffer.rb, line 153
def length
  synchronize { super }
end
pop() click to toggle source

Stored traces are returned and the local buffer is reset.

Calls superclass method Datadog::Buffer#pop
# File lib/ddtrace/buffer.rb, line 163
def pop
  synchronize { super }
end
push(item) click to toggle source

Add a new “item“ in the local queue. This method doesn't block the execution even if the buffer is full. In that case, a random item is discarded.

Calls superclass method Datadog::Buffer#push
# File lib/ddtrace/buffer.rb, line 144
def push(item)
  synchronize { super }
end
synchronize(&block) click to toggle source
# File lib/ddtrace/buffer.rb, line 171
def synchronize(&block)
  @mutex.synchronize(&block)
end