Parent

Class/Module Index [+]

Quicksearch

Celluloid::RingBuffer

Public Class Methods

new(size) click to toggle source
# File lib/celluloid/logging/ring_buffer.rb, line 3
def initialize(size)
  @size = size
  @start = 0
  @count = 0
  @buffer = Array.new(size)
  @mutex = Mutex.new
end

Public Instance Methods

<<(value) click to toggle source
Alias for: push
clear() click to toggle source
# File lib/celluloid/logging/ring_buffer.rb, line 49
def clear
  @buffer = Array.new(@size)
  @start = 0
  @count = 0
end
empty?() click to toggle source
# File lib/celluloid/logging/ring_buffer.rb, line 15
def empty?
  @count == 0
end
flush() click to toggle source
# File lib/celluloid/logging/ring_buffer.rb, line 39
def flush
  values = []
  @mutex.synchronize do
    while !empty?
      values << remove_element
    end
  end
  values
end
full?() click to toggle source
# File lib/celluloid/logging/ring_buffer.rb, line 11
def full?
  @count == @size
end
push(value) click to toggle source
# File lib/celluloid/logging/ring_buffer.rb, line 19
def push(value)
  @mutex.synchronize do
    stop = (@start + @count) % @size
    @buffer[stop] = value
    if full?
      @start = (@start + 1) % @size
    else
      @count += 1
    end
    value
  end
end
Also aliased as: <<
shift() click to toggle source
# File lib/celluloid/logging/ring_buffer.rb, line 33
def shift
  @mutex.synchronize do
    remove_element
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.