[Archipelago-submits] [79] trunk/archipelago: added to TODO.
nobody at rubyforge.org
nobody at rubyforge.org
Tue Nov 28 21:54:23 EST 2006
Revision: 79
Author: zond
Date: 2006-11-28 21:54:23 -0500 (Tue, 28 Nov 2006)
Log Message:
-----------
added to TODO. made Current::ThreadedCollection take callables as well as blocks. fixed broken include? in BerkeleyHashish. fixed so that store_if_changed doesnt restore removed objects.
Modified Paths:
--------------
trunk/archipelago/TODO
trunk/archipelago/lib/archipelago/current.rb
trunk/archipelago/lib/archipelago/hashish.rb
Modified: trunk/archipelago/TODO
===================================================================
--- trunk/archipelago/TODO 2006-11-29 01:19:04 UTC (rev 78)
+++ trunk/archipelago/TODO 2006-11-29 02:54:23 UTC (rev 79)
@@ -6,6 +6,9 @@
check whether the instance before the call differs from the instance after
the call. Preferably without incurring performance lossage.
+ * Make Dubloon proxy targets able to provide a dirty_state method that decides
+ whether they are to be considered dirty, clean or auto-select.
+
* Test the transaction recovery mechanism of Chest.
* Make Archipelago::Treasure::Dubloons work after an Archipelago::Treasure::Chest
Modified: trunk/archipelago/lib/archipelago/current.rb
===================================================================
--- trunk/archipelago/lib/archipelago/current.rb 2006-11-29 01:19:04 UTC (rev 78)
+++ trunk/archipelago/lib/archipelago/current.rb 2006-11-29 02:54:23 UTC (rev 79)
@@ -36,47 +36,69 @@
#
# Adds a few threaded methods to the normal ruby collections.
#
+ # The only method your class has to implement to use this module is <b>each(&block)</b>.
+ #
# NB: Will work slightly different than the unthreaded ones in certain circumstances.
#
module ThreadedCollection
#
- # Like each, except calls +block+ within a new thread.
+ # Like each, except calls +block+ or +callable+ within a new thread.
#
- def t_each(&block)
+ def t_each(callable = nil, &block)
+ raise "You have to provide either callable or block" if callable.nil? && block.nil?
+
threads = []
+
self.each do |args|
threads << Thread.new do
- yield(args)
+ if callable
+ callable.call(args)
+ else
+ yield(args)
+ end
end
end
+
threads.each do |thread|
thread.join
end
end
#
- # Like collect, except calls +block+ within a new thread.
+ # Like collect, except calls +block+ or +callable+ within a new thread.
#
- def t_collect(&block)
+ def t_collect(callable = nil, &block)
+ raise "You have to provide either callable or block" if callable.nil? && block.nil?
+
result = []
result.extend(Synchronized)
self.t_each do |args|
result.synchronize do
- result << yield(args)
+ if callable
+ result << callable.call(args)
+ else
+ result << yield(args)
+ end
end
end
return result
end
#
- # Like select, except calls +block+ within a new thread.
+ # Like select, except calls +block+ or +callable+ within a new thread.
#
- def t_select(&block)
+ def t_select(callable = nil, &block)
+ raise "You have to provide either callable or block" if callable.nil? && block.nil?
+
result = []
result.extend(Synchronized)
self.t_each do |args|
- matches = yield(args)
+ if callable
+ matches = callable.call(args)
+ else
+ matches = yield(args)
+ end
result.synchronize do
result << args
end if matches
@@ -85,13 +107,19 @@
end
#
- # Like reject, except calls +block+ within a new thread.
+ # Like reject, except calls +block+ or +callable+ within a new thread.
#
- def t_reject(&block)
+ def t_reject(callable = nil, &block)
+ raise "You have to provide either callable or block" if callable.nil? && block.nil?
+
result = []
result.extend(Synchronized)
self.t_each do |args|
- matches = yield(args)
+ if callable
+ matches = callable.call(args)
+ else
+ matches = yield(args)
+ end
result.synchronize do
result << args
end unless matches
Modified: trunk/archipelago/lib/archipelago/hashish.rb
===================================================================
--- trunk/archipelago/lib/archipelago/hashish.rb 2006-11-29 01:19:04 UTC (rev 78)
+++ trunk/archipelago/lib/archipelago/hashish.rb 2006-11-29 02:54:23 UTC (rev 79)
@@ -65,7 +65,7 @@
# Returns true if this BerkeleyHashish include +key+.
#
def include?(key)
- @content.include?(key) || @content_db.include?(Marshal.dump(key))
+ @content.include?(key) || !@content_db[Marshal.dump(key)].nil?
end
#
# Simply get the value for the +key+.
@@ -105,7 +105,8 @@
end
#
# Stores whatever is under +key+ if it is not the same as
- # whats in the persistent db.
+ # whats in the persistent db - if the +key+ actually has
+ # a representation in the db.
#
# Will call <b>value.save_hook(old_value)</b> and send
# it a block that does the actual saving if
@@ -116,11 +117,13 @@
@lock.synchronize_on(key) do
serialized_key = Marshal.dump(key)
+
value = @content[key]
serialized_value = Marshal.dump(value)
+ old_serialized_value = @content_db[serialized_key]
+
+ write_to_db(key, serialized_key, serialized_value, value) if old_serialized_value && old_serialized_value != serialized_value
- write_to_db(key, serialized_key, serialized_value, value) if @content_db[serialized_key] != serialized_value
-
end
end
#
More information about the Archipelago-submits
mailing list