This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "JMS - Listener as inner class" Watch "JMS - Listener as inner class" New topic
Author

JMS - Listener as inner class

wai yuan
Greenhorn

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:

JMSListenerInstance()
JMSListenerInstance(int)

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);
myQReceiver.setMessageListener(this);

*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)
JMSListenerInstance(JMSReceiver, int)

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

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.
 
wood burning stoves
 
subject: JMS - Listener as inner class