madeleine 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/NEWS CHANGED
@@ -1,4 +1,11 @@
1
1
 
2
+ Madeleine 0.7.2 (May 29, 2006):
3
+
4
+ * An automatic class with no methods would cause an error
5
+ * System sanity check at first use
6
+ * Now creates full path to storage files, not just the last
7
+ directory (reported by Wayne Vucenic)
8
+
2
9
  Madeleine 0.7.1 (August 22, 2004):
3
10
 
4
11
  * ZMarshal changed to work around Zlib bug.
@@ -0,0 +1,39 @@
1
+ #
2
+ # Dynamic creation of command classes.
3
+ #
4
+ # Contributed by James Britt 2004.
5
+ #
6
+
7
+ class Command
8
+ Command::Target_map = {}
9
+
10
+ def execute( system )
11
+ cls = self.class.to_s
12
+ cmd = Command::Target_map[ cls ]
13
+ system.send( cmd, *@_vars )
14
+ end
15
+ end
16
+
17
+ # See http://www.rubytalk.com/cgi-bin/scat.rb/ruby/ruby-talk/56334
18
+ # But simplified/hacked so that it creates command/query classes
19
+ # This method defines a new class derived from Command. The initialize
20
+ # method is defined such that all arguments are pushed onto an
21
+ # instance variable array named @_vars. When 'execute' is called,
22
+ # this array will provide all the parameters to be sent to the
23
+ # method invoked on 'system'.
24
+ def createCommandClass( name, m_name )
25
+ Object.const_set( name, Class.new( Command ) ).instance_eval do
26
+ define_method( :initialize ) do |*args|
27
+ inst_vars = []
28
+ args.each do |k|
29
+ inst_vars.push( k )
30
+ end
31
+ instance_variable_set( "@_vars", inst_vars )
32
+ end
33
+ end
34
+ begin
35
+ Command::Target_map[ name ] = m_name
36
+ rescue Exception
37
+ STDERR.puts( "Error setting value in Command::Target_map: #{$!}" )
38
+ end
39
+ end
data/lib/madeleine.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # Madeleine - Ruby Object Prevalence
3
3
  #
4
4
  # Author:: Anders Bengtsson <ndrsbngtssn@yahoo.se>
5
- # Copyright:: Copyright (c) 2003-2004
5
+ # Copyright:: Copyright (c) 2003-2006
6
6
  #
7
7
  # Usage:
8
8
  #
@@ -19,9 +19,11 @@ module Madeleine
19
19
 
20
20
  require 'thread'
21
21
  require 'sync'
22
+ require 'fileutils'
22
23
  require 'madeleine/files'
24
+ require 'madeleine/sanity'
23
25
 
24
- MADELEINE_VERSION = "0.7.1"
26
+ MADELEINE_VERSION = "0.7.2"
25
27
 
26
28
  class SnapshotMadeleine
27
29
 
@@ -63,6 +65,8 @@ module Madeleine
63
65
  attr_reader :system
64
66
 
65
67
  def initialize(system, logger, snapshotter, lock, executer)
68
+ SanityCheck.instance.run_once
69
+
66
70
  @system = system
67
71
  @logger = logger
68
72
  @snapshotter = snapshotter
@@ -84,7 +88,7 @@ module Madeleine
84
88
  def execute_command(command)
85
89
  verify_command_sane(command)
86
90
  @lock.synchronize {
87
- raise "closed" if @closed
91
+ raise MadeleineClosedException if @closed
88
92
  @logger.store(command)
89
93
  @executer.execute(command)
90
94
  }
@@ -149,6 +153,9 @@ module Madeleine
149
153
  class InvalidCommandException < Exception
150
154
  end
151
155
 
156
+ class MadeleineClosedException < RuntimeError
157
+ end
158
+
152
159
  #
153
160
  # Internal classes below
154
161
  #
@@ -309,7 +316,7 @@ module Madeleine
309
316
 
310
317
  def ensure_directory_exists
311
318
  if ! File.exist?(@directory_name)
312
- Dir.mkdir(@directory_name)
319
+ FileUtils.mkpath(@directory_name)
313
320
  end
314
321
  end
315
322
 
@@ -7,8 +7,8 @@ module Madeleine
7
7
  # Automatic commands for Madeleine
8
8
  #
9
9
  # Author:: Stephen Sykes <sds@stephensykes.com>
10
- # Copyright:: Copyright (C) 2003-2004
11
- # Version:: 0.41
10
+ # Copyright:: Copyright (C) 2003-2006
11
+ # Version:: 0.42
12
12
  #
13
13
  # This module provides a way of automatically generating command objects for madeleine to
14
14
  # store. It works by making a proxy object for all objects of any classes in which it is included.
@@ -52,8 +52,8 @@ module Madeleine
52
52
  # mad = AutomaticSnapshotMadeleine.new("storage_directory") { A.new(param1, ...) }
53
53
  #
54
54
  # mad.system.some_method(paramA, ...) # logged as a command by madeleine
55
- # print mad.foo # not logged
56
- # print mad.bigfoo # not logged
55
+ # print mad.system.foo # not logged
56
+ # print mad.system.bigfoo # not logged
57
57
  # mad.take_snapshot
58
58
  #
59
59
 
@@ -76,6 +76,7 @@ module Madeleine
76
76
  alias_method :_old_new, :new
77
77
 
78
78
  def new(*args, &block)
79
+ @read_only_methods ||= []
79
80
  Prox.new(_old_new(*args, &block))
80
81
  end
81
82
  #
@@ -153,6 +154,7 @@ module Madeleine
153
154
  class Automatic_marshaller #:nodoc:
154
155
  def Automatic_marshaller.load(io)
155
156
  restored_obj = Deserialize.load(io, Thread.current[:system].marshaller)
157
+ p restored_obj if restored_obj.class != Prox
156
158
  ObjectSpace.each_object(Prox) {|o| Thread.current[:system].restore(o) if (o.sysid == restored_obj.sysid)}
157
159
  restored_obj
158
160
  end
@@ -268,14 +270,19 @@ module Madeleine
268
270
  @@systems[@sysid] = self
269
271
  Thread.critical = false
270
272
  @marshaller = marshaller # until attrb
273
+
271
274
  begin
272
275
  @persister = persister.new(directory_name, Automatic_marshaller, &new_system_block)
273
276
  @list.delete_if {|k,v| # set all the prox objects that now exist to have the right sysid
274
277
  begin
275
- ObjectSpace._id2ref(v).sysid = @sysid
278
+ obj = ObjectSpace._id2ref(v)
279
+ raise unless obj.respond_to?(:sysid=)
280
+ obj.sysid = @sysid
276
281
  false
277
282
  rescue RangeError
278
283
  true # Id was to a GC'd object, delete it
284
+ rescue RuntimeError
285
+ true # GC'd object, and id was reused for something else
279
286
  end
280
287
  }
281
288
  ensure
@@ -334,7 +341,10 @@ module Madeleine
334
341
  #
335
342
  def close
336
343
  begin
337
- @list.each_key {|k| myid2ref(k).sysid = nil}
344
+ @list.each_key {|k|
345
+ ref = myid2ref(k)
346
+ ref.sysid = nil if ref.class == Prox
347
+ }
338
348
  rescue RangeError
339
349
  # do nothing
340
350
  end
@@ -389,6 +399,7 @@ module Madeleine
389
399
  #
390
400
  def Deserialize.load(io, marshaller=Marshal)
391
401
  begin
402
+ raise "Must detect with YAML" if marshaller == YAML
392
403
  marshaller.load(io)
393
404
  rescue Exception => e
394
405
  io.rewind
@@ -0,0 +1,50 @@
1
+ #
2
+ # Author:: Anders Bengtsson <ndrsbngtssn@yahoo.se>
3
+ # Copyright:: Copyright (c) 2004
4
+ #
5
+
6
+ require 'tempfile'
7
+ require 'singleton'
8
+
9
+ module Madeleine
10
+ class SanityCheck
11
+ include Singleton
12
+
13
+ def initialize
14
+ @testdata = "\x85\x00\x0a\0x0d\x0a".freeze
15
+ @was_run = false
16
+ end
17
+
18
+ def run_once
19
+ unless @was_run
20
+ run
21
+ end
22
+ end
23
+
24
+ def run
25
+ marshal_check
26
+ file_check
27
+ @was_run = true
28
+ end
29
+
30
+ def marshal_check
31
+ result = Marshal.load(Marshal.dump(@testdata))
32
+ if result != @testdata
33
+ raise "Sanity check failed for Marshal"
34
+ end
35
+ end
36
+
37
+ def file_check
38
+ Tempfile.open("madeleine_sanity") do |file|
39
+ file.write(@testdata)
40
+ file.flush
41
+ open(file.path, 'rb') do |read_file|
42
+ result = read_file.read
43
+ if result != @testdata
44
+ raise "Sanity check failed for file IO"
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.4
2
+ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: madeleine
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.7.1
7
- date: 2005-01-06
6
+ version: 0.7.2
7
+ date: 2006-05-29 00:00:00 +02:00
8
8
  summary: Madeleine is a Ruby implementation of Object Prevalence
9
9
  require_paths:
10
- - lib
10
+ - lib
11
11
  email: ndrsbngtssn@yahoo.se
12
12
  homepage: http://madeleine.sourceforge.net
13
13
  rubyforge_project:
@@ -18,36 +18,46 @@ bindir: bin
18
18
  has_rdoc: false
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
20
20
  requirements:
21
- -
22
- - ">="
23
- - !ruby/object:Gem::Version
24
- version: 1.8.1
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.1
25
24
  version:
26
25
  platform: ruby
26
+ signing_key:
27
+ cert_chain:
27
28
  authors:
28
- - Anders Bengtsson
29
+ - Anders Bengtsson
29
30
  files:
30
- - lib/madeleine.rb
31
- - lib/madeleine/automatic.rb
32
- - lib/madeleine/clock.rb
33
- - lib/madeleine/files.rb
34
- - lib/madeleine/zmarshal.rb
35
- - samples/clock_click.rb
36
- - samples/dictionary_client.rb
37
- - samples/dictionary_server.rb
38
- - samples/painter.rb
39
- - contrib/batched.rb
40
- - contrib/benchmark.rb
41
- - contrib/test_batched.rb
42
- - contrib/test_scalability.rb
43
- - contrib/threaded_benchmark.rb
44
- - README
45
- - NEWS
46
- - COPYING
31
+ - lib/madeleine.rb
32
+ - lib/madeleine/automatic.rb
33
+ - lib/madeleine/clock.rb
34
+ - lib/madeleine/files.rb
35
+ - lib/madeleine/sanity.rb
36
+ - lib/madeleine/zmarshal.rb
37
+ - samples/clock_click.rb
38
+ - samples/dictionary_client.rb
39
+ - samples/dictionary_server.rb
40
+ - samples/painter.rb
41
+ - contrib/batched.rb
42
+ - contrib/benchmark.rb
43
+ - contrib/create_command.rb
44
+ - contrib/test_batched.rb
45
+ - contrib/test_scalability.rb
46
+ - contrib/threaded_benchmark.rb
47
+ - README
48
+ - NEWS
49
+ - COPYING
47
50
  test_files: []
51
+
48
52
  rdoc_options: []
53
+
49
54
  extra_rdoc_files: []
55
+
50
56
  executables: []
57
+
51
58
  extensions: []
59
+
52
60
  requirements: []
53
- dependencies: []
61
+
62
+ dependencies: []
63
+