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