Class: Datadog::Statsd::Batch
- Inherits:
-
Object
- Object
- Datadog::Statsd::Batch
- Defined in:
- lib/datadog/statsd.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.
103 104 105 106 107 108 |
# File 'lib/datadog/statsd.rb', line 103 def initialize(connection, max_buffer_bytes) @connection = connection @max_buffer_bytes = max_buffer_bytes @depth = 0 reset end |
Instance Method Details
#add(message) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/datadog/statsd.rb', line 122 def add() = .bytesize unless @buffer_bytes == 0 if @buffer_bytes + 1 + >= @max_buffer_bytes flush else @buffer << NEW_LINE @buffer_bytes += 1 end end @buffer << @buffer_bytes += end |
#flush ⇒ Object
138 139 140 141 142 |
# File 'lib/datadog/statsd.rb', line 138 def flush return if @buffer_bytes == 0 @connection.write @buffer reset end |
#open ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/datadog/statsd.rb', line 110 def open @depth += 1 yield ensure @depth -= 1 flush if !open? end |
#open? ⇒ Boolean
118 119 120 |
# File 'lib/datadog/statsd.rb', line 118 def open? @depth > 0 end |