wso2-dev/andes — pull request #137 by hastef88 (2014-11-04 06:53:33+00:00)
Title: Queue Purge Feature to remove all messages not awaiting acknowledgement on a given queue.

Rationale :
-------------
According to AMQP spec 0_9_1 : Once purged, We need to remove all messages which are not awaiting acknowledgement from the given queue.

Requirements in terms of MB 3.0.0 architecture :
-------------------------------------------------------------
1. Once a queue purge is requested from UI console (queue->browse page), all messages addressed to that queue in the receiving node in memory should be cleared.
2. If in a cluster, all other nodes should be notified of the purge event including the timestamp, after which those nodes must clear their in memory messages of the given queue.
3. All messages in delivery threads will be skipped if their arrival Time is before the purged timestamp.
4. All messages of the queue in durable store should be removed (JDBC / Cassandra)
5. Any message counters for the queue in store should be reset to 0.

*Messages published to that queue immediately after a purge should still be received by the subscriber later.

Follow up tasks :
---------------------
1. When deleting message content, we have to collect the message ID list of the given queue, because MessageContent entity is not associated to queues directly. (inferring queueName from parsing metadata is expensive.) This operation will be further improved by reducing the range of query using the min messageID in slots for the given queue.

2. Support for purging topics is pending. (until topic flow is finalized)

Other fixes done when testing :
----------------------------------------
1. Handled NoSuchElementException in QueueDeliveryWorker : sendMessagesToSubscribers.
2. Handled NPE in OnFlightMessageTracker : releaseAllMessagesOfSlotFromTracking.
3. Descriptive exception handling for message delivery failures in SubscriptionImpl.
4. Added controlled thread sleeps to better handle threadpool exhaustion at QueueDeliveryWorker : sendMessageToFlusher