From: Eric Hodel Date: 2006-04-20T04:21:29+09:00 Subject: Re: a flaw in tuplespace implementation? On Apr 18, 2006, at 12:31 AM, Guest wrote: > so what is the problem you say? i don't want to use pass-by-reference > and DRbUndumped, so that each reader process actually gets a copy > of the > object instead of a reference to it. This is exactly how DRb works by default. > to do that, i have to define my own marshalling method. No you don't. DRb takes care of this for you. You don't need to do anything other that make sure the class exists on all processes that will hold it. > try uncommenting the above class code, and something similar to > this will > occur: > > in `init_with_ary': undefined method `size' for > # (NoMethodError) If you ever get a DRb::DRbUnknown object you don't have the class available on one of your remote processes. Fix that problem first. The second problem is that you seem to be passing an object that is neither an Array nor a Hash into the Tuplespace. The code you gave didn't specify how you were adding the object to the Tuplespace, so a full example is necessary to figure out what's gone wrong. > any suggestion, or is tuplespace's read operation isn't as > important as > take operation? is this a flaw? There is no flaw in Tuplespace. What you want to do works out of the box. Adding extra marshalling doesn't do anything since ruby's built- in Marshal does that work for you. Here's an example that illustrates what you want. Each slave process gets a copy of the object, not a reference to it. You only need to have the class exist in every process that will hold the object: $ cat ts.rb require 'drb' require 'rinda/tuplespace' require 'x' ts = Rinda::TupleSpace.new DRb.start_service nil, ts puts DRb.uri DRb.thread.join $ cat master.rb require 'drb' require 'x' DRb.start_service ts = DRbObject.new nil, ARGV.shift x = X.new x.value = 0 ts.write [:x, x] $ cat slave.rb require 'drb' require 'x' DRb.start_service ts = DRbObject.new nil, ARGV.shift obj = ts.read [:x, nil] p obj.last p obj.last.value obj.last.value = 100 p obj.last.value $ cat x.rb class X attr_accessor :value end $ ruby ts.rb & druby://kaa.coop.robotcoop.com:52189 [2] 17630 $ ruby master.rb druby://kaa.coop.robotcoop.com:52189 $ ruby slave.rb druby://kaa.coop.robotcoop.com:52189 # 0 100 $ ruby slave.rb druby://kaa.coop.robotcoop.com:52189 # 0 100 -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com