Fwd: Commented: (JRUBY-5166) ClassCastException when Queue implements Java interface

I had problems with the jira emailer: Got told the user was
above-quota.
So, I’m forwarding this here, in the hopes that others can offer Wisdom
to
me.

Cheers,
–Bob

---------- Forwarded message ----------
From: Bob W. (JIRA) [email protected]
Date: Mon, Nov 1, 2010 at 12:38 PM
Subject: [jira] Commented: (JRUBY-5166) ClassCastException when Queue
implements Java interface
To: [email protected]

[
http://jira.codehaus.org/browse/JRUBY-5166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=241695#action_241695]

Bob W. commented on JRUBY-5166:

Hi Charles,

Thanks so much for looking at this. If I understand what you’ve done,
I’d
almost suggest rolling back the commit. I’m not going to second-guess
decisions you’ve had to make wrt
functionality/performance/maintainability,
but it seems to me the current behavior is quite complicated to
document:

Implementing Java Interfaces
You declare that your class implements a Java interface by using
"include
".

  • Except that this doesn’t work with classes derived from core JRuby
    classes.
    • Except that it does work with Thread.Queue.

As I’m apparently the only one who’s complained about this, I will take
your
strong recommendation to do something different.

Now, I will presume to ask for design advice. This whole thing started
with
the following class:


require ‘thread’
require ‘jmx_server’ # Bob’s little JMX module

class MonitorableQueue < Queue
include JMX
jmx_attr_reader :queue_size, :jmx_queue_name

def initialize(object_name = ‘name=queue’)
super()
@jmx_queue_name = object_name
jmx_register_as(object_name)
end

def queue_size
self.size
end
end

The “JMX” module is one I wrote, and I’ll confess is at the edges of my
understanding/capabilities (it uses some class instance variables, which
make this old-schooler’s brain hurt). However, it worked in previous
versions, and “felt” nice. You just include JMX, then use
jmx_attr_reader/writer/accessor to export things for JMX monitoring.
Otherwise, you just use it as a Queue. Inside that module is where
there’s
the troublesome line:

include Java::javax.management.DynamicMbean

That’s the interface that does all the JMX stuff.

Anyway, I now need to refactor this, and if you’ve time to offer any
broad
suggestions, I’d appreciate it.

I’m feeling like perhaps I need to learn about Delegates, although I’m
currently unsure which direction to delegate. Or perhaps that’s not
right
at all.

Anyway, in spite of my whining, thanks much for your work on JRuby.

Cheers,
–Bob

       Reporter: Bob W.

end
puts RunnableQueue.new.size

The exception looks like:

org/jruby/libraries/ThreadLibrary$Queue$i_method_0_0$RUBYINVOKER$length.gen:65535:in
`call’: java.lang.ClassCastException: RunnableQueue_367947505 cannot be
cast
to org.jruby.libraries.ThreadLibrary$Queue

bash-3.2$

I hope this is not a waste of your time: I think this is how I should
be able to make Queue declare that it implements a Java interface. This
runs successfully on 1.1.6 and 1.2
Cheers,
–Bob


This message is automatically generated by JIRA.

If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa

For more information on JIRA, see:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs