Class: LS4::FileUpdateLog::LogFile
- Inherits:
-
Object
- Object
- LS4::FileUpdateLog::LogFile
- Defined in:
- lib/ls4/service/ulog_file.rb
Instance Method Summary collapse
- #append(atime, data, &block) ⇒ Object
- #close ⇒ Object
- #get(time) ⇒ Object
-
#initialize(path, atime) ⇒ LogFile
constructor
A new instance of LogFile.
Constructor Details
#initialize(path, atime) ⇒ LogFile
Returns a new instance of LogFile.
184 185 186 187 188 189 190 191 192 |
# File 'lib/ls4/service/ulog_file.rb', line 184 def initialize(path, atime) @path = path @file = File.open(@path, File::RDWR|File::CREAT) if @file.stat.size == 0 init_file(atime) else read_file end end |
Instance Method Details
#append(atime, data, &block) ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/ls4/service/ulog_file.rb', line 198 def append(atime, data, &block) reltime = atime - @atime if reltime <= @last_reltime reltime = @last_reltime+1 end @last_reltime = reltime pos = get_offset r = Record.new(reltime, data) ref = RecordRef.new(reltime, pos) @file.pos = pos r.write(@file) noffset = @file.pos block.call @index << ref set_offset(noffset) reltime + @atime end |
#close ⇒ Object
194 195 196 |
# File 'lib/ls4/service/ulog_file.rb', line 194 def close @file.close end |
#get(time) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/ls4/service/ulog_file.rb', line 222 def get(time) reltime = time - @atime while true # FIXME binary search ref = @index.find {|ref| ref.reltime > reltime } unless ref break end r = ref.read_body(@file) return r.data, r.reltime + @atime end return nil, reltime + @atime end |