Module: Madeleine::Automatic

Defined in:
lib/madeleine/automatic.rb

Overview

Automatic commands for Madeleine

Author

Stephen Sykes <[email protected]>

Copyright

Copyright © 2003-2006

Version

0.42

This module provides a way of automatically generating command objects for madeleine to store. It works by making a proxy object for all objects of any classes in which it is included. Method calls to these objects are intercepted, and stored as a command before being passed on to the real receiver. The command objects remember which object the command was destined for by using a pair of internal ids that are contained in each of the proxy objects.

There is also a mechanism for specifying which methods not to intercept calls to by using automatic_read_only, and its opposite automatic_read_write.

Should you require it, the snapshots can be stored as yaml, and can be compressed. Just pass the marshaller you want to use as the second argument to AutomaticSnapshotMadeleine.new.

If the passed marshaller did not successfully deserialize the latest snapshot, the system will try to automatically detect and read either Marshal, YAML, SOAP, or their corresponding compressed versions.

This module is designed to work correctly in the case there are multiple madeleine systems in use by a single program, and is also safe to use with threads.

Usage:

require 'madeleine'
require 'madeleine/automatic'

class A
  include Madeleine::Automatic::Interceptor
  attr_reader :foo
  automatic_read_only :foo
  def initialize(param1, ...)
    ...
  end
  def some_method(paramA, ...)
    ...
  end
  automatic_read_only
  def bigfoo
    foo.upcase
  end
end

mad = AutomaticSnapshotMadeleine.new("storage_directory") { A.new(param1, ...) }

mad.system.some_method(paramA, ...) # logged as a command by madeleine
print mad.system.foo                # not logged
print mad.system.bigfoo             # not logged
mad.take_snapshot

Defined Under Namespace

Modules: Deserialize, Interceptor Classes: AutomaticSnapshotMadeleine, Automatic_marshaller, Command, Prox