Class: Madeleine::SnapshotMadeleine

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

Class Method Summary collapse

Class Method Details

.new(directory_name, snapshot_marshaller = Marshal, &new_system_block) ⇒ Object

Builds a new Madeleine instance. If there is a snapshot available then the system will be created from that, otherwise new_system will be used. The state of the system will then be restored from the command logs.

You can provide your own snapshot marshaller, for instance using YAML, instead of Ruby’s built-in marshaller. The snapshot_marshaller must respond to load(stream) and dump(object, stream). You must use the same marshaller every time for a system.

See: DefaultSnapshotMadeleine

  • directory_name - Storage directory to use. Will be created if needed.

  • snapshot_marshaller - Marshaller to use for system snapshots. (Optional)

  • new_system_block - Block to create a new system (if no stored system was found).



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/madeleine.rb', line 47

def self.new(directory_name, snapshot_marshaller=Marshal, &new_system_block)
  log_factory = DefaultLogFactory.new
  logger = Logger.new(directory_name,
                      log_factory)
  snapshotter = Snapshotter.new(directory_name,
                                snapshot_marshaller)
  lock = DefaultLock.new
  recoverer = Recoverer.new(directory_name,
                            snapshot_marshaller)
  system = recoverer.recover_snapshot(new_system_block)
  executer = Executer.new(system)
  recoverer.recover_logs(executer)
  DefaultSnapshotMadeleine.new(system, logger, snapshotter, lock, executer)
end