# Do i have to use DRbUndumped?

**URL:** <https://rubytalk.org/t/do-i-have-to-use-drbundumped/26551>\
**Category:** ruby-talk\
**Created:** [10 April 2006 15:23 UTC](https://rubytalk.org/t/do-i-have-to-use-drbundumped/26551 "2006-04-10T15:23:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guest10](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@Guest10](https://rubytalk.org/u/Guest10)\
**Post date:** [10 April 2006 15:23 UTC](https://rubytalk.org/t/do-i-have-to-use-drbundumped/26551/1 "2006-04-10T15:23:03Z")

</div>

i am currently using Ruby 1.8.4 and DRb 2.0.4, and i am stuck with some marshalling problem  
related to tuplespace. this is my hello world code using tuplespace

> **···**
>
> ---  
> #HelloWorld.rb  
> require "rinda/ring"
> 
> class HelloWorld  
> # include DRbUndumped  
> &nbsp;&nbsp;def initialize(str)  
> &nbsp;&nbsp;&nbsp;&nbsp;@str = str  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;def \_dump(dumpDepth)  
> &nbsp;&nbsp;&nbsp;&nbsp;@str  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;def HelloWorld.\_load(srcString)  
> &nbsp;&nbsp;&nbsp;&nbsp;HelloWorld.new(srcString)  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;def to\_s  
> &nbsp;&nbsp;&nbsp;&nbsp;@str  
> &nbsp;&nbsp;end  
> end
> 
> 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!")])
> 
> aHelloWorldObject = tupleSpace.take(["helloWorldObject", nil])  
> puts aHelloWorldObject[1]
> 
> #DRb.thread.join
> 
> ---
> 
> my problem is that \_dump doesn't work, because the HelloWorld object gets converted into  
> DRb::DRbUnknown, which can not be converted into tuple to be inserted into the tuplespace. it does  
> not occur if i use DRb::DRbUndumped, but i think using DRb::DRbUndumped is rather unsecure if i  
> try using read instead of take to get the object out of the tuplespace. the question is:  
> - what's wrong with my \_dump (and \_load) ? do i have to use DRb::DRbUndumped ?  
> - do i have to use Rinda::Ring to work with Rinda::TupleSpace ?
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> Do You Yahoo!?  
> Tired of spam? Yahoo! Mail has the best spam protection around  
> [http://mail.yahoo.com](http://mail.yahoo.com)

---

<div class="post-metadata">

**Author:** ![Ara.T.Howard6](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Ara.T.Howard6](https://rubytalk.org/u/Ara.T.Howard6)\
**Post date:** [10 April 2006 15:42 UTC](https://rubytalk.org/t/do-i-have-to-use-drbundumped/26551/2 "2006-04-10T15:42:22Z")

</div>

yn Tue, 11 Apr 2006, holy sinner wrote:

> - what's wrong with my \_dump (and \_load) ? do i have to use DRb::DRbUndumped ?

harp:~ \> cat a.rb  
require 'rinda/ring'

class HelloWorld  
&nbsp;&nbsp;&nbsp;def initialize(str) @str = str end  
&nbsp;&nbsp;&nbsp;def \_dump(\*a, &b) Marshal.dump(@str, \*a, &b) end  
&nbsp;&nbsp;&nbsp;def HelloWorld.\_load(\*a, &b) new(Marshal.load(\*a, &b)) end  
&nbsp;&nbsp;&nbsp;def to\_s() @str end  
end

hello\_world = HelloWorld.new 'hello world'

puts(Marshal.load(Marshal.dump(hello\_world)))

harp:~ \> ruby a.rb  
hello world

-a

> **···**
>
> --  
> be kind whenever possible... it is always possible.  
> - h.h. the 14th dali lama

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [10 April 2006 18:10 UTC](https://rubytalk.org/t/do-i-have-to-use-drbundumped/26551/3 "2006-04-10T18:10:21Z")

</div>

> i am currently using Ruby 1.8.4 and DRb 2.0.4, and i am stuck with some marshalling problem  
> related to tuplespace. this is my hello world code using tuplespace
> 
> ---  
> #HelloWorld.rb  
> require "rinda/ring"
> 
> class HelloWorld  
> # include DRbUndumped  
> &nbsp;&nbsp;def initialize(str)  
> &nbsp;&nbsp;&nbsp;&nbsp;@str = str  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;def \_dump(dumpDepth)  
> &nbsp;&nbsp;&nbsp;&nbsp;@str  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;def HelloWorld.\_load(srcString)  
> &nbsp;&nbsp;&nbsp;&nbsp;HelloWorld.new(srcString)  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;def to\_s  
> &nbsp;&nbsp;&nbsp;&nbsp;@str  
> &nbsp;&nbsp;end  
> end
> 
> 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!")])
> 
> aHelloWorldObject = tupleSpace.take(["helloWorldObject", nil])  
> puts aHelloWorldObject[1]
> 
> #DRb.thread.join
> 
> ---
> 
> my problem is that \_dump doesn't work, because the HelloWorld object gets converted into DRb::DRbUnknown, which can not be converted into tuple to be inserted into the tuplespace. it does not occur if i use DRb::DRbUndumped, but i think using DRb::DRbUndumped is rather unsecure if i try using read instead of take to get the object out of the tuplespace.

Unsecure? Why?

If you're worried about losing the object due to the taking process dying use a TupleSpaceProxy. It ensures that the object won't get lost.

> the question is:  
> - what's wrong with my \_dump (and \_load) ? do i have to use DRb::DRbUndumped ?

You should really use marshal\_load and marshal\_dump. DRb::DRbUndumped must be used on objects that don't have their class present on all ruby processes in the system.

> - do i have to use Rinda::Ring to work with Rinda::TupleSpace ?

No. Rinda::Ring lets you find DRb services easily. It is zeroconf for DRb.

> **···**
>
> On Apr 10, 2006, at 8:23 AM, holy sinner wrote:
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://blog.segment7.net](http://blog.segment7.net)  
> This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![Guest10](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@Guest10](https://rubytalk.org/u/Guest10)\
**Post date:** [11 April 2006 07:29 UTC](https://rubytalk.org/t/do-i-have-to-use-drbundumped/26551/4 "2006-04-11T07:29:34Z")

</div>

thanx, it indeed can replace DRbUndumped, but with the same consequence:  
it is still a pass-by-reference thing, which is rather dangerous to be  
used when working with tuplespace's read operation.

consider this, what if two clients read the same object written by some  
server, and one of the client modifies the object (hoping it would only  
change his "copy of object"). using DRbUndumped or this alternative  
marshalling is a bad method, since the object would still appear changed  
on both clients.

what i really need is a pass-by-value marshalling so that the one  
written into the space is actually the copy of the real object, and not  
the reference to it. can anyone help me? i believe the drawback of  
having the client to own physical copy of the object's class (i.e. the  
object's source code) is not something to be worried about. or is there  
any other disadvantage of using pass-by-value compared to using  
pass-by-reference, maybe speed / execution time?

i currently combine Rinda::TupleSpace and Rinda::Ring instead of putting  
the tuplespace as a DRbServer's front object, trying to make the whole  
thing works like jini

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [11 April 2006 17:47 UTC](https://rubytalk.org/t/do-i-have-to-use-drbundumped/26551/5 "2006-04-11T17:47:01Z")

</div>

Not quoting past messages is very bad form. Please quote relevant parts of the message you are replying to.

> thanx, it indeed can replace DRbUndumped, but with the same consequence:  
> it is still a pass-by-reference thing, which is rather dangerous to be  
> used when working with tuplespace's read operation.

#read is not dangerous. #take can lose the object if the taking node quits before receiving the object, so you should use a TupleSpaceProxy whenever you take tuples.

> consider this, what if two clients read the same object written by some  
> server, and one of the client modifies the object (hoping it would only  
> change his "copy of object"). using DRbUndumped or this alternative  
> marshalling is a bad method, since the object would still appear changed  
> on both clients.

That is as intended. It is called Distributed Ruby after all.

It sounds like you really want some kind of access control or locking mechanism.

> what i really need is a pass-by-value marshalling so that the one  
> written into the space is actually the copy of the real object, and not  
> the reference to it. can anyone help me? i believe the drawback of  
> having the client to own physical copy of the object's class (i.e. the  
> object's source code) is not something to be worried about. or is there  
> any other disadvantage of using pass-by-value compared to using  
> pass-by-reference, maybe speed / execution time?

Your problem seems to be an implementation detail. It seems you want an object usable by only one node at a time.

You should either use take to remove the object from the TupleSpace or provide locking via the TupleSpace to prevent other nodes from fiddling with your object while one node is working on it.

Pass by reference allows a transparent object space. Pass by value is going to complicate your design much more than building atop of the primitive operations TupleSpace provides.

> i currently combine Rinda::TupleSpace and Rinda::Ring instead of putting  
> the tuplespace as a DRbServer's front object, trying to make the whole  
> thing works like jini

I don't understand what this means.

> **···**
>
> On Apr 11, 2006, at 12:29 AM, xaea alvein wrote:
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://blog.segment7.net](http://blog.segment7.net)  
> This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![Guest10](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@Guest10](https://rubytalk.org/u/Guest10)\
**Post date:** [12 April 2006 07:48 UTC](https://rubytalk.org/t/do-i-have-to-use-drbundumped/26551/6 "2006-04-12T07:48:53Z")

</div>

Eric Hodel wrote:

> Not quoting past messages is very bad form. Please quote relevant  
> parts of the message you are replying to.

i am very sorry

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

> ...
> 
> #read is not dangerous. #take can lose the object if the taking node  
> quits before receiving the object, so you should use a  
> TupleSpaceProxy whenever you take tuples.

i am using tuplespaceproxy, thank you

> That is as intended. It is called Distributed Ruby after all.
> 
> It sounds like you really want some kind of access control or locking  
> mechanism.
> 
> ...
> 
> Your problem seems to be an implementation detail. It seems you want  
> an object usable by only one node at a time.
> 
> You should either use take to remove the object from the TupleSpace  
> or provide locking via the TupleSpace to prevent other nodes from  
> fiddling with your object while one node is working on it.
> 
> Pass by reference allows a transparent object space. Pass by value  
> is going to complicate your design much more than building atop of  
> the primitive operations TupleSpace provides.
> 
> > i currently combine Rinda::TupleSpace and Rinda::Ring instead of  
> > putting  
> > the tuplespace as a DRbServer's front object, trying to make the whole  
> > thing works like jini
> 
> I don't understand what this means.

javaspace is a service to jini. for further reference, please use  
[http://www.jini.org](http://www.jini.org)

i am using Rinda::TupleSpace and Rinda::Ring based on your example, Mr.  
Eric, and i prefer using it compared to serving a TupleSpace instance as  
a DRbServer's front object, since the Ring API works somehow like jini's  
lookup service

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Guest10](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@Guest10](https://rubytalk.org/u/Guest10)\
**Post date:** [13 April 2006 17:20 UTC](https://rubytalk.org/t/do-i-have-to-use-drbundumped/26551/7 "2006-04-13T17:20:35Z")

</div>

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  
> &nbsp;&nbsp;attr\_writer :str  
> # you can use DRbUndumped or the following.  
> # either results in the same  
> &nbsp;&nbsp;def initialize(str)  
> &nbsp;&nbsp;&nbsp;&nbsp;@str = str  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;def \_dump(\*args, &block)  
> &nbsp;&nbsp;&nbsp;&nbsp;Marshall.dump(@str, \*args, &block)  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;def HelloWorld.\_load(\*args, &block)  
> &nbsp;&nbsp;&nbsp;&nbsp;HelloWorld.new(Marshall.load(\*args, &block))  
> &nbsp;&nbsp;end  
> &nbsp;&nbsp;def to\_s  
> &nbsp;&nbsp;&nbsp;&nbsp;@str  
> &nbsp;&nbsp;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 {  
> &nbsp;&nbsp;aHelloWorldObject = tupleSpace.read(["helloWorldObject", nil])  
> &nbsp;&nbsp;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/\](http://www.ruby-forum.com/%5C).
