Class: Celluloid::RingBuffer

### Home Classes Methods

### In Files

- lib/celluloid/logging/ring_buffer.rb

### Parent

Object

### Methods

- ::new
- #<<
- #clear
- #empty?
- #flush
- #full?
- #push
- #shift

### Class/Module Index

Quicksearch

- Celluloid
- Celluloid::Incident
- Celluloid::IncidentLogger
- Celluloid::IncidentLogger::Severity
- Celluloid::IncidentReporter
- Celluloid::IncidentReporter::Formatter
- Celluloid::Internals
- Celluloid::Internals::CPUCounter
- Celluloid::Internals::CallChain
- Celluloid::Internals::Handler
- Celluloid::Internals::Handlers
- Celluloid::Internals::Links
- Celluloid::Internals::Logger
- Celluloid::Internals::Logger::WithBacktrace
- Celluloid::Internals::Method
- Celluloid::Internals::Properties
- Celluloid::Internals::Receiver
- Celluloid::Internals::Receivers
- Celluloid::Internals::Registry
- Celluloid::Internals::Response
- Celluloid::Internals::Response::Block
- Celluloid::Internals::Response::Error
- Celluloid::Internals::Response::Success
- Celluloid::Internals::Signals
- Celluloid::Internals::Stack
- Celluloid::Internals::Stack::ActorState
- Celluloid::Internals::Stack::CellState
- Celluloid::Internals::Stack::DisplayBacktrace
- Celluloid::Internals::Stack::Dump
- Celluloid::Internals::Stack::Summary
- Celluloid::Internals::Stack::TaskState
- Celluloid::Internals::Stack::ThreadState
- Celluloid::Internals::TaskSet
- Celluloid::Internals::ThreadHandle
- Celluloid::Internals::UUID
- Celluloid::LogEvent
- Celluloid::Notifications
- Celluloid::Notifications::Fanout
- Celluloid::Notifications::Subscriber
- Celluloid::Probe
- Celluloid::RingBuffer

No matching classes.

# 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 47
    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
        values << remove_element until empty?
      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.