Urgent DRb help

rubyists-

is it possible to call a method from a DRb object which creates and object,
start service for this object, and returns a handle for the new distributed
object?

class Distributed
class AlsoDistributed
end

def get_object
  ad = AlsoDistributed
  DRb.start_service nil, ad
  ad = DRbObject.new nil, DRb.uri
end

end

···

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

Hello,

is it possible to call a method from a DRb object which creates and object,
start service for this object, and returns a handle for the new distributed
object?

Do you want to distribute two or more objects by one server?

#-- s.rb
require ‘drb/drb’
require ‘monitor’

class MyObject
include DRbUndumped
def initialize(name)
@name = name
@info = {}
end
attr_accessor :name

def
@info[key]
end

def =(key, value)
@info[key] = value
end
end

class MockDB
include MonitorMixin
def initialize
super()
@db = {}
end

def
synchronize do
@db[name] ||= Element.new(name)
end
end
end

DRb.start_service(‘druby://localhost:12345’, MockDB.new)
DRb.thread.join

#-- c.rb
require ‘drb/drb’

DRb.start_service
db = DRbObject.new(nil, ‘druby://localhost:12345’)

foo = db[‘foo’]
p foo
puts foo.name
puts foo[‘age’]
foo[‘age’] = 0x20

bar = db[‘bar’]
p bar
puts bar.name
puts bar[‘age’]
bar[‘age’] = 0x10

Hello,

is it possible to call a method from a DRb object which creates and object,
start service for this object, and returns a handle for the new distributed
object?

Do you want to distribute two or more objects by one server?

#-- s.rb
require ‘drb/drb’
require ‘monitor’

class MyObject
include DRbUndumped
def initialize(name)
@name = name
@info = {}
end
attr_accessor :name

def
@info[key]
end

def =(key, value)
@info[key] = value
end
end

class MockDB
include MonitorMixin
def initialize
super()
@db = {}
end

def
synchronize do
@db[name] ||= Element.new(name)
end
end
end

DRb.start_service(‘druby://localhost:12345’, MockDB.new)
DRb.thread.join

#-- c.rb
require ‘drb/drb’

DRb.start_service
db = DRbObject.new(nil, ‘druby://localhost:12345’)

foo = db[‘foo’]
p foo
puts foo.name
puts foo[‘age’]
foo[‘age’] = 0x20

bar = db[‘bar’]
p bar
puts bar.name
puts bar[‘age’]
bar[‘age’] = 0x10

class Distributed
class AlsoDistributed

Add this:
include DRbUndumped

···

ahoward (ahoward@fsl.noaa.gov) wrote:

end

def get_object
  ad = AlsoDistributed
  DRb.start_service nil, ad
  ad = DRbObject.new nil, DRb.uri
end

end


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

[snip]

i’m trying to make a server which returns the uri of newly created (in master
server) drb servers.

-a

···

On Sat, 16 Nov 2002 m_seki@mva.biglobe.ne.jp wrote:

Do you want to distribute two or more objects by one server?

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

Add this:
include DRbUndumped

why? it seems to work without it?

./factory.rb &
./client.rb
#<DRb::DRbObject:0x401f1f1c @ref=nil, @uri=“druby://localhost:12345”>
#<DRb::DRbObject:0x401f1940 @ref=nil, @uri=“druby://dhcppc1:4723”>
“name”
“child amethod”
#<DRb::DRbObject:0x401f0cac @ref=nil, @uri=“druby://dhcppc1:4725”>
“name”
“child amethod”

factory.rb
--------cut--------
#!/usr/local/bin/ruby

require ‘drb’

class Distributed
class Parent
include DRbUndumped
def amethod
‘parent amethod’
end
def name
‘name’
end
end

class Child < Parent
include DRbUndumped
def amethod
‘child amethod’
end
end

def get_object
ad = Child.new
server = DRb::DRbServer.new(nil, ad)
DRbObject.new(nil, server.uri)
end
end

parent = Distributed::Parent.new
child = Distributed::Child.new

puts parent.amethod
puts child.amethod

DRb.start_service(‘druby://localhost:12345’, Distributed.new)
DRb.thread.join
--------cut--------

client.rb
--------cut--------
#!/usr/local/bin/ruby

require ‘drb’
require ‘drb/drb’

DRb.start_service

ro = DRbObject.new(nil, ‘druby://localhost:12345’)
p ro

it = ro.get_object
p it
p it.name
p it.amethod

it = ro.get_object
p it
p it.name
p it.amethod
--------cut--------

-a

···

On Mon, 18 Nov 2002, Eric Hodel wrote:

====================================

Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================

Do you want to distribute two or more objects by one server?
[snip]

i’m trying to make a server which returns the uri of newly created (in master
server) drb servers.

hmm…

#— s2.rb
require ‘drb/drb’

class Distributed
class AlsoDistributed
def name
inspect
end
end

def get_object
ad = AlsoDistributed.new
server = DRb::DRbServer.new(nil, ad)
DRbObject.new(nil, server.uri)
end
end

DRb.start_service(‘druby://localhost:12345’, Distributed.new)
DRb.thread.join

#— c2.rb
require ‘drb/drb’

DRb.start_service

ro = DRbObject.new(nil, ‘druby://localhost:12345’)
p ro

it = ro.get_object
p it
p it.name

it = ro.get_object
p it
p it.name

ah, in the initial snippit, I assumed you were starting the server with
Distributed, rather than its inner class. You will need to use it for a
case like this:

------ server
require ‘drb’

class Foo
def bar
return Bar.new
end
end

class Bar
def foopy
“foopy”
end
end

DRb.start_service(nil, Foo.new)

puts DRb.uri

gets

------ client

require ‘drb’

DRb.start_service
foo = DRbObject.new(nil, ‘uri’)

puts foo.bar # <= works
puts foo.bar.foopy # <= NameError, unless you include DRbUndumped in Bar
# then its “foopy”

···

ahoward (ahoward@fsl.noaa.gov) wrote:

On Mon, 18 Nov 2002, Eric Hodel wrote:

Add this:
include DRbUndumped

why? it seems to work without it?


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04