Class: CommandLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/internal/command_logger.rb

Constant Summary collapse

Logger_Extension =
'commandlog'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(iomanager, marshaler) ⇒ CommandLogger

Returns a new instance of CommandLogger.



37
38
39
# File 'lib/internal/command_logger.rb', line 37

def initialize( iomanager, marshaler )
  @iomanager, @marshaler = iomanager, marshaler
end

Instance Attribute Details

#current_file_nameObject (readonly)

Returns the value of attribute current_file_name.



35
36
37
# File 'lib/internal/command_logger.rb', line 35

def current_file_name
  @current_file_name
end

Instance Method Details

#create_command_storeObject



41
42
43
44
45
# File 'lib/internal/command_logger.rb', line 41

def create_command_store()
  stream = @iomanager.create_new_stream( Logger_Extension )
  @current_file_name = stream.full_name
  CommandSerializer.new( stream, @marshaler )
end

#log_filesObject



47
48
49
# File 'lib/internal/command_logger.rb', line 47

def log_files
  @iomanager.list( Logger_Extension )
end

#reset_commandsObject

removes all command_logs as a snapshot has been taken



52
53
54
55
56
57
58
# File 'lib/internal/command_logger.rb', line 52

def reset_commands()
  streams = @iomanager.obtain_ordered_read_streams( Logger_Extension )
  streams.each do |stream|
      stream.close
      File.delete stream.full_name
  end
end

#restore(system) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/internal/command_logger.rb', line 60

def restore( system )
  streams = @iomanager.obtain_ordered_read_streams( Logger_Extension )
  
  begin
    streams.each do |stream|
      CommandSerializer.restore_from_io( stream, system, @marshaler )
    end
  ensure
    streams.each do |stream|
      stream.close
    end
  end
end