Class: Wukong::Store::ChunkedFlatFileStore

Inherits:
FlatFileStore show all
Defined in:
lib/wukong/store/chunked_flat_file_store.rb

Instance Attribute Summary collapse

Attributes inherited from FlatFileStore

#filemode, #filename

Instance Method Summary collapse

Methods inherited from FlatFileStore

#<<, #close, #each, #file, #flush, #mkdir!, #size, #skip!

Methods inherited from Base

#each_as, #log_line

Constructor Details

#initialize(options = {}) ⇒ ChunkedFlatFileStore

Note that filemode is inherited from flat_file



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/wukong/store/chunked_flat_file_store.rb', line 14

def initialize options={}
  # super wants a :filename in the options or it will fail. We need to get the initial filename
  # set up before we call super, so we need all of the parts of the pattern set up.
  self.chunktime        = options[:interval] || Settings[:chunk_file_interval]
  self.rootdir          = options[:rootdir]  || Settings[:chunk_file_rootdir]
  self.handle           = options[:handle]
  pattern               = options[:pattern]  || Settings[:chunk_file_pattern]
  self.filename_pattern = FilenamePattern.new(pattern, :handle => handle, :rootdir => self.rootdir)
  options[:filename]    = filename_pattern.make()
  options[:filemode]  ||= 'a'
  Log.warn "You don't really want a chunk time this small: #{self.chunktime}" unless self.chunktime > 600
  self.chunk_monitor    = Wukong::Monitor::PeriodicMonitor.new( :time => self.chunktime )

  super options
  self.mkdir!
end

Instance Attribute Details

#chunk_monitorObject

Returns the value of attribute chunk_monitor.



5
6
7
# File 'lib/wukong/store/chunked_flat_file_store.rb', line 5

def chunk_monitor
  @chunk_monitor
end

#chunktimeObject

Returns the value of attribute chunktime.



5
6
7
# File 'lib/wukong/store/chunked_flat_file_store.rb', line 5

def chunktime
  @chunktime
end

#filename_patternObject

Returns the value of attribute filename_pattern.



5
6
7
# File 'lib/wukong/store/chunked_flat_file_store.rb', line 5

def filename_pattern
  @filename_pattern
end

#handleObject

Returns the value of attribute handle.



5
6
7
# File 'lib/wukong/store/chunked_flat_file_store.rb', line 5

def handle
  @handle
end

#rootdirObject

Returns the value of attribute rootdir.



5
6
7
# File 'lib/wukong/store/chunked_flat_file_store.rb', line 5

def rootdir
  @rootdir
end

Instance Method Details

#new_chunk!Object



31
32
33
34
35
36
37
38
# File 'lib/wukong/store/chunked_flat_file_store.rb', line 31

def new_chunk!
  new_filename = filename_pattern.make()
  Log.info "Rotating chunked file #{filename} into #{new_filename}"
  self.flush
  self.close
  @filename = new_filename
  self.mkdir!
end

#save(*args) ⇒ Object



40
41
42
43
44
# File 'lib/wukong/store/chunked_flat_file_store.rb', line 40

def save *args
  result = super *args
  chunk_monitor.periodically{ new_chunk! }
  result
end