Class ServerConsumerImpl
- java.lang.Object
-
- org.apache.activemq.artemis.core.server.impl.ServerConsumerImpl
-
- All Implemented Interfaces:
PriorityAware,Consumer,ConsumerInfo,ServerConsumer,ReadyListener
public class ServerConsumerImpl extends Object implements ServerConsumer, ReadyListener
Concrete implementation of a ClientConsumer.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classServerConsumerImpl.BrowserDeliverer
-
Field Summary
Fields Modifier and Type Field Description protected ServerConsumerImpl.BrowserDelivererbrowserDelivererprotected Objectlockprotected QueuemessageQueue
-
Constructor Summary
Constructors Constructor Description ServerConsumerImpl(long id, ServerSession session, QueueBinding binding, Filter filter, boolean started, boolean browseOnly, StorageManager storageManager, SessionCallback callback, boolean preAcknowledge, boolean strictUpdateDeliveryCount, ManagementService managementService, boolean supportLargeMessage, Integer credits, ActiveMQServer server)ServerConsumerImpl(long id, ServerSession session, QueueBinding binding, Filter filter, boolean started, boolean browseOnly, StorageManager storageManager, SessionCallback callback, boolean preAcknowledge, boolean strictUpdateDeliveryCount, ManagementService managementService, ActiveMQServer server)ServerConsumerImpl(long id, ServerSession session, QueueBinding binding, Filter filter, int priority, boolean started, boolean browseOnly, StorageManager storageManager, SessionCallback callback, boolean preAcknowledge, boolean strictUpdateDeliveryCount, ManagementService managementService, boolean supportLargeMessage, Integer credits, ActiveMQServer server)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<Long>acknowledge(Transaction tx, long messageID)booleanallowReferenceCallback()the current queue settings will allow use of the Reference Execution and callback.voidbackToDelivering(MessageReference reference)Some protocols may choose to send the message back to delivering instead of redeliver.List<MessageReference>cancelRefs(boolean failed, boolean lastConsumedAsDelivered, Transaction tx)voidclose(boolean failed)Stringdebug()voiddisconnect()disconnect the consumervoiderrorProcessing(Throwable e, MessageReference deliveryObject)voidfireSlowConsumer()voidforceDelivery(long sequence)Prompt delivery and send a "forced delivery" message to the consumer.voidforceDelivery(long sequence, Runnable r)AtomicIntegergetAvailableCredits()To be used on tests onlyBindinggetBinding()SessionCallbackgetCallback()StringgetConnectionClientID()StringgetConnectionID()StringgetConnectionLocalAddress()Returns a string representation of the local address this connection is connected to.StringgetConnectionProtocolName()Returns the name of the protocol for this Remoting ConnectionStringgetConnectionRemoteAddress()Returns a string representation of the remote address this connection is connected to.longgetCreationTime()List<MessageReference>getDeliveringMessages()FiltergetFilter()SimpleStringgetFilterString()longgetID()intgetPriority()ObjectgetProtocolContext()An object set by the Protocol implementation.ObjectgetProtocolData()this is to be used with anything specific on a protocol head.QueuegetQueue()SimpleStringgetQueueAddress()SimpleStringgetQueueName()RoutingTypegetQueueType()floatgetRate()longgetSequentialID()an unique sequential ID for this consumerStringgetSessionID()StringgetSessionName()SlowConsumerDetectionListenergetSlowConsumerDetecion()HandleStatushandle(MessageReference ref)There was a change on semantic during 2.3 here.
We now first accept the message, and the actual deliver is done as part ofConsumer.proceedDeliver(MessageReference).voidindividualAcknowledge(Transaction tx, long messageID)voidindividualCancel(long messageID, boolean failed)booleanisBrowseOnly()voidproceedDeliver(MessageReference reference)This will proceed with the actual delivery.voidpromptDelivery()wakes up internal threads to deliver more messagesvoidreadyForWriting()voidreceiveCredits(int credits)voidreject(long messageID)voidremoveItself()This method is just to remove itself from Queues.MessageReferenceremoveReferenceByID(long messageID)List<MessageReference>scanDeliveringReferences(boolean remove, Function<MessageReference,Boolean> startFunction, Function<MessageReference,Boolean> endFunction)Remove references based on the protocolData.longsequentialID()an unique sequential ID for this consumervoidsetlowConsumerDetection(SlowConsumerDetectionListener listener)voidsetPreAcknowledge(boolean preAcknowledge)voidsetProtocolContext(Object protocolContext)voidsetProtocolData(Object protocolData)this is to be used with anything specific on a protocol head.voidsetStarted(boolean started)voidsetTransferring(boolean transferring)booleansupportsDirectDelivery()iStringtoManagementString()This method will create a string representation meant for management operations.StringtoString()protected voidupdateDeliveryCountForCanceledRef(MessageReference ref, boolean failed)
-
-
-
Field Detail
-
messageQueue
protected final Queue messageQueue
-
lock
protected final Object lock
-
browserDeliverer
protected ServerConsumerImpl.BrowserDeliverer browserDeliverer
-
-
Constructor Detail
-
ServerConsumerImpl
public ServerConsumerImpl(long id, ServerSession session, QueueBinding binding, Filter filter, boolean started, boolean browseOnly, StorageManager storageManager, SessionCallback callback, boolean preAcknowledge, boolean strictUpdateDeliveryCount, ManagementService managementService, ActiveMQServer server) throws Exception- Throws:
Exception
-
ServerConsumerImpl
public ServerConsumerImpl(long id, ServerSession session, QueueBinding binding, Filter filter, boolean started, boolean browseOnly, StorageManager storageManager, SessionCallback callback, boolean preAcknowledge, boolean strictUpdateDeliveryCount, ManagementService managementService, boolean supportLargeMessage, Integer credits, ActiveMQServer server) throws Exception- Throws:
Exception
-
ServerConsumerImpl
public ServerConsumerImpl(long id, ServerSession session, QueueBinding binding, Filter filter, int priority, boolean started, boolean browseOnly, StorageManager storageManager, SessionCallback callback, boolean preAcknowledge, boolean strictUpdateDeliveryCount, ManagementService managementService, boolean supportLargeMessage, Integer credits, ActiveMQServer server) throws Exception- Throws:
Exception
-
-
Method Detail
-
readyForWriting
public void readyForWriting()
- Specified by:
readyForWritingin interfaceReadyListener
-
allowReferenceCallback
public boolean allowReferenceCallback()
Description copied from interface:ServerConsumerthe current queue settings will allow use of the Reference Execution and callback. This is because- Specified by:
allowReferenceCallbackin interfaceServerConsumer
-
sequentialID
public long sequentialID()
Description copied from interface:Consumeran unique sequential ID for this consumer- Specified by:
sequentialIDin interfaceConsumer
-
getProtocolData
public Object getProtocolData()
Description copied from interface:ServerConsumerthis is to be used with anything specific on a protocol head.- Specified by:
getProtocolDatain interfaceServerConsumer
-
setProtocolData
public void setProtocolData(Object protocolData)
Description copied from interface:ServerConsumerthis is to be used with anything specific on a protocol head.- Specified by:
setProtocolDatain interfaceServerConsumer
-
setlowConsumerDetection
public void setlowConsumerDetection(SlowConsumerDetectionListener listener)
- Specified by:
setlowConsumerDetectionin interfaceServerConsumer
-
getSlowConsumerDetecion
public SlowConsumerDetectionListener getSlowConsumerDetecion()
- Specified by:
getSlowConsumerDetecionin interfaceServerConsumer
-
fireSlowConsumer
public void fireSlowConsumer()
- Specified by:
fireSlowConsumerin interfaceServerConsumer
-
getProtocolContext
public Object getProtocolContext()
Description copied from interface:ServerConsumerAn object set by the Protocol implementation. it could be anything pre-determined by the implementation- Specified by:
getProtocolContextin interfaceServerConsumer
-
setProtocolContext
public void setProtocolContext(Object protocolContext)
- Specified by:
setProtocolContextin interfaceServerConsumer- See Also:
ServerConsumer.getProtocolContext()
-
getID
public long getID()
- Specified by:
getIDin interfaceServerConsumer
-
isBrowseOnly
public boolean isBrowseOnly()
- Specified by:
isBrowseOnlyin interfaceServerConsumer
-
getCreationTime
public long getCreationTime()
- Specified by:
getCreationTimein interfaceServerConsumer
-
getConnectionID
public String getConnectionID()
- Specified by:
getConnectionIDin interfaceServerConsumer
-
getSessionID
public String getSessionID()
- Specified by:
getSessionIDin interfaceServerConsumer
-
getDeliveringMessages
public List<MessageReference> getDeliveringMessages()
- Specified by:
getDeliveringMessagesin interfaceConsumer- Returns:
- the list of messages being delivered
-
supportsDirectDelivery
public boolean supportsDirectDelivery()
i- Specified by:
supportsDirectDeliveryin interfaceConsumer- See Also:
SessionCallback.supportsDirectDelivery()
-
errorProcessing
public void errorProcessing(Throwable e, MessageReference deliveryObject)
- Specified by:
errorProcessingin interfaceConsumer
-
handle
public HandleStatus handle(MessageReference ref) throws Exception
Description copied from interface:ConsumerThere was a change on semantic during 2.3 here.
We now first accept the message, and the actual deliver is done as part ofConsumer.proceedDeliver(MessageReference). This is to avoid holding a lock on the queues while the delivery is being accomplished To avoid a lock on the queue in case of misbehaving consumers.This should return busy if handle is called before proceed deliver is called
-
proceedDeliver
public void proceedDeliver(MessageReference reference) throws Exception
Description copied from interface:ConsumerThis will proceed with the actual delivery. Notice that handle should hold a readLock and proceedDelivery should release the readLock any lock operation on Consumer should also get a writeLock on the readWriteLock to guarantee there are no pending deliveries- Specified by:
proceedDeliverin interfaceConsumer- Throws:
Exception
-
getBinding
public Binding getBinding()
- Specified by:
getBindingin interfaceConsumer
-
getPriority
public int getPriority()
- Specified by:
getPriorityin interfaceConsumer- Specified by:
getPriorityin interfacePriorityAware
-
getFilterString
public SimpleString getFilterString()
- Specified by:
getFilterStringin interfaceConsumerInfo
-
close
public void close(boolean failed) throws Exception- Specified by:
closein interfaceServerConsumer- Throws:
Exception
-
removeItself
public void removeItself() throws ExceptionDescription copied from interface:ServerConsumerThis method is just to remove itself from Queues. If for any reason during a close an exception occurred, the exception treatment will call removeItself what should take the consumer out of any queues.- Specified by:
removeItselfin interfaceServerConsumer- Throws:
Exception
-
forceDelivery
public void forceDelivery(long sequence)
Prompt delivery and send a "forced delivery" message to the consumer.When the consumer receives such a "forced delivery" message, it discards it and knows that there are no other messages to be delivered.
- Specified by:
forceDeliveryin interfaceServerConsumer
-
forceDelivery
public void forceDelivery(long sequence, Runnable r)
-
cancelRefs
public List<MessageReference> cancelRefs(boolean failed, boolean lastConsumedAsDelivered, Transaction tx) throws Exception
- Specified by:
cancelRefsin interfaceServerConsumer- Throws:
Exception
-
updateDeliveryCountForCanceledRef
protected void updateDeliveryCountForCanceledRef(MessageReference ref, boolean failed)
-
setStarted
public void setStarted(boolean started)
- Specified by:
setStartedin interfaceServerConsumer
-
setTransferring
public void setTransferring(boolean transferring)
- Specified by:
setTransferringin interfaceServerConsumer
-
receiveCredits
public void receiveCredits(int credits)
- Specified by:
receiveCreditsin interfaceServerConsumer
-
getQueue
public Queue getQueue()
- Specified by:
getQueuein interfaceServerConsumer
-
scanDeliveringReferences
public List<MessageReference> scanDeliveringReferences(boolean remove, Function<MessageReference,Boolean> startFunction, Function<MessageReference,Boolean> endFunction)
Remove references based on the protocolData. there will be an interval defined between protocolDataStart and protocolDataEnd. This method will fetch the delivering references, remove them from the delivering list and return a list. This will be useful for other protocols that will need this such as openWire or MQTT.- Specified by:
scanDeliveringReferencesin interfaceServerConsumer
-
acknowledge
public List<Long> acknowledge(Transaction tx, long messageID) throws Exception
- Specified by:
acknowledgein interfaceServerConsumer- Throws:
Exception
-
individualAcknowledge
public void individualAcknowledge(Transaction tx, long messageID) throws Exception
- Specified by:
individualAcknowledgein interfaceServerConsumer- Throws:
Exception
-
individualCancel
public void individualCancel(long messageID, boolean failed) throws Exception- Specified by:
individualCancelin interfaceServerConsumer- Throws:
Exception
-
reject
public void reject(long messageID) throws Exception- Specified by:
rejectin interfaceServerConsumer- Throws:
Exception
-
backToDelivering
public void backToDelivering(MessageReference reference)
Description copied from interface:ServerConsumerSome protocols may choose to send the message back to delivering instead of redeliver. For example openwire will redeliver through the client, so messages will go back to delivering list after rollback.- Specified by:
backToDeliveringin interfaceServerConsumer
-
removeReferenceByID
public MessageReference removeReferenceByID(long messageID) throws Exception
- Specified by:
removeReferenceByIDin interfaceServerConsumer- Throws:
Exception
-
getAvailableCredits
public AtomicInteger getAvailableCredits()
To be used on tests only
-
toManagementString
public String toManagementString()
Description copied from interface:ConsumerThis method will create a string representation meant for management operations. This is different from the toString method that's meant for debugging and will contain information that regular users won't understand well- Specified by:
toManagementStringin interfaceConsumer- Returns:
-
disconnect
public void disconnect()
Description copied from interface:Consumerdisconnect the consumer- Specified by:
disconnectin interfaceConsumer
-
getRate
public float getRate()
-
promptDelivery
public void promptDelivery()
Description copied from interface:Consumerwakes up internal threads to deliver more messages- Specified by:
promptDeliveryin interfaceConsumer
-
setPreAcknowledge
public void setPreAcknowledge(boolean preAcknowledge)
-
getSequentialID
public long getSequentialID()
Description copied from interface:ConsumerInfoan unique sequential ID for this consumer- Specified by:
getSequentialIDin interfaceConsumerInfo
-
getQueueName
public SimpleString getQueueName()
- Specified by:
getQueueNamein interfaceConsumerInfo- Returns:
- name of the queue that is being consumed
-
getQueueType
public RoutingType getQueueType()
- Specified by:
getQueueTypein interfaceConsumerInfo- Returns:
- routing type of the queue that is being consumed
-
getQueueAddress
public SimpleString getQueueAddress()
- Specified by:
getQueueAddressin interfaceConsumerInfo- Returns:
- address of the queue that is being consumed
-
getSessionName
public String getSessionName()
- Specified by:
getSessionNamein interfaceConsumerInfo
-
getConnectionClientID
public String getConnectionClientID()
- Specified by:
getConnectionClientIDin interfaceConsumerInfo
-
getConnectionProtocolName
public String getConnectionProtocolName()
Description copied from interface:ConsumerInfoReturns the name of the protocol for this Remoting Connection- Specified by:
getConnectionProtocolNamein interfaceConsumerInfo- Returns:
- the name of protocol
-
getConnectionLocalAddress
public String getConnectionLocalAddress()
Description copied from interface:ConsumerInfoReturns a string representation of the local address this connection is connected to. This is useful when the server is configured at 0.0.0.0 (or multiple IPs). This will give you the actual IP that's being used.- Specified by:
getConnectionLocalAddressin interfaceConsumerInfo- Returns:
- the local address
-
getConnectionRemoteAddress
public String getConnectionRemoteAddress()
Description copied from interface:ConsumerInfoReturns a string representation of the remote address this connection is connected to.- Specified by:
getConnectionRemoteAddressin interfaceConsumerInfo- Returns:
- the remote address
-
getCallback
public SessionCallback getCallback()
-
-