请输入您要查询的百科知识:

 

词条 Rinda (Ruby programming language)
释义

  1. Example usage

  2. External links

  3. References

{{refimprove|date=April 2016}}

Rinda is a software library for creating modular and distributed co-operating services in Ruby using the tuple space or Linda distributed computing paradigm.

Based on a source code initially released to the Ruby community by Masatoshi SEKI in 2000,[1] Rinda was later absorbed into Ruby's core distributed Ruby (DRb) 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 initializes a DRb service that waits for requests coming over the network.

require 'rinda/tuplespace'

URI = "druby://localhost:61676"

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:61676"

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:61676"

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

  • Ruby Standard Library Documentation for Rinda

References

1. ^{{cite web|title=Tuplespace|url=http://raa.ruby-lang.org/project/tuplespace/|work=Ruby Application Archive (RAA)|accessdate=26 October 2011}}
{{programming-software-stub}}

2 : Ruby (programming language)|Inter-process communication

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/21 8:51:06