Rinda (Ruby programming language)
Encyclopedia
Rinda is a software library for creating modular and distributed co-operating services in Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

 using the tuple space
Tuple space
A tuple space is an implementation of the associative memory paradigm for parallel/distributed computing. It provides a repository of tuples that can be accessed concurrently. As an illustrative example, consider that there are a group of processors that produce pieces of data and a group of...

 or Linda
Linda (coordination language)
In computer science, Linda is a model of coordination and communication among several parallel processes operating upon objects stored in and retrieved from shared, virtual, associative memory...

 distributed computing
Distributed computing
Distributed computing is a field of computer science that studies distributed systems. A distributed system consists of multiple autonomous computers that communicate through a computer network. The computers interact with each other in order to achieve a common goal...

 paradigm.

Based on a source code initially released to the Ruby community by Masatoshi SEKI in 2000 , Rinda was later absorbed into Ruby's core distributed Ruby (DRb)
Distributed Ruby
Distributed Ruby or DRb allows Ruby programs to communicate with each other on the same machine or over a network. DRb uses remote method invocation to pass commands and data between processes.- External links :* * *...

 module. Rinda has been distributed as part of the core Ruby library since Ruby 1.8.

Example usage

Rinda provides a framework by which multiple Ruby processes (which or may not be running on the same machine) can add, access and modify tuples (an ordered list of elements) stored in a shared data repository (the tuplespace).

For example, the following program creates a new Rinda tuplespace and intitalizes a DRb service that waits for requests coming over the network.


require 'rinda/tuplespace'

URI = "druby://localhost:67671"
DRb.start_service(URI, Rinda::TupleSpace.new)
DRb.thread.join


Using Rinda, other applications can poll the tuplespace for tuples that match specific criteria.

For example, the program below connects to a Rinda service and listens for any tuple composed an arithmetic operator followed two numbers (such as the sequence "+ 2 4") When such a tuple is discovered the program computes the result of the mathematical operation (for example, processing "+ 2 4" into "6") and stores it in tuplespace.


require 'rinda/rinda'

URI = "druby://localhost:67671"
DRb.start_service
ts = Rinda::TupleSpaceProxy.new(DRbObject.new(nil, URI))
loop do
ops, a, b = ts.take([ %r{^[-+/*]$}, Numeric, Numeric])
ts.write(["result", a.send(ops, b)])
end


Finally, Rinda applications can add or remove tuples from the tuplespace.

For instance, the following program posts prefix arithmetic tuples to the tuplespace and reads back the result (posted by the program above).


require 'rinda/rinda'

URI = "druby://localhost:67671"
DRb.start_service
ts = Rinda::TupleSpaceProxy.new(DRbObject.new(nil, URI))
tuples = "*", 2, 2 ], [ "+", 2, 5 ], [ "-", 9, 3
tuples.each do |t|
ts.write(t)
res = ts.take(["result", nil])
puts "#{res[1]} = #{t[1]} #{t[0]} #{t[2]}"
end

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK