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