Project

General

Profile

Actions

Feature #8128

closed

New primitives for Rinda::TupleSpace

Added by vjoel (Joel VanderWerf) over 11 years ago. Updated over 11 years ago.

Status:
Rejected
Target version:
-
[ruby-core:53557]

Description

=begin

= New primitives for Rinda::TupleSpace

This issue proposes adding two new primitives to TupleSpace for atomic bulk operations:

== 1. TupleSpace#replace_all

=== What it does

Calling

replace_all(tuple, new_tuple, sec=nil)

atomically removes all tuples matching ((|tuple|)) and writes ((|new_tuple|)). It does not block waiting for tuples. The return value is a pair:

[ matching_tuples, entry ]

where ((|matching_tuples|)) is like the return value of (({read_all(tuple)})) and
((|entry|)) is like the return value of (({write(new_tuple)})).

=== Why it is needed

It is not possible to do this atomically with existing primitives. As noted in ((The dRuby Book)), p. 176, "It isn't easy to represent a dictionary using TupleSpace." Essentially, the #[]= and #[] operations must take/write a global lock tuple.

Using #replace_all, it is easy to implement a key-value store without lock tuples. See key-value-store.rb for an example.

=== Modularity

The new code is entirely contained in two modules in a single separate file. These modules are included/extended to TupleSpace and TupleSpaceProxy as desired to add the replace_all functionality.

=== Examples

See key-value-store.rb and example-replace-all.rb.

== 2. TupleSpace#take_all

=== What it does

Calling

take_all(tuple)

atomically removes all matching tuples. It does not block waiting for tuples. The return value is the array of tuples, like the return value of (({read_all(tuple)})).

=== Why it is needed

It is not possible to do this atomically with existing primitives, though in this case atomicity may not be important. More importantly, it is not possible to do this efficiently with existing primitives. The best approximation would be an unbounded sequence of #take calls.

=== Modularity

The new code is entirely contained in two modules in a single separate file. These modules are included/extended to TupleSpace and TupleSpaceProxy as desired to add the take_all functionality.

=== Examples

See example-take-all.rb.

=end


Files

replace-all.rb (1.59 KB) replace-all.rb vjoel (Joel VanderWerf), 03/20/2013 08:00 AM
take-all.rb (961 Bytes) take-all.rb vjoel (Joel VanderWerf), 03/20/2013 08:00 AM
example-replace-all.rb (910 Bytes) example-replace-all.rb vjoel (Joel VanderWerf), 03/20/2013 08:00 AM
example-take-all.rb (813 Bytes) example-take-all.rb vjoel (Joel VanderWerf), 03/20/2013 08:00 AM
key-value-store.rb (1.13 KB) key-value-store.rb vjoel (Joel VanderWerf), 03/20/2013 08:00 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0