Class: Madeleine::SnapshotMadeleine

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

Class Method Summary collapse

Class Method Details

.new(directory_name, options = {}, &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.

  • options - Options hash:

    * <tt>:snapshot_marshaller</tt> - Marshaller to use for system snapshots (defaults to Marshal)
    * <tt>:execution_context</tt> - Optional context to be passed to commands' execute() method as a second parameter
    
  • new_system_block - Block to create a new system (if no stored system was found).



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/madeleine.rb', line 49

def self.new(directory_name, options = {}, &new_system_block)
  if options.kind_of? Hash
    options = {
      :snapshot_marshaller => Marshal,
      :execution_context => nil
    }.merge(options)
  else
    # Backwards compat.
    options = {:snapshot_marshaller => options}
  end

  log_factory = DefaultLogFactory.new
  logger = Logger.new(directory_name,
                      log_factory)
  snapshotter = Snapshotter.new(directory_name,
                                options[:snapshot_marshaller])
  recoverer = Recoverer.new(directory_name,
                            options[:snapshot_marshaller])
  system = recoverer.recover_snapshot(new_system_block)
  executer = Executer.new(system, options[:execution_context])
  recoverer.recover_logs(executer)
  DefaultSnapshotMadeleine.new(system, logger, snapshotter, executer)
end