Sha256: 5a5932db0e596d72d537efd4de5fcd6cb2954d4b0289b6c85efeadcd80efb3fa

Contents?: true

Size: 1.49 KB

Versions: 14

Compression:

Stored size: 1.49 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

# EventBuffer is intended to be an abstract base class. It should not be
# instantiated directly. Subclasses should define an `append_event` method
# looking something like this:
#
# def append_event(x)
#   <attempt to append>
#   if append_success?
#     return x
#   else
#     return nil
#   end
# end

module NewRelic
  module Agent
    class EventBuffer
      attr_reader :capacity

      def initialize(capacity)
        @capacity = capacity
        @items    = []
        @seen     = 0
      end

      def reset!
        @items = []
        @seen  = 0
      end

      def capacity=(new_capacity)
        @capacity = new_capacity
        old_items = @items
        @items    = []
        old_seen  = @seen
        old_items.each { |i| append(i) }
        @seen     = old_seen
      end

      def append(x)
        @seen += 1
        append_event(x)
      end

      def <<(x)
        append(x)
        self # return self for method chaining
      end

      def full?
        @items.size >= @capacity
      end

      def size
        @items.size
      end

      def note_dropped
        @seen += 1
      end

      def num_seen
        @seen
      end

      def num_dropped
        @seen - @items.size
      end

      def sample_rate
        @seen > 0 ? (size.to_f / @seen) : 0.0
      end

      def to_a
        @items.dup
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
newrelic_rpm-3.14.1.311 lib/new_relic/agent/event_buffer.rb
newrelic_rpm-3.14.0.305 lib/new_relic/agent/event_buffer.rb
newrelic_rpm-3.13.2.302 lib/new_relic/agent/event_buffer.rb
newrelic_rpm-3.13.1.300 lib/new_relic/agent/event_buffer.rb
newrelic_rpm-3.13.0.299 lib/new_relic/agent/event_buffer.rb
newrelic_rpm-3.12.1.298 lib/new_relic/agent/event_buffer.rb
newrelic_rpm-3.12.0.288 lib/new_relic/agent/event_buffer.rb
newrelic_rpm-3.11.2.286 lib/new_relic/agent/event_buffer.rb
newrelic_rpm-3.11.1.284 lib/new_relic/agent/event_buffer.rb
newrelic_rpm-3.11.0.283 lib/new_relic/agent/event_buffer.rb
newrelic_rpm-3.10.0.279 lib/new_relic/agent/event_buffer.rb
newrelic_rpm-3.9.9.275 lib/new_relic/agent/event_buffer.rb
newrelic_rpm-3.9.8.273 lib/new_relic/agent/event_buffer.rb
newrelic_rpm-3.9.7.266 lib/new_relic/agent/event_buffer.rb