Class ClientConsumerImpl
- java.lang.Object
-
- org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl
-
- All Implemented Interfaces:
AutoCloseable,ClientConsumer,ClientConsumerInternal
public final class ClientConsumerImpl extends Object implements ClientConsumerInternal
-
-
Field Summary
Fields Modifier and Type Field Description static SimpleStringFORCED_DELIVERY_MESSAGE
-
Constructor Summary
Constructors Constructor Description 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)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidacknowledge(ClientMessage message)voidcleanUp()voidclear(boolean waitForOnMessage)voidclearAtFailover()voidclose()Closes the consumer.voidflowControl(int messageBytes, boolean discountSlowConsumer)LargeMessageBuffer will call flowcontrol here, while other handleMessage will also be calling flowControl.voidflushAcks()intgetBufferSize()intgetClientWindowSize()ConsumerContextgetConsumerContext()The server's ID associated with this consumer.ThreadgetCurrentThread()SimpleStringgetFilterString()longgetForceDeliveryCount()intgetInitialWindowSize()ExceptiongetLastException()Returns the last exception thrown by a call to this consumer's MessageHandler.MessageHandlergetMessageHandler()Returns the MessageHandler associated to this consumer.intgetPriority()ClientSession.QueueQuerygetQueueInfo()SimpleStringgetQueueName()voidhandleLargeMessage(ClientLargeMessageInternal clientLargeMessage, long largeMessageSize)voidhandleLargeMessageContinuation(byte[] chunk, int flowControlSize, boolean isContinues)voidhandleMessage(ClientMessageInternal message)voidindividualAcknowledge(ClientMessage message)booleanisBrowseOnly()booleanisClosed()Returns whether the consumer is closed or not.ThreadprepareForClose(FutureLatch future)To be used by MDBs to stop any more handling of messages.ClientMessagereceive()Receives a message from a queue.ClientMessagereceive(long timeout)Receives a message from a queue.ClientMessagereceiveImmediate()Receives a message from a queue.ClientConsumerImplsetMessageHandler(MessageHandler theHandler)Sets the MessageHandler for this consumer to consume messages asynchronously.voidstart()voidstop(boolean waitForOnMessage)StringtoString()
-
-
-
Field Detail
-
FORCED_DELIVERY_MESSAGE
public static final SimpleString FORCED_DELIVERY_MESSAGE
-
-
Constructor Detail
-
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)
-
-
Method Detail
-
getConsumerContext
public ConsumerContext 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- Returns:
-
receive
public ClientMessage receive(long timeout) throws ActiveMQException
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
public ClientMessage receive() throws ActiveMQException
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
public ClientMessage receiveImmediate() throws ActiveMQException
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
public MessageHandler getMessageHandler() throws ActiveMQException
Description copied from interface:ClientConsumerReturns the MessageHandler associated to this consumer.Calling 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
public Thread getCurrentThread()
- Specified by:
getCurrentThreadin interfaceClientConsumerInternal
-
setMessageHandler
public ClientConsumerImpl setMessageHandler(MessageHandler theHandler) throws ActiveMQException
Description copied from interface:ClientConsumerSets the MessageHandler for this consumer to consume messages asynchronously.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
public void close() throws ActiveMQExceptionDescription 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
public Thread prepareForClose(FutureLatch future) throws ActiveMQException
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:ClientConsumerReturns whether the consumer is closed or not.- Specified by:
isClosedin interfaceClientConsumer- Returns:
trueif this consumer is closed,falseelse
-
stop
public void stop(boolean waitForOnMessage) throws ActiveMQException- Specified by:
stopin interfaceClientConsumerInternal- Throws:
ActiveMQException
-
clearAtFailover
public void clearAtFailover()
- Specified by:
clearAtFailoverin interfaceClientConsumerInternal
-
start
public void start()
- Specified by:
startin interfaceClientConsumerInternal
-
getLastException
public Exception getLastException()
Description copied from interface:ClientConsumerReturns the last exception thrown by a call to this consumer's MessageHandler.- Specified by:
getLastExceptionin interfaceClientConsumer- Returns:
- the last exception thrown by a call to this consumer's MessageHandler or
null
-
getQueueInfo
public ClientSession.QueueQuery getQueueInfo()
- Specified by:
getQueueInfoin interfaceClientConsumerInternal
-
getForceDeliveryCount
public long getForceDeliveryCount()
- Specified by:
getForceDeliveryCountin interfaceClientConsumerInternal
-
getFilterString
public SimpleString getFilterString()
- Specified by:
getFilterStringin interfaceClientConsumerInternal
-
getPriority
public int getPriority()
- Specified by:
getPriorityin interfaceClientConsumerInternal
-
getQueueName
public SimpleString getQueueName()
- Specified by:
getQueueNamein interfaceClientConsumerInternal
-
isBrowseOnly
public boolean isBrowseOnly()
- Specified by:
isBrowseOnlyin interfaceClientConsumerInternal
-
handleMessage
public void handleMessage(ClientMessageInternal message) throws Exception
- 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
public void clear(boolean waitForOnMessage) throws ActiveMQException- 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
public void acknowledge(ClientMessage message) throws ActiveMQException
- Specified by:
acknowledgein interfaceClientConsumerInternal- Throws:
ActiveMQException
-
individualAcknowledge
public void individualAcknowledge(ClientMessage message) throws ActiveMQException
- Specified by:
individualAcknowledgein interfaceClientConsumerInternal- Throws:
ActiveMQException
-
flushAcks
public void flushAcks() throws ActiveMQException- Specified by:
flushAcksin interfaceClientConsumerInternal- Throws:
ActiveMQException
-
flowControl
public void flowControl(int messageBytes, boolean discountSlowConsumer) throws ActiveMQExceptionLargeMessageBuffer 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
-
-