Package com.gigaspaces.events.fifo
Class BlockedOrderedQueue
java.lang.Object
com.gigaspaces.events.fifo.BlockedOrderedQueue
BlockedOrderedQueue is a concurrent ordered queue that can deliver unordered events to a client
in a FIFO order (using the event sequence number) the client is notified using a thread from the
proxy's thread pool.
the event dispensing / consumption algorithm is as follows:
on ready event arrival: 1. push Msg to ready Queue 2. tryNotifyPooll()
event onNotifyPool() // Task was added to pool 1. pop ready event from Queue 2. if event not null
process event 3. if Queue not empty notifyPool() and exit // flag stays marked 4. set(flag,
false) 5. if Queue not empty tryNotifyPool() // need to remark flag
procedure tryNotifyPool() 1. CAS(flag,true) 2. if success notifyPool()
procedure notifyPool() 1. Add Task(Queue) // this task can be saved with Queue and reuse
- Since:
- 5.0
- Version:
- 1.0
- Author:
- asy
-
Constructor Summary
ConstructorsConstructorDescriptionBlockedOrderedQueue(RemoteEventListener listener, ExecutorService threadPool, long maxCapacity, NotifyInfo info) Constructor -
Method Summary
Modifier and TypeMethodDescriptiondequeue()Remove and return the next event in queue.voidenqueue(RemoteEvent theEvent) Add new event object to the queue.voidThis method interrupts all blocked threads awaiting on enqueue.voidsetInitialSeqNumbers(Map<Uuid, Long> initialSeqNumbers)
-
Constructor Details
-
BlockedOrderedQueue
public BlockedOrderedQueue(RemoteEventListener listener, ExecutorService threadPool, long maxCapacity, NotifyInfo info) Constructor- Parameters:
maxCapacity- the maximum capacity of the queue
-
-
Method Details
-
enqueue
Add new event object to the queue. The operation will block if - the queue exceeded its maximum capacity and event sequence number exceeded the maximum sequence number in queue,- Parameters:
theEvent- the event to be enqueued
-
dequeue
Remove and return the next event in queue. If the queue is empty the method will block until an event arrives Note: This method is not concurrent and must be called from one thread only.- Returns:
- the removed event
-
interrupt
public void interrupt()This method interrupts all blocked threads awaiting on enqueue. This is usually called when the Queue is no longer needed and should be discarded. -
setInitialSeqNumbers
- Parameters:
initialSeqNumbers- the initialSeqNumbers to set
-