class Sawmill::EntryProcessor::BuildRecords

An entry processor that builds log records from a stream of entries, and passes those log records to the given record processor.

Public Class Methods

new(processor_, opts_={}) click to toggle source

Create record builder emitting to the given record processor.

Recognized options include:

:emit_incomplete_records_on_finish

When the processor is finished, any records that are still not complete will be emitted to the record processor anyway, even in their incomplete state.

# File lib/sawmill/entry_processor/build_records.rb, line 57
def initialize(processor_, opts_={})
  @processor = processor_
  @records = {}
  @emit_incomplete_records_on_finish = opts_[:emit_incomplete_records_on_finish]
end

Public Instance Methods

attribute(entry_) click to toggle source
# File lib/sawmill/entry_processor/build_records.rb, line 118
def attribute(entry_)
  return unless @records
  record_ = @records[entry_.record_id]
  if record_
    record_.add_entry(entry_)
    true
  else
    @processor.extra_entry(entry_)
    false
  end
end
begin_record(entry_) click to toggle source
# File lib/sawmill/entry_processor/build_records.rb, line 78
def begin_record(entry_)
  return unless @records
  record_id_ = entry_.record_id
  if @records.include?(record_id_)
    @processor.extra_entry(entry_)
    false
  else
    @records[record_id_] = Record.new([entry_])
    true
  end
end
emit_incomplete_records() click to toggle source

Emit all currently incomplete records immediately in their incomplete state. This clears those incomplete records, so note that if they do get completed later, they will not be re-emitted.

# File lib/sawmill/entry_processor/build_records.rb, line 68
def emit_incomplete_records
  if @records
    @records.values.each do |record_|
      @processor.record(record_)
    end
    @records.clear
  end
end
end_record(entry_) click to toggle source
# File lib/sawmill/entry_processor/build_records.rb, line 91
def end_record(entry_)
  return unless @records
  record_ = @records.delete(entry_.record_id)
  if record_
    record_.add_entry(entry_)
    @processor.record(record_)
    true
  else
    @processor.extra_entry(entry_)
    false
  end
end
finish() click to toggle source
# File lib/sawmill/entry_processor/build_records.rb, line 138
def finish
  if @records
    emit_incomplete_records if @emit_incomplete_records_on_finish
    @records = nil
    @processor.finish
  else
    nil
  end
end
message(entry_) click to toggle source
# File lib/sawmill/entry_processor/build_records.rb, line 105
def message(entry_)
  return unless @records
  record_ = @records[entry_.record_id]
  if record_
    record_.add_entry(entry_)
    true
  else
    @processor.extra_entry(entry_)
    false
  end
end
unknown_data(entry_) click to toggle source
# File lib/sawmill/entry_processor/build_records.rb, line 131
def unknown_data(entry_)
  return unless @records
  @processor.extra_entry(entry_)
  false
end