From: Master Marv on
hi,
i would like to store an array of this very simple class on a drb server

class IEB_wrapper1
attr_accessor :status

def initialize
@status="ready"
end
end

the object on the drb server is an array:
dump=[]
DRb.start_service "druby://BLA:55555", dump


if a client modifies the status variable of a class instance in the
array it does not get changed.

dump = DRbObject.new nil, ARGV.shift
myclass = IEB_wrapper1.new
dump.push myclass
dump[0].status = "Hello"
p dump[0].status => results in "ready" not in "Hello"

how can i modify the status of my class in the array on the drb server?
--
Posted via http://www.ruby-forum.com/.

From: Brian Candler on
Master Marv wrote:
> if a client modifies the status variable of a class instance in the
> array it does not get changed.
>
> dump = DRbObject.new nil, ARGV.shift
> myclass = IEB_wrapper1.new
> dump.push myclass
> dump[0].status = "Hello"
> p dump[0].status => results in "ready" not in "Hello"
>
> how can i modify the status of my class in the array on the drb server?

class IEB_wrapper1
include DRbUndumped
end

This means that instead of passing across a *copy* of the object (made
using Marshal.dump and load), it will pass across a DRb *proxy object*.
All operations made on that proxy are sent across as remote method calls
and therefore made on the server.

I wrote a document called "DrbTutorial" on rubygarden.org, which
unfortunately is long since gone. You might be able to find a cached
copy somewhere.
--
Posted via http://www.ruby-forum.com/.

From: Master Marv on
> include DRbUndumped
this seems to let the class reside wherever it has been generated.
is it possible to generate a class on a drb client, copy it to the
server and then let it stay there (ie. further interaction with the
class should be made with the the class on the server and not with local
copies).

what i want to do is the following:
i have a class that has a run and a status function. when the run
function is invoked the class computes something for ~5minutes.
the calculation should happen on the drb server.
multiple drb clients should generate classes on the server(or locally
and copy them to the server), so that the server does the computation.
after the jobs have been started (remote_job_array[x].start) the clients
terminate. other clients that should check the status of the computation
via a status function (remote_job_array[x].status) of the class on the
server.
--
Posted via http://www.ruby-forum.com/.

From: Brian Candler on
Master Marv wrote:
>> include DRbUndumped
> this seems to let the class reside wherever it has been generated.
> is it possible to generate a class on a drb client, copy it to the
> server and then let it stay there (ie. further interaction with the
> class should be made with the the class on the server and not with local
> copies).

DRb has no real concept of a "server" or a "client" - connections can be
opened and method calls made from either side.

You could originate your object, pass it across to another place, and at
that point do
obj.extend DRbUndumped
which will lock it there.

But perhaps more sensible is to pass across the *parameters* needed to
make the object, i.e. have a class method on the server such as

def Foo.make_status(*args)
IEB_wrapper1.new(*args)
end

and you share the Foo object via DRb.
--
Posted via http://www.ruby-forum.com/.

From: Robert Klemme on
2009/11/26 Master Marv <marvin.mun(a)gmx.de>:
>>   include DRbUndumped
> this seems to let the class reside wherever it has been generated.
> is it possible to generate a class on a drb client, copy it to the
> server and then let it stay there (ie. further interaction with the
> class should be made with the the class on the server and not with local
> copies).
>
> what i want to do is the following:
> i have a class that has a run and a status function. when the run
> function is invoked the class computes something for ~5minutes.
> the calculation should happen on the drb server.
> multiple drb clients should generate classes on the server(or locally
> and copy them to the server), so that the server does the computation.
> after the jobs have been started (remote_job_array[x].start) the clients
> terminate. other clients that should check the status of the computation
> via a status function (remote_job_array[x].status) of the class on the
> server.

DRb does not implement the concept of moving *code* around. You
either have to do it manually (there are several ways to do that) or
you have to require the class needed for the operation to be present
on the server already.

Ways how you can send over code:

- as a string of valid Ruby code (very insecure)
- as the name of a file to load on the server (a bit more secure)
- as a string of a particular DSL you invent for the task
- in your case you might be able to parametrize class generation and
do it completely on the server

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/