Class: DLogReader::DistributedLogReader

Inherits:
Object
  • Object
show all
Defined in:
lib/distributed_logreader/distributed_log_reader.rb

Direct Known Subclasses

RotaterReader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, worker, num_threads = 100) ⇒ DistributedLogReader

Returns a new instance of DistributedLogReader.



11
12
13
14
15
# File 'lib/distributed_logreader/distributed_log_reader.rb', line 11

def initialize(filename, worker, num_threads = 100)
  self.filename = filename
  # self.distributer = SimpleForked.new(worker, 5, num_threads)
  self.distributer = SimpleThreadPool.new(worker, num_threads)
end

Instance Attribute Details

#distributerObject

Returns the value of attribute distributer.



9
10
11
# File 'lib/distributed_logreader/distributed_log_reader.rb', line 9

def distributer
  @distributer
end

#filenameObject

Returns the value of attribute filename.



9
10
11
# File 'lib/distributed_logreader/distributed_log_reader.rb', line 9

def filename
  @filename
end

#log_readerObject (readonly)

Returns the value of attribute log_reader.



10
11
12
# File 'lib/distributed_logreader/distributed_log_reader.rb', line 10

def log_reader
  @log_reader
end

Instance Method Details

#log_fileObject



34
35
36
# File 'lib/distributed_logreader/distributed_log_reader.rb', line 34

def log_file
  self.filename
end

#post_processObject

predefined hooks



43
44
# File 'lib/distributed_logreader/distributed_log_reader.rb', line 43

def post_process
end

#pre_processObject

predefined hooks



39
40
# File 'lib/distributed_logreader/distributed_log_reader.rb', line 39

def pre_process
end

#processObject

selector/archiver seem to be strongly connected. it’s possible it needs to be moved into LogReader



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/distributed_logreader/distributed_log_reader.rb', line 19

def process
  pre_process

  $dlog_logger.info("Started  #{log_file}:")
    lines_processed = 0
  @log_reader = LogReader.new(log_file) do |line|
    self.distributer.process(line)
    lines_processed += 1
  end
  @log_reader.run
  self.distributer.join
  $dlog_logger.info("Finished #{log_file}: Processed (#{lines_processed}) lines")
  post_process
end