Class: Wukong::Store::ChunkedFlatFileStore
- Inherits:
-
FlatFileStore
- Object
- Base
- FlatFileStore
- Wukong::Store::ChunkedFlatFileStore
- Defined in:
- lib/wukong/store/chunked_flat_file_store.rb
Instance Attribute Summary collapse
-
#chunk_monitor ⇒ Object
Returns the value of attribute chunk_monitor.
-
#chunktime ⇒ Object
Returns the value of attribute chunktime.
-
#filename_pattern ⇒ Object
Returns the value of attribute filename_pattern.
-
#handle ⇒ Object
Returns the value of attribute handle.
-
#rootdir ⇒ Object
Returns the value of attribute rootdir.
Attributes inherited from FlatFileStore
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ChunkedFlatFileStore
constructor
Note that filemode is inherited from flat_file.
- #new_chunk! ⇒ Object
- #save(*args) ⇒ Object
Methods inherited from FlatFileStore
#<<, #close, #each, #file, #flush, #mkdir!, #size, #skip!
Methods inherited from Base
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 ={} # 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 = [:interval] || Settings[:chunk_file_interval] self.rootdir = [:rootdir] || Settings[:chunk_file_rootdir] self.handle = [:handle] pattern = [:pattern] || Settings[:chunk_file_pattern] self.filename_pattern = FilenamePattern.new(pattern, :handle => handle, :rootdir => self.rootdir) [:filename] = filename_pattern.make() [: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 self.mkdir! end |
Instance Attribute Details
#chunk_monitor ⇒ Object
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 |
#chunktime ⇒ Object
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_pattern ⇒ Object
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 |
#handle ⇒ Object
Returns the value of attribute handle.
5 6 7 |
# File 'lib/wukong/store/chunked_flat_file_store.rb', line 5 def handle @handle end |
#rootdir ⇒ Object
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 |