File an issue for this please. I think we could make Java arrays
trivially serializable by giving them named classes rather than
anonymous classes.

A possible workaround might be this:

$ jirb
irb(main):001:0> bytes = 'foo'.to_java_bytes
=> byte[102, 111, 111]@c5a311d
irb(main):002:0> bytes.class
=> #<Class:0x3fd9af48>
irb(main):003:0> ByteArray = bytes.class
=> ByteArray
irb(main):004:0> bytes.class
=> ByteArray
irb(main):005:0> Marshal.dump(bytes)
=> 
"\x04\bU:\x0EByteArray\"#\xAC\xED\x00\x05ur\x00\x02[B\xAC\xF3\x17\xF8\x06\bT\xE0\x02\x00\x00xp\x00\x00\x00\x03foo"

There's a bit more fiddling around to get this to properly enlist in
Java serialization + marshaling, but it's not far off.

- Charlie

On Tue, Jul 16, 2013 at 11:02 AM, Rodrigo Rosenfeld Rosas
<rr.ro...@gmail.com> wrote:
> I've just published an article on how I'm using DRb to command JRuby from
> MRI:
>
> http://rosenfeld.herokuapp.com/en/articles/ruby-rails/2013-07-16-running-java-from-mri-ruby-through-drb
>
> I'd appreciate any feedbacks on how to avoid the mentioned warning, since I
> need to include that DRb::DRbUndumped module, at least for byte arrays.
>
> Thanks in advance,
> Rodrigo.
>
> Em 16-07-2013 07:57, Rodrigo Rosenfeld Rosas escreveu:
>
>> if I extend the byte[] with DRb::DRbUndumped it works but I get a warning
>> in the server application:
>>
>> server.rb:9 warning: singleton on non-persistent Java type
>> #<Class:0x4d7c1b64> (http://wiki.jruby.org/Persistence)
>>
>> Em 16-07-2013 07:44, Rodrigo Rosenfeld Rosas escreveu:
>>>
>>> Why isn't it possible to pass byte[] back to JRuby DRb server? I believe
>>> it should be passed by reference, right?
>>>
>>> Here's an example code:
>>>
>>> server.rb
>>> require 'drb/drb'
>>>
>>> class Service
>>>   def to_java_bytes(str)
>>>     str.to_java_bytes
>>>   end
>>>
>>>   def from_java_bytes(bytes)
>>>     String.from_java_bytes bytes
>>>   end
>>> end
>>>
>>> service = Service.new
>>>
>>> p service.from_java_bytes service.to_java_bytes 'Test'
>>>
>>> DRb.start_service "druby://localhost:8787", Service.new
>>>
>>> DRb.thread.join
>>>
>>>
>>> client.rb
>>> require 'drb/drb'
>>>
>>> DRb.start_service
>>>
>>> service = DRbObject.new_with_uri "druby://localhost:8787"
>>>
>>> p service.from_java_bytes service.to_java_bytes 'Test'
>>>
>>>
>>> Running the client with JRuby, I get this stacktrace:
>>>
>>> TypeError: can't retrieve anonymous class #<Class:0x2b753bb9>
>>>             load at org/jruby/RubyMarshal.java:148
>>>             load at
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:626
>>>      synchronize at org/jruby/ext/thread/Mutex.java:149
>>>             load at
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:622
>>>       recv_reply at
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:674
>>>       recv_reply at
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:959
>>>     send_message at
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:1238
>>>   method_missing at
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:1129
>>>             open at
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:1213
>>>   method_missing at
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:1128
>>>      with_friend at
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:1146
>>>   method_missing at
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:1127
>>>           (root) at client.rb:7
>>>
>>> Running with MRI 2.0.0 I get this stacktrace:
>>>
>>> (druby://localhost:8787) org/jruby/RubyMarshal.java:148:in `load': can't
>>> retrieve anonymous class #<Class:0x2b753bb9> (TypeError)
>>>         from (druby://localhost:8787)
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:530:in `_load'
>>>         from (druby://localhost:8787) org/jruby/RubyMarshal.java:148:in
>>> `load'
>>>         from (druby://localhost:8787)
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:626:in `load'
>>>         from (druby://localhost:8787)
>>> org/jruby/ext/thread/Mutex.java:149:in `synchronize'
>>>         from (druby://localhost:8787)
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:622:in `load'
>>>         from (druby://localhost:8787)
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:660:in
>>> `recv_request'
>>>         from (druby://localhost:8787) org/jruby/RubyFixnum.java:285:in
>>> `times'
>>>         from (druby://localhost:8787)
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:659:in
>>> `recv_request'
>>>         from (druby://localhost:8787)
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:949:in
>>> `recv_request'
>>>         from (druby://localhost:8787)
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:1564:in
>>> `init_with_client'
>>>         from (druby://localhost:8787)
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:1576:in
>>> `setup_message'
>>>         from (druby://localhost:8787)
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:1528:in
>>> `perform'
>>>         from (druby://localhost:8787)
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:1627:in
>>> `main_loop'
>>>         from (druby://localhost:8787) org/jruby/RubyKernel.java:1489:in
>>> `loop'
>>>         from (druby://localhost:8787)
>>> /home/rodrigo/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/drb/drb.rb:1623:in
>>> `main_loop'
>>>         from client.rb:7:in `<main>'
>>>
>>> Is there any work-around that would allow me to pass byte[] back to the
>>> server?
>>>
>>> Thanks in advance,
>>> Rodrigo.
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to