The moose likes Web Services and the fly likes JMS - Listener as inner class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "JMS - Listener as inner class" Watch "JMS - Listener as inner class" New topic

JMS - Listener as inner class

wai yuan

Joined: Dec 30, 2005
Posts: 9
I am trying to understand this (the code is working):

A QueueReceiver Wrapper class JMSReceiver has a inner class JMSListenerInstance which acts like a Listener. In the source code, JMSListenerInstance has 2 constructors:


The first constructor is empty, the second does something as following:

myQSession = (QueueSession)getJMSConnection().createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
Queue responseQueue = myQSession.createQueue(myQName);
QueueReceiver myQReceiver = myQSession.createReceiver(responseQueue);

*getJMSConnection is JMSReceiver method, basically just return a established connection.

And the JMSReceiver setup the listener by calling the first constructor

new JMSListenerInstance()

but not the second one. I would have thought the code is wrong if I don't know the code is actually working.

After compiling this code and look at it through eclipse. The 2 constructors become:

JMSListenerInstance(JMSReceiver, int)

So does the compiler do something to actually make this code work?
wai yuan

Joined: Dec 30, 2005
Posts: 9
Never mind.
This empty Listener actually is put into a object pool. And the pool manager calls the listener's function newInstance(). And this function creates a new listener by using the second constructor.
I agree. Here's the link:
subject: JMS - Listener as inner class
It's not a secret anymore!