When working locally with an object whose attribute is meant to store
an array, I have no problem making calls like:
object.items << new_item
If I try to do the same thing with a DRb object, though, appending has
no effect on the remote object. I've distilled the problem down to
this example...
My server:
require 'drb'
class TestServer
attr_accessor :items
def initialize @items = []
end
def add_item(item) @items << item
end
def add
sum = 0 @items.each {|item| sum += item}
sum
end
end
server = TestServer.new
DRb.start_service('druby://localhost:9000', server)
DRb.thread.join
When working locally with an object whose attribute is meant to store
an array, I have no problem making calls like:
object.items << new_item
If I try to do the same thing with a DRb object, though, appending has
no effect on the remote object.
The #items method returns an Array. That Array is not DRbUndumped (i.e., not a proxy object), so it gets _copied_ back to the client. Modifying that copy in the client can't affect the original in the server.
Your #add_item method is a good way around this.
Or, you could extend the array with DRbUndumped, to keep it on the server.
···
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
When working locally with an object whose attribute is meant to store
an array, I have no problem making calls like:
object.items << new_item
If I try to do the same thing with a DRb object, though, appending has
no effect on the remote object. I've distilled the problem down to
this example...
The BackgrounDRb mailing list will give you better odds of a good answer.
In general, I treat my background threads with the strictest isolation, and I don't go passing arrays back and forth. Consider the marshalling that must occur just for one stinkin' <<. So I don't know the answer to your question, even though I have used BackgrounDRb on 2 projects so far...
The BackgrounDRb mailing list will give you better odds of a good answer.
In general, I treat my background threads with the strictest isolation, and
I don't go passing arrays back and forth. Consider the marshalling that must
occur just for one stinkin' <<. So I don't know the answer to your question,
even though I have used BackgrounDRb on 2 projects so far...
require 'drb'
class UndumpedArray < Array
include DRbUndumped
end
class TestServer
attr_accessor :items
def initialize @items = UndumpedArray.new
end
def add
sum = 0 @items.each {|item| sum += item}
sum
end
end
server = TestServer.new
DRb.start_service('druby://localhost:9000', server)
DRb.thread.join
end
def add
sum = 0 @items.each {|item| sum += item}
sum
end
end
server = TestServer.new
DRb.start_service('druby://localhost:9000', server)
DRb.thread.join