Hello again -
Thanks for replying.
AFAIK, casting in Java doesn’t actually change the underlying object, it
just gives you assurance at runtime that you have an object of the type
you are casting to, or you get a classcastexception.
It doesn’t change it particularly - but yes - allows you to have that
object type that it fits into - this issue being the perfect example.
I can do this if I just call a new on the ConnectionFactory - but that
removes accessing the factories via a pool - so isn’t what we want. The
jndi lookup is returning the generic adapter - which we then cast to
what we need if we need to access certain methods for that particular
one.
A google search
later and I can’t see this setProperty method on either
QueueConnectionFactory (Java 2 Platform Ent. Ed. v1.4)http://java.sun.com/j2ee/1.4/docs/api/javax/jms/QueueConnectionFactory.html
or
com.sun.messaging.jms.ra: public class: ConnectionFactoryAdapterhttp://www.docjar.com/docs/api/com/sun/messaging/jms/ra/ConnectionFactoryAdapter.html
These are the casts directly - the method is in there:
http://www.docjar.com/docs/api/com/sun/messaging/ConnectionFactory.html
http://www.docjar.com/docs/api/com/sun/messaging/QueueConnectionFactory.html
Perhaps your JNDI lookup is returning a different type of object to the
one you expect? What type actually has this setProperty method?
This is returning: Java::ComSunMessagingJmsRa::ConnectionFactoryAdapter
which is:
com.sun.messaging.ConnectionFactory
com.sun.messaging.QueueConnectionFactory
which is where the method is at - to set the properties in OpenMQ. This
is a common thing to do (casting of this sort) in java - so isn’t
anything new - but I cannot get this method at all without casting the
object returned into the correct implementation.
There is no way to set the properties on the ConnectionFactory that we
get out connection from without this cast here.
Thanks.
Cheers,
Nick
On Fri, 2010-05-07 at 09:42 -0700, Robert W. wrote:
Hello -
Why do you need to cast, exactly? Jruby & Ruby are untyped, so if the
method is there, even on a java object, it’ll be called (presumably by
introspection). Are there multiple signatures for setProperty? If so,
then I’m not sure how jruby decides which method to call.
So, you should just be able to do:
conn_factory = ctx.lookup(whatever_the_key_is)
conn_factory.setProperty(key_string, value_string)
Correct - you would think that - but with jdni - the lookup does not
pull back the actual ConnectionFactory - but a ConnectionFactoryAdapter
- which is usually cast to the actual ConnectionFactory (Queue/Topic,
etc.) - to call the appropriate methods upon it.
The above does not work because ‘setProperty’ is not a part of the
ConnectionFactoryAdapter - but is available when you cast it to the
specific adapter needed.
For example - the what is returned from ‘conn_factory’ call above:
conn_factory: Java::ComSunMessagingJmsRa::ConnectionFactoryAdapter
It is pretty common to cast this to get access to the Factory specific
methods:
QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory)
jndiContext.lookup(“jms/QueueConnectionFactory”);
This is where my issue is - in that I cannot set (on a per connection
basis) the flow limit (or anything else really):
@ conn_factory.setProperty(ConnectionConfiguration.imqConsumerFlowLimit,
“1”)
Does not work at all:
undefined method `setProperty' for
#Java::ComSunMessagingJmsRa::ConnectionFactoryAdapter:0x4f124609
(NoMethodError)
Thanks.
Hope that helps,
Nick
On Fri, 2010-05-07 at 08:25 -0700, Robert W. wrote:
Hello -
I have an interesting situation where I am taking a current script
(poller) and making to work via OpenMQ/jndi/glassfish - but being that
there is no casting it seems in j/ruby - I am curious on how to make
this work.
I have a jruby class - that in the initialize method is getting the
connection setup - similar to:
@ctx = InitialContext.new
@conn_factory = @ctx.lookup(“jms/ExtQueueConnectionFactory”)
@jms_connection = @conn_factory.create_connection()
…
But I need to be able to set properties on the factory - such as the
imqConsumerFlowLimit - but the ‘setProperty()’ method is on the
‘ConnectionFactory’ object - and the factory returned above is a
ConnectionFactoryAdapter (via jndi).
In Java - would do something similar to:
connectionFactory =
(QueueConnectionFactory)ctx.lookup(“jms/ExtQueueConnectionFactory”);
Then I could set the property I would need:
connectionFactory.setProperty(ConnectionConfiguration.imqConsumerFlowLimit,
“1”);
Does anyone know if there is a way around this - or a way to actually
cast in ruby/jruby?
Thanks.
–
Robert B. Weeks
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
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