DRb object mutation issues

N

Nwallins

# file 1
require 'drb/drb'
require 'thread'
DRb.start_service("druby://:1234", Hash.new.extend(DRbUndumped))
DRb.thread.join
# EOF


# file 2
require 'drb/drb'
d = DRbObject.new_with_uri("druby://:1234")
d[0] = 'zero'
d[0] #=> "zero"
d[0].slice!(0, 1)
d[0] #=> "zero"

# file 3
h = Hash.new
h[0] = 'zero'
h[0].slice!(0, 1)
h[0] #=> "ero"

# how can I change the state of the distributed hash's values?
 
J

Joel VanderWerf

Nwallins said:
# file 1
require 'drb/drb'
require 'thread'
DRb.start_service("druby://:1234", Hash.new.extend(DRbUndumped))
DRb.thread.join
# EOF


# file 2
require 'drb/drb'
d = DRbObject.new_with_uri("druby://:1234")
d[0] = 'zero'
d[0] #=> "zero"
d[0].slice!(0, 1)
d[0] #=> "zero"

# file 3
h = Hash.new
h[0] = 'zero'
h[0].slice!(0, 1)
h[0] #=> "ero"

# how can I change the state of the distributed hash's values?

Some options:

1. make the values DRbUndumped, too.

2. use non-destructive methods on the values:

d[0] = d[0].slice(0, 1)

3. define a method on your front object that handles everything at
server side, so the client says this:

idx = 0
d.slice_at_index(idx,0,1)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,828
Latest member
LauraCastr

Latest Threads

Top