On Jul 11, 2007, at 12:15 PM, Nwallins wrote:
d = DRbObject.new_with_uri(“druby://:1234”)
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