From: xaea alvein Date: 2006-04-14T02:20:35+09:00 Subject: Re: do i have to use DRbUndumped? maybe some code could illustrate better: [assuming there is a TupleSpace-based name server and TupleSpace provider, like the one given in Mr. Eric Hodel's Ring example in his Segment7 site] --- #HelloWorld.rb class HelloWorld attr_writer :str # you can use DRbUndumped or the following. # either results in the same def initialize(str) @str = str end def _dump(*args, &block) Marshall.dump(@str, *args, &block) end def HelloWorld._load(*args, &block) HelloWorld.new(Marshall.load(*args, &block)) end def to_s @str end end --- #Master.rb require "rinda/ring" require "HelloWorld" DRb.start_service ringServer = Rinda::RingFinger.primary tupleSpace = ringServer.read([:name, :TupleSpace, nil, nil])[2] tupleSpace = Rinda::TupleSpaceProxy.new tupleSpace tupleSpace.write(["helloWorldObject", HelloWorld.new("Hello World!")]) DRb.thread.join --- #Client1.rb require "rinda/ring" #require "HelloWorld" DRb.start_service ringServer = Rinda::RingFinger.primary tupleSpace = ringServer.read([:name, :TupleSpace, nil, nil])[2] tupleSpace = Rinda::TupleSpaceProxy.new tupleSpace loop { aHelloWorldObject = tupleSpace.read(["helloWorldObject", nil]) puts aHelloWorldObject[1] } --- #Client2.rb require "rinda/ring" #require "HelloWorld" DRb.start_service ringServer = Rinda::RingFinger.primary tupleSpace = ringServer.read([:name, :TupleSpace, nil, nil])[2] tupleSpace = Rinda::TupleSpaceProxy.new tupleSpace aHelloWorldObject = tupleSpace.read(["helloWorldObject", nil]) aHelloWorldObject[1].str = "Goodbye!" --- anyone can help me with HelloWorld's dumping alternative, or do i have o use DRbUndumped / pass-by-reference? i am expecting that each client gets a fresh copy of HelloWorld object, not a reference to it xaea alvein wrote: > > i guess i better give an example: > > a master/server M has an object A that he want to put into tuplespace > (using write). > a worker/client C1 wants to have a copy of the object A for himself to > work with (by using read, instead of take). > a worker/client C2 also wants copy of object A (also using read). > > the problem is, i currently only know that M have to use > DRb::DRbUndumped (or use the alternative dumping as listed in the first > reply of this topic by -a) if A is to be put into tuplespace, which is a > pass-by-reference, meaning that the copy of A that each client C1 and C2 > has is actually the very same object currently residing in master M > (since the one put into the tuplespace is none other than DRbObject > reference to the object A) > > what i need is that M to put exactly a copy of object A into the > tuplespace instead just a reference to the object A, and C1 and C2 to > each have the copy of the copy of object A that was previously inserted > into the tuplespace, so that if C1 or C2 each modifies the copy (of copy > of A, if that matters), it only appears to himself. this is what i > believe is a pass-by-value > -- Posted via http://www.ruby-forum.com/.