Package org.apache.qpid.jms
Class JmsMessageConsumer
- java.lang.Object
-
- org.apache.qpid.jms.JmsMessageConsumer
-
- All Implemented Interfaces:
jakarta.jms.MessageConsumer,java.lang.AutoCloseable,JmsMessageAvailableConsumer,JmsMessageDispatcher
- Direct Known Subclasses:
JmsQueueReceiver,JmsSharedMessageConsumer,JmsTopicSubscriber
public class JmsMessageConsumer extends java.lang.Object implements java.lang.AutoCloseable, jakarta.jms.MessageConsumer, JmsMessageAvailableConsumer, JmsMessageDispatcher
implementation of a JMS Message Consumer
-
-
Field Summary
Fields Modifier and Type Field Description protected intacknowledgementModeprotected java.lang.Stringaddressprotected JmsMessageAvailableListeneravailableListenerprotected java.util.concurrent.atomic.AtomicBooleanclosedprotected JmsConnectionconnectionprotected JmsConsumerInfoconsumerInfoprotected org.apache.qpid.jms.JmsMessageConsumer.MessageDeliverTaskdeliveryTaskprotected java.util.concurrent.locks.ReentrantLockdispatchLockprotected java.util.concurrent.atomic.AtomicReference<java.lang.Throwable>failureCauseprotected java.util.concurrent.locks.Locklockprotected jakarta.jms.MessageListenermessageListenerprotected MessageQueuemessageQueueprotected JmsSessionsessionprotected JmsTracertracer
-
Constructor Summary
Constructors Modifier Constructor Description protectedJmsMessageConsumer(JmsConsumerId consumerId, JmsSession session, JmsDestination destination, java.lang.String selector, boolean noLocal)protectedJmsMessageConsumer(JmsConsumerId consumerId, JmsSession session, JmsDestination destination, java.lang.String name, java.lang.String selector, boolean noLocal)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckClosed()protected voidcheckMessageListener()voidclose()protected voiddoClose()Called to initiate shutdown of Producer resources and request that the remote peer remove the registered producer.JmsMessageAvailableListenergetAvailableListener()Gets the listener used to notify synchronous consumers that there is a message available so that theMessageConsumer.receiveNoWait()can be called.JmsConsumerIdgetConsumerId()JmsDestinationgetDestination()jakarta.jms.MessageListenergetMessageListener()protected intgetMessageQueueSize()java.lang.StringgetMessageSelector()intgetPrefetchSize()Gets the configured prefetch size for this consumer.voidinit()booleanisBrowser()booleanisDurableSubscription()protected booleanisNoLocal()booleanisPullConsumer()booleanisSharedSubscription()protected voidonConnectionInterrupted()protected voidonConnectionRecovered(Provider provider)protected voidonConnectionRecovery(Provider provider)protected voidonConnectionRestored()voidonInboundMessage(JmsInboundMessageDispatch envelope)Called from the session when a new Message has been dispatched to this Consumer from the connection.protected booleanperformPullIfRequired(long timeout, boolean treatAsPullConsumer)Triggers a pull request from the connected Provider with the given timeout value if the consumer is a pull consumer or requested to be treated as one, and the local queue is still running, and is currently empty.jakarta.jms.Messagereceive()jakarta.jms.Messagereceive(long timeout)<T> TreceiveBody(java.lang.Class<T> desired, long timeout)Reads the next available message for this consumer and returns the body of that message if the type requested matches that of the message.jakarta.jms.MessagereceiveNoWait()voidsetAvailableListener(JmsMessageAvailableListener availableListener)Sets the listener used to notify synchronous consumers that there is a message available so that theMessageConsumer.receiveNoWait()can be called.voidsetMessageListener(jakarta.jms.MessageListener listener)protected voidshutdown()Called to release all producer resources without requiring a destroy request to be sent to the remote peer.protected voidshutdown(java.lang.Throwable cause)voidstart()voidstop()
-
-
-
Field Detail
-
session
protected final JmsSession session
-
connection
protected final JmsConnection connection
-
consumerInfo
protected JmsConsumerInfo consumerInfo
-
acknowledgementMode
protected final int acknowledgementMode
-
closed
protected final java.util.concurrent.atomic.AtomicBoolean closed
-
messageListener
protected volatile jakarta.jms.MessageListener messageListener
-
availableListener
protected volatile JmsMessageAvailableListener availableListener
-
messageQueue
protected final MessageQueue messageQueue
-
lock
protected final java.util.concurrent.locks.Lock lock
-
dispatchLock
protected final java.util.concurrent.locks.ReentrantLock dispatchLock
-
failureCause
protected final java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> failureCause
-
deliveryTask
protected final org.apache.qpid.jms.JmsMessageConsumer.MessageDeliverTask deliveryTask
-
tracer
protected final JmsTracer tracer
-
address
protected final java.lang.String address
-
-
Constructor Detail
-
JmsMessageConsumer
protected JmsMessageConsumer(JmsConsumerId consumerId, JmsSession session, JmsDestination destination, java.lang.String selector, boolean noLocal) throws jakarta.jms.JMSException
- Throws:
jakarta.jms.JMSException
-
JmsMessageConsumer
protected JmsMessageConsumer(JmsConsumerId consumerId, JmsSession session, JmsDestination destination, java.lang.String name, java.lang.String selector, boolean noLocal) throws jakarta.jms.JMSException
- Throws:
jakarta.jms.JMSException
-
-
Method Detail
-
init
public void init() throws jakarta.jms.JMSException- Throws:
jakarta.jms.JMSException
-
close
public void close() throws jakarta.jms.JMSException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejakarta.jms.MessageConsumer- Throws:
jakarta.jms.JMSException
-
doClose
protected void doClose() throws jakarta.jms.JMSExceptionCalled to initiate shutdown of Producer resources and request that the remote peer remove the registered producer.- Throws:
jakarta.jms.JMSException- if an error occurs during the consumer close operation.
-
shutdown
protected void shutdown() throws jakarta.jms.JMSExceptionCalled to release all producer resources without requiring a destroy request to be sent to the remote peer. This is most commonly needed when the parent Session is closing.- Throws:
jakarta.jms.JMSException- if an error occurs during shutdown.
-
shutdown
protected void shutdown(java.lang.Throwable cause) throws jakarta.jms.JMSException- Throws:
jakarta.jms.JMSException
-
receive
public jakarta.jms.Message receive() throws jakarta.jms.JMSException- Specified by:
receivein interfacejakarta.jms.MessageConsumer- Throws:
jakarta.jms.JMSException
-
receive
public jakarta.jms.Message receive(long timeout) throws jakarta.jms.JMSException- Specified by:
receivein interfacejakarta.jms.MessageConsumer- Throws:
jakarta.jms.JMSException
-
receiveNoWait
public jakarta.jms.Message receiveNoWait() throws jakarta.jms.JMSException- Specified by:
receiveNoWaitin interfacejakarta.jms.MessageConsumer- Throws:
jakarta.jms.JMSException
-
receiveBody
public <T> T receiveBody(java.lang.Class<T> desired, long timeout) throws jakarta.jms.JMSExceptionReads the next available message for this consumer and returns the body of that message if the type requested matches that of the message. The amount of time this method blocks is based on the timeout value. timeout < 0 then it blocks until a message is received. timeout = 0 then it returns the body immediately or null if none available. timeout > 0 then it blocks up to timeout amount of time.- Parameters:
desired- The type to assign the body of the message to for return.timeout- The time to wait for an incoming message before this method returns null.- Returns:
- the assigned body of the next available message or null if the consumer is closed or the specified timeout elapses.
- Throws:
jakarta.jms.MessageFormatException- if the message body cannot be assigned to the requested type.jakarta.jms.JMSException- if an error occurs while receiving the next message.
-
checkClosed
protected void checkClosed() throws jakarta.jms.IllegalStateException- Throws:
jakarta.jms.IllegalStateException
-
onInboundMessage
public void onInboundMessage(JmsInboundMessageDispatch envelope)
Called from the session when a new Message has been dispatched to this Consumer from the connection.- Specified by:
onInboundMessagein interfaceJmsMessageDispatcher- Parameters:
envelope- the newly arrived message.
-
start
public void start()
-
stop
public void stop()
-
getConsumerId
public JmsConsumerId getConsumerId()
- Returns:
- the id
-
getDestination
public JmsDestination getDestination()
- Returns:
- the Destination
-
getMessageListener
public jakarta.jms.MessageListener getMessageListener() throws jakarta.jms.JMSException- Specified by:
getMessageListenerin interfacejakarta.jms.MessageConsumer- Throws:
jakarta.jms.JMSException
-
setMessageListener
public void setMessageListener(jakarta.jms.MessageListener listener) throws jakarta.jms.JMSException- Specified by:
setMessageListenerin interfacejakarta.jms.MessageConsumer- Throws:
jakarta.jms.JMSException
-
getMessageSelector
public java.lang.String getMessageSelector() throws jakarta.jms.JMSException- Specified by:
getMessageSelectorin interfacejakarta.jms.MessageConsumer- Throws:
jakarta.jms.JMSException
-
getPrefetchSize
public int getPrefetchSize()
Gets the configured prefetch size for this consumer.- Returns:
- the prefetch size configuration for this consumer.
-
checkMessageListener
protected void checkMessageListener() throws jakarta.jms.JMSException- Throws:
jakarta.jms.JMSException
-
getMessageQueueSize
protected int getMessageQueueSize()
-
isNoLocal
protected boolean isNoLocal()
-
isDurableSubscription
public boolean isDurableSubscription()
-
isSharedSubscription
public boolean isSharedSubscription()
-
isBrowser
public boolean isBrowser()
-
isPullConsumer
public boolean isPullConsumer()
-
setAvailableListener
public void setAvailableListener(JmsMessageAvailableListener availableListener)
Description copied from interface:JmsMessageAvailableConsumerSets the listener used to notify synchronous consumers that there is a message available so that theMessageConsumer.receiveNoWait()can be called.- Specified by:
setAvailableListenerin interfaceJmsMessageAvailableConsumer- Parameters:
availableListener- the JmsMessageAvailableListener instance to signal.
-
getAvailableListener
public JmsMessageAvailableListener getAvailableListener()
Description copied from interface:JmsMessageAvailableConsumerGets the listener used to notify synchronous consumers that there is a message available so that theMessageConsumer.receiveNoWait()can be called.- Specified by:
getAvailableListenerin interfaceJmsMessageAvailableConsumer- Returns:
- the currently configured message available listener instance.
-
onConnectionInterrupted
protected void onConnectionInterrupted()
-
onConnectionRecovery
protected void onConnectionRecovery(Provider provider) throws java.lang.Exception
- Throws:
java.lang.Exception
-
onConnectionRecovered
protected void onConnectionRecovered(Provider provider) throws java.lang.Exception
- Throws:
java.lang.Exception
-
onConnectionRestored
protected void onConnectionRestored()
-
performPullIfRequired
protected boolean performPullIfRequired(long timeout, boolean treatAsPullConsumer) throws jakarta.jms.JMSExceptionTriggers a pull request from the connected Provider with the given timeout value if the consumer is a pull consumer or requested to be treated as one, and the local queue is still running, and is currently empty.The timeout value can be one of:
< 0 to indicate that the request should never time out.
= 0 to indicate that the request should expire immediately if no message.
> 0 to indicate that the request should expire after the given time in milliseconds.- Parameters:
timeout- The amount of time the pull request should remain valid.treatAsPullConsumer- Treat the consumer as if it were a pull consumer, even if it isn't.- Returns:
- true if a pull was performed, false if it was not.
- Throws:
jakarta.jms.JMSException
-
-