Class: HPrevalence::SimpleEngine

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_dir, system, iomanager = FileIOManager.new(target_dir), marshaller = DefaultMarshaller.new(), model_serializer = DefaultModelSerializer.new(iomanager, marshaller), store_manager = StorageManager.new(target_dir, iomanager, marshaller, model_serializer)) ⇒ SimpleEngine

Returns a new instance of SimpleEngine.



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hprevalence.rb', line 41

def initialize( 
      target_dir, 
      system, 
      iomanager = FileIOManager.new(target_dir),
      marshaller = DefaultMarshaller.new(), 
      model_serializer = DefaultModelSerializer.new(iomanager, marshaller), 
      store_manager = StorageManager.new(target_dir, iomanager, marshaller, model_serializer) )
      
  @lock = Mutex.new
  @target_dir, @system, @store_manager = target_dir, system, store_manager
  @system = @store_manager.restore( system() )
end

Instance Attribute Details

#systemObject (readonly)

Returns the value of attribute system.



39
40
41
# File 'lib/hprevalence.rb', line 39

def system
  @system
end

#target_dirObject (readonly)

Returns the value of attribute target_dir.



39
40
41
# File 'lib/hprevalence.rb', line 39

def target_dir
  @target_dir
end

Instance Method Details

#closeObject



64
65
66
# File 'lib/hprevalence.rb', line 64

def close
  @store_manager.close
end

#execute_command(command) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/hprevalence.rb', line 54

def execute_command( command )
  raise 'Invalid command' unless command.respond_to?( :execute )
  @lock.synchronize {
    set_time_if_requested(command)
    result = command.execute( @system )
    @store_manager.store( command )
    result
  }
end

#take_snapshotObject



68
69
70
71
72
# File 'lib/hprevalence.rb', line 68

def take_snapshot
  @lock.synchronize {
    @store_manager.take_snapshot @system
  }
end