On Mon, Oct 11, 2010 at 8:16 PM, Joel VanderWerf
<joelvanderwerf / gmail.com> wrote:
> On 10/11/2010 05:39 AM, Josh Mcdade wrote:
>>
>> I have server model classes that definitely need DRbUndumped. =A0Except
>> for the methods that return an array. =A0I would rather it return an arr=
ay
>> that is NOT wrapped in a DRbObject, and everything else still be a
>> DRbObject.
>>
>> Here is a client/server example: http://pastie.org/1211949
>>
>> The main reason I need this is because I'm integrating a remote backend
>> implemented in Ruby with a Java front-end, written in Java and using
>> JSR223 w/ JRuby to grab the objects. =A0The DRbObject will map to the
>> appropriate interfaces, except when the DRbObject is an Array. =A0The Ja=
va
>> application only knows the DRbObject as a org.jruby.RubyObject and it
>> cannot be cast to SomeArray[] for instance.
>>
>> I'm asking this in the Ruby forum because the DRbObject behavior is the
>> same in Ruby/JRuby, I just need it for JRuby purposes.
>>
>> I tried patching DRbObject, but I've had no success. =A0Here is my
>> attempt:
>>
>> http://pastie.org/1212829
>
> If you add this line to the client:
>
> DRb.start_service
>
> then your #each call works.

I do not think this is necessary nor does this seem to be the issue if
I get Josh correctly.

> The array stays on the server, however, and each
> iteration involves a message to and from the server to get the array entr=
y's
> DRbObject. This would be inefficient for a large array, unless your
> round-trip latency is small.

Whatever network performance, iterating an Array remotely is awfully
slow compared to in memory.  Note that for each iteration there is a
call back into the client for processing the block.  So you have 2 + n
* 2 network communications, where n is the number of items in the
Array.

> What do you actually want to get back on the client side? An array of
> DRbUndumped proxies to RemoteObj instances on the server, or an array of
> copies of Remote Obj?

I believe Josh expected the former (a local Array with proxies).  DRb
seems to apply some automatism, i.e. if there is at least one
DRbUndumped in an Array the whole Array is proxied.  If you only place
String, Fixnum etc. in the Array then you actually get a local copy.

I have no idea why this automatism is in place and I would love to
learn the wisdom behind this.  Right now it seems to much automation
to me.  But I may be overlooking something.

Kind regards

robert

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