Class ClientConsumerImpl
- All Implemented Interfaces:
AutoCloseable,ClientConsumer,ClientConsumerInternal
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionClientConsumerImpl(ClientSessionInternal session, ConsumerContext consumerContext, SimpleString queueName, SimpleString filterString, int priority, boolean browseOnly, int initialWindow, int clientWindowSize, int ackBatchSize, TokenBucketLimiter rateLimiter, Executor executor, Executor flowControlExecutor, SessionContext sessionContext, ClientSession.QueueQuery queueInfo, ClassLoader contextClassLoader, int onMessageCloseTimeout) -
Method Summary
Modifier and TypeMethodDescriptionvoidacknowledge(ClientMessage message) voidcleanUp()voidclear(boolean waitForOnMessage) voidvoidclose()Closes the consumer.voidflowControl(int messageBytes, boolean discountSlowConsumer) LargeMessageBuffer will call flowcontrol here, while other handleMessage will also be calling flowControl.voidintintThe server's ID associated with this consumer.longintReturns the last exception thrown by a call to this consumer's MessageHandler ornull.Calling this method on a closed consumer will throw an ActiveMQException.intvoidhandleLargeMessage(ClientLargeMessageInternal clientLargeMessage, long largeMessageSize) voidhandleLargeMessageContinuation(byte[] chunk, int flowControlSize, boolean isContinues) voidhandleMessage(ClientMessageInternal message) voidindividualAcknowledge(ClientMessage message) booleanbooleanisClosed()Returnstrueif this consumer is closed,falseelse.prepareForClose(FutureLatch future) To be used by MDBs to stop any more handling of messages.receive()Receives a message from a queue.receive(long timeout) Receives a message from a queue.Receives a message from a queue.voidsetManualFlowMessageHandler(MessageHandler theHandler) setMessageHandler(MessageHandler theHandler) Sets the MessageHandler for this consumer to consume messages asynchronously.voidstart()voidstop(boolean waitForOnMessage) toString()
-
Field Details
-
FORCED_DELIVERY_MESSAGE
-
-
Constructor Details
-
ClientConsumerImpl
public ClientConsumerImpl(ClientSessionInternal session, ConsumerContext consumerContext, SimpleString queueName, SimpleString filterString, int priority, boolean browseOnly, int initialWindow, int clientWindowSize, int ackBatchSize, TokenBucketLimiter rateLimiter, Executor executor, Executor flowControlExecutor, SessionContext sessionContext, ClientSession.QueueQuery queueInfo, ClassLoader contextClassLoader, int onMessageCloseTimeout)
-
-
Method Details
-
getConsumerContext
Description copied from interface:ClientConsumerThe server's ID associated with this consumer. ActiveMQ Artemis implements this as a long but this could be protocol dependent.- Specified by:
getConsumerContextin interfaceClientConsumer
-
receive
Description copied from interface:ClientConsumerReceives a message from a queue.This call will block until a message is received or the given timeout expires.
Calling this method on a closed consumer will throw an ActiveMQException.
- Specified by:
receivein interfaceClientConsumer- Parameters:
timeout- time (in milliseconds) to wait to receive a message- Returns:
- a message or
nullif the time out expired - Throws:
ActiveMQException- if an exception occurs while waiting to receive a message
-
receive
Description copied from interface:ClientConsumerReceives a message from a queue.This call will block indefinitely until a message is received.
Calling this method on a closed consumer will throw an ActiveMQException.
- Specified by:
receivein interfaceClientConsumer- Returns:
- a ClientMessage
- Throws:
ActiveMQException- if an exception occurs while waiting to receive a message
-
receiveImmediate
Description copied from interface:ClientConsumerReceives a message from a queue. This call will force a network trip to ActiveMQ Artemis server to ensure that there are no messages in the queue which can be delivered to this consumer.This call will never wait indefinitely for a message, it will return
nullif no messages are available for this consumer.Note however that there is a performance cost as an additional network trip to the server may required to check the queue status.
Calling this method on a closed consumer will throw an ActiveMQException.
- Specified by:
receiveImmediatein interfaceClientConsumer- Returns:
- a message or
nullif there are no messages in the queue for this consumer - Throws:
ActiveMQException- if an exception occurs while waiting to receive a message
-
getMessageHandler
Description copied from interface:ClientConsumerCalling this method on a closed consumer will throw an ActiveMQException.- Specified by:
getMessageHandlerin interfaceClientConsumer- Returns:
- the MessageHandler associated to this consumer or
null - Throws:
ActiveMQException- if an exception occurs while getting the MessageHandler
-
getCurrentThread
- Specified by:
getCurrentThreadin interfaceClientConsumerInternal
-
setManualFlowMessageHandler
public ClientConsumer setManualFlowMessageHandler(MessageHandler theHandler) throws ActiveMQException - Specified by:
setManualFlowMessageHandlerin interfaceClientConsumerInternal- Throws:
ActiveMQException
-
setMessageHandler
Description copied from interface:ClientConsumerSets the MessageHandler for this consumer to consume messages asynchronously.Note that setting a handler dedicates the parent session, and its child producers and consumers, to the session-wide handler delivery thread of control.
Calling this method on a closed consumer will throw a ActiveMQException.
- Specified by:
setMessageHandlerin interfaceClientConsumer- Parameters:
theHandler- a MessageHandler- Throws:
ActiveMQException- if an exception occurs while setting the MessageHandler
-
close
Description copied from interface:ClientConsumerCloses the consumer.Once this consumer is closed, it can not receive messages, whether synchronously or asynchronously.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceClientConsumer- Throws:
ActiveMQException
-
prepareForClose
To be used by MDBs to stop any more handling of messages.- Specified by:
prepareForClosein interfaceClientConsumerInternal- Parameters:
future- the future to run once the onMessage Thread has completed- Throws:
ActiveMQException
-
cleanUp
public void cleanUp()- Specified by:
cleanUpin interfaceClientConsumerInternal
-
isClosed
public boolean isClosed()Description copied from interface:ClientConsumerReturnstrueif this consumer is closed,falseelse.- Specified by:
isClosedin interfaceClientConsumer- Returns:
trueif this consumer is closed,falseelse
-
stop
- Specified by:
stopin interfaceClientConsumerInternal- Throws:
ActiveMQException
-
clearAtFailover
public void clearAtFailover()- Specified by:
clearAtFailoverin interfaceClientConsumerInternal
-
start
public void start()- Specified by:
startin interfaceClientConsumerInternal
-
getLastException
Description copied from interface:ClientConsumerReturns the last exception thrown by a call to this consumer's MessageHandler ornull.- Specified by:
getLastExceptionin interfaceClientConsumer- Returns:
- the last exception thrown by a call to this consumer's MessageHandler or
null
-
getQueueInfo
- Specified by:
getQueueInfoin interfaceClientConsumerInternal
-
getForceDeliveryCount
public long getForceDeliveryCount()- Specified by:
getForceDeliveryCountin interfaceClientConsumerInternal
-
getFilterString
- Specified by:
getFilterStringin interfaceClientConsumerInternal
-
getPriority
public int getPriority()- Specified by:
getPriorityin interfaceClientConsumerInternal
-
getQueueName
- Specified by:
getQueueNamein interfaceClientConsumerInternal
-
isBrowseOnly
public boolean isBrowseOnly()- Specified by:
isBrowseOnlyin interfaceClientConsumerInternal
-
handleMessage
- Specified by:
handleMessagein interfaceClientConsumerInternal- Throws:
Exception
-
handleLargeMessage
public void handleLargeMessage(ClientLargeMessageInternal clientLargeMessage, long largeMessageSize) throws Exception - Specified by:
handleLargeMessagein interfaceClientConsumerInternal- Throws:
Exception
-
handleLargeMessageContinuation
public void handleLargeMessageContinuation(byte[] chunk, int flowControlSize, boolean isContinues) throws Exception - Specified by:
handleLargeMessageContinuationin interfaceClientConsumerInternal- Throws:
Exception
-
clear
- Specified by:
clearin interfaceClientConsumerInternal- Throws:
ActiveMQException
-
getInitialWindowSize
public int getInitialWindowSize()- Specified by:
getInitialWindowSizein interfaceClientConsumerInternal
-
getClientWindowSize
public int getClientWindowSize()- Specified by:
getClientWindowSizein interfaceClientConsumerInternal
-
getBufferSize
public int getBufferSize()- Specified by:
getBufferSizein interfaceClientConsumerInternal
-
acknowledge
- Specified by:
acknowledgein interfaceClientConsumerInternal- Throws:
ActiveMQException
-
individualAcknowledge
- Specified by:
individualAcknowledgein interfaceClientConsumerInternal- Throws:
ActiveMQException
-
flushAcks
- Specified by:
flushAcksin interfaceClientConsumerInternal- Throws:
ActiveMQException
-
flowControl
LargeMessageBuffer will call flowcontrol here, while other handleMessage will also be calling flowControl. So, this operation needs to be atomic.- Specified by:
flowControlin interfaceClientConsumerInternal- Parameters:
discountSlowConsumer- When dealing with slowConsumers, we need to discount one credit that was pre-sent when the first receive was called. For largeMessage that is only done at the latest packet- Throws:
ActiveMQException
-
resetIfSlowConsumer
public void resetIfSlowConsumer()- Specified by:
resetIfSlowConsumerin interfaceClientConsumerInternal
-
toString
-