Class: Datadog::ThreadSafeBuffer
Overview
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, CRubyBuffer is a faster implementation with minimal compromise.
Direct Known Subclasses
Instance Method Summary collapse
- #close ⇒ Object
- #concat(items) ⇒ Object
-
#empty? ⇒ Boolean
Return if the buffer is empty.
-
#initialize(max_size) ⇒ ThreadSafeBuffer
constructor
A new instance of ThreadSafeBuffer.
-
#length ⇒ Object
Return the current number of stored traces.
-
#pop ⇒ Object
Stored traces are returned and the local buffer is reset.
-
#push(item) ⇒ Object
Add a new “item“ in the local queue.
- #synchronize(&block) ⇒ Object
Methods inherited from Buffer
Constructor Details
#initialize(max_size) ⇒ ThreadSafeBuffer
Returns a new instance of ThreadSafeBuffer.
136 137 138 139 140 |
# File 'lib/ddtrace/buffer.rb', line 136 def initialize(max_size) super @mutex = Mutex.new end |
Instance Method Details
#close ⇒ Object
167 168 169 |
# File 'lib/ddtrace/buffer.rb', line 167 def close synchronize { super } end |
#concat(items) ⇒ Object
148 149 150 |
# File 'lib/ddtrace/buffer.rb', line 148 def concat(items) synchronize { super } end |
#empty? ⇒ Boolean
Return if the buffer is empty.
158 159 160 |
# File 'lib/ddtrace/buffer.rb', line 158 def empty? synchronize { super } end |
#length ⇒ Object
Return the current number of stored traces.
153 154 155 |
# File 'lib/ddtrace/buffer.rb', line 153 def length synchronize { super } end |
#pop ⇒ Object
Stored traces are returned and the local buffer is reset.
163 164 165 |
# File 'lib/ddtrace/buffer.rb', line 163 def pop synchronize { super } end |
#push(item) ⇒ Object
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.
144 145 146 |
# File 'lib/ddtrace/buffer.rb', line 144 def push(item) synchronize { super } end |
#synchronize(&block) ⇒ Object
171 172 173 |
# File 'lib/ddtrace/buffer.rb', line 171 def synchronize(&block) @mutex.synchronize(&block) end |