Class: Sawmill::RecordProcessor::SimpleQueue

Inherits:
Base
  • Object
show all
Defined in:
lib/sawmill/record_processor/simple_queue.rb

Overview

This processor simply queues up log records for later use.

Instance Method Summary collapse

Methods inherited from Base

add_dsl_method, inherited

Constructor Details

#initialize(opts_ = {}) ⇒ SimpleQueue

Create a queue. This processor actually maintains two separate queues, one for records and another for extra entries.

Recognized options include:

:limit

Size limit for the queue. If not specified, the queue can grow arbitrarily large.

:drop_oldest

If set to true, then when an item is added to a full queue, the oldest item is dropped. If set to false or not specified, then the new item is not added.



61
62
63
64
65
# File 'lib/sawmill/record_processor/simple_queue.rb', line 61

def initialize(opts_={})
  @queue = Util::Queue.new(opts_)
  @extra_entries_queue = Util::Queue.new(opts_)
  @closed = false
end

Instance Method Details

#dequeueObject

Return the oldest record in the record queue, or nil if the record queue is empty.



71
72
73
# File 'lib/sawmill/record_processor/simple_queue.rb', line 71

def dequeue
  @queue.dequeue
end

#dequeue_allObject

Return an array of the contents of the record queue, in order.



78
79
80
# File 'lib/sawmill/record_processor/simple_queue.rb', line 78

def dequeue_all
  @queue.dequeue_all
end

#dequeue_all_extra_entriesObject

Return an array of the contents of the extra entry queue, in order.



100
101
102
# File 'lib/sawmill/record_processor/simple_queue.rb', line 100

def dequeue_all_extra_entries
  @extra_entries_queue.dequeue_all
end

#dequeue_extra_entryObject

Return the oldest entry in the extra entry queue, or nil if the extra entry queue is empty.



93
94
95
# File 'lib/sawmill/record_processor/simple_queue.rb', line 93

def dequeue_extra_entry
  @extra_entries_queue.dequeue
end

#extra_entries_sizeObject

Return the number of entries in the extra entry queue.



107
108
109
# File 'lib/sawmill/record_processor/simple_queue.rb', line 107

def extra_entries_size
  @extra_entries_queue.size
end

#extra_entry(entry_) ⇒ Object



116
117
118
# File 'lib/sawmill/record_processor/simple_queue.rb', line 116

def extra_entry(entry_)
  @extra_entries_queue.enqueue(entry_) unless @closed
end

#finishObject



120
121
122
123
# File 'lib/sawmill/record_processor/simple_queue.rb', line 120

def finish
  @closed = true
  nil
end

#record(record_) ⇒ Object



112
113
114
# File 'lib/sawmill/record_processor/simple_queue.rb', line 112

def record(record_)
  @queue.enqueue(record_) unless @closed
end

#sizeObject

Return the number of records in the record queue.



85
86
87
# File 'lib/sawmill/record_processor/simple_queue.rb', line 85

def size
  @queue.size
end