Class: Datadog::Statsd::Batch
- Inherits:
-
Object
- Object
- Datadog::Statsd::Batch
- Defined in:
- lib/datadog/statsd/batch.rb
Instance Method Summary collapse
- #add(message) ⇒ Object
- #flush ⇒ Object
-
#initialize(connection, max_buffer_bytes) ⇒ Batch
constructor
A new instance of Batch.
- #open ⇒ Object
- #open? ⇒ Boolean
Constructor Details
#initialize(connection, max_buffer_bytes) ⇒ Batch
Returns a new instance of Batch.
6 7 8 9 10 11 |
# File 'lib/datadog/statsd/batch.rb', line 6 def initialize(connection, max_buffer_bytes) @connection = connection @max_buffer_bytes = max_buffer_bytes @depth = 0 reset end |
Instance Method Details
#add(message) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/datadog/statsd/batch.rb', line 26 def add() = .bytesize unless @buffer_bytes == 0 if @buffer_bytes + 1 + >= @max_buffer_bytes flush else @buffer << "\n" @buffer_bytes += 1 end end @buffer << @buffer_bytes += end |
#flush ⇒ Object
42 43 44 45 46 |
# File 'lib/datadog/statsd/batch.rb', line 42 def flush return if @buffer_bytes == 0 @connection.write(@buffer) reset end |
#open ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/datadog/statsd/batch.rb', line 13 def open @depth += 1 yield ensure @depth -= 1 flush if !open? end |
#open? ⇒ Boolean
22 23 24 |
# File 'lib/datadog/statsd/batch.rb', line 22 def open? @depth > 0 end |