[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

DRb object mutation issues

Nwallins

7/11/2007 6:11:00 PM

# 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?

6 Answers

Joel VanderWerf

7/11/2007 7:03:00 PM

0

Nwallins wrote:
> # 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)

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Nwallins

7/12/2007 5:46:00 PM

0

On Jul 11, 3:02 pm, Joel VanderWerf <v...@path.berkeley.edu> wrote:
> Nwallins wrote:
> > # 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)
>
> --
> vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Joel,

thanks for the response.

(1) is not viable, as you cannot make objects or classes undumpable
from the client
(2) does not address the issue -- to mutate the value
(3) is interesting, but violates the architecture that my simplified
example is distilled from

I'm still wondering if the demonstrated behavior is a bug or a
feature. I'm leaning towards the former ;)

- Rick

Nwallins

7/12/2007 5:50:00 PM

0

On Jul 12, 1:46 pm, Nwallins <rick.h...@gmail.com> wrote:
> On Jul 11, 3:02 pm, Joel VanderWerf <v...@path.berkeley.edu> wrote:
>
>
>
> > Nwallins wrote:
> > > # 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)
>
> > --
> > vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
>
> Joel,
>
> thanks for the response.
>
> (1) is not viable, as you cannot make objects or classes undumpable
> from the client
> (2) does not address the issue -- to mutate the value
> (3) is interesting, but violates the architecture that my simplified
> example is distilled from
>
> I'm still wondering if the demonstrated behavior is a bug or a
> feature. I'm leaning towards the former ;)
>
> - Rick

Regarding my comment for (1), I presume you mean something like this:

# file 2
require 'drb/drb'
d = DRbObject.new_with_uri("druby://:1234")
d[0] = 'zero'.extend(DRbUndumped)


# DRb::DRbConnError: DRb::DRbServerNotFound
# from /usr/lib/ruby/1.8/drb/drb.rb:1650:in `current_server'

- Rick

Nwallins

7/12/2007 5:52:00 PM

0

On Jul 12, 1:50 pm, Nwallins <rick.h...@gmail.com> wrote:
> On Jul 12, 1:46 pm, Nwallins <rick.h...@gmail.com> wrote:
>
>
>
> > On Jul 11, 3:02 pm, Joel VanderWerf <v...@path.berkeley.edu> wrote:
>
> > > Nwallins wrote:
> > > > # 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)
>
> > > --
> > > vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
>
> > Joel,
>
> > thanks for the response.
>
> > (1) is not viable, as you cannot make objects or classes undumpable
> > from the client
> > (2) does not address the issue -- to mutate the value
> > (3) is interesting, but violates the architecture that my simplified
> > example is distilled from
>
> > I'm still wondering if the demonstrated behavior is a bug or a
> > feature. I'm leaning towards the former ;)
>
> > - Rick
>
> Regarding my comment for (1), I presume you mean something like this:
>
> # file 2
> require 'drb/drb'
> d = DRbObject.new_with_uri("druby://:1234")
> d[0] = 'zero'.extend(DRbUndumped)
>
> # DRb::DRbConnError: DRb::DRbServerNotFound
> # from /usr/lib/ruby/1.8/drb/drb.rb:1650:in `current_server'
>
> - Rick

There is also this approach, but it still fails:

>> d[0].extend(DRbUndumped)
=> "zero"
>> d[0].slice!(0,1)
=> "z"
>> d[0]
=> "zero"

- Rick

Joel VanderWerf

7/12/2007 6:45:00 PM

0

Nwallins wrote:
>> 1. make the values DRbUndumped, too.
...
> (1) is not viable, as you cannot make objects or classes undumpable
> from the client

What about extend-ing the hash to make its values undumped as soon as
they are assigned? (Or subclass Hash to do this.)

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

ara.t.howard

7/12/2007 8:13:00 PM

0


On Jul 11, 2007, at 12:15 PM, Nwallins wrote:

> # 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?
>
>


cfp:~ > ruby a.rb server &
[1] 2778


cfp:~ > ruby a.rb client
316250
"druby://8-159.boulder.noaa.gov:1234"
zero
#<DRb::DRbObject:0x986ac>
ero
#<DRb::DRbObject:0x96014>

cfp:~ > cat a.rb
#! /usr/bin/env ruby
require 'drb/drb'
require 'thread'

class Table
def initialize
extend DRbUndumped
@table = {}
end
def [] k
@table[k.to_s]
end
def []= k, v
v.extend DRbUndumped
@table[k.to_s] = v
end
class ::Object
def Table(*a, &b) Table.new(*a, &b) end
end
end

mode = ARGV.shift || 'server'
case mode
when 'server'
DRb.start_service "druby://:1234", Table()
DRb.thread.join

when 'client'
d = DRbObject.new_with_uri "druby://:1234"

# this marshals data across the wire to server, never to come
back as
# anything other that a remote object
d[0] = 'zero'

# the repercusions are that you can only call remote methods on the
# object, including to_s, inspect, etc which all act as a drb
object
p d[0].__drbref
p d[0].__drburi
puts d[0].downcase
puts d[0]

# on the other hand the client may detruct object on the server
d[0].slice!(0, 1)
puts d[0].downcase
puts d[0]
end


-a
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama