Class BasicBlockingRecordQueue<K,V>
- java.lang.Object
-
- io.streamthoughts.azkarra.api.events.BasicBlockingRecordQueue<K,V>
-
- Type Parameters:
K
- the record-key type.V
- the record-value type.
- All Implemented Interfaces:
BlockingRecordQueue<K,V>
public class BasicBlockingRecordQueue<K,V> extends Object implements BlockingRecordQueue<K,V>
A simpleBlockingRecordQueue
backed by aBlockingQueue
.- Since:
- 0.8.0
-
-
Constructor Summary
Constructors Constructor Description BasicBlockingRecordQueue()
Creates a newBasicBlockingRecordQueue
instance.BasicBlockingRecordQueue(int queueSizeLimit)
Creates a newBasicBlockingRecordQueue
instance.BasicBlockingRecordQueue(int queueSizeLimit, Duration maxBlockDuration)
Creates a newBasicBlockingRecordQueue
instance.BasicBlockingRecordQueue(int queueSizeLimit, Duration maxBlockDuration, LimitHandler limitHandler)
Creates a newBasicBlockingRecordQueue
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
void
close()
Close the queue.void
drainTo(Collection<? super KV<K,V>> collection)
boolean
isEmpty()
void
open()
Open the queue.KV<K,V>
poll()
KV<K,V>
poll(Duration timeout)
void
send(KV<K,V> record)
Sends a key-value record into this queue.void
setLimitHandler(LimitHandler limitHandler)
Sets the handler to be invoked when the limit queue is reached.void
setQueueCallback(QueueCallback callback)
Sets the callback to be executed when a new record is queued or the queue is closed.int
size()
-
-
-
Constructor Detail
-
BasicBlockingRecordQueue
public BasicBlockingRecordQueue()
Creates a newBasicBlockingRecordQueue
instance.
-
BasicBlockingRecordQueue
public BasicBlockingRecordQueue(int queueSizeLimit)
Creates a newBasicBlockingRecordQueue
instance.- Parameters:
queueSizeLimit
- the queue max capacity.
-
BasicBlockingRecordQueue
public BasicBlockingRecordQueue(int queueSizeLimit, Duration maxBlockDuration)
Creates a newBasicBlockingRecordQueue
instance.- Parameters:
queueSizeLimit
- the queue max capacity.maxBlockDuration
- the maximum duration to wait to wait before giving up, when the queue is full.
-
BasicBlockingRecordQueue
public BasicBlockingRecordQueue(int queueSizeLimit, Duration maxBlockDuration, LimitHandler limitHandler)
Creates a newBasicBlockingRecordQueue
instance.- Parameters:
queueSizeLimit
- the blocking size limit;maxBlockDuration
- the maximum duration to wait to wait before giving up, when the queue is full.limitHandler
- theLimitHandler
to invoke aftermaxBlockDuration
has been reached.
-
-
Method Detail
-
setLimitHandler
public void setLimitHandler(LimitHandler limitHandler)
Sets the handler to be invoked when the limit queue is reached.- Specified by:
setLimitHandler
in interfaceBlockingRecordQueue<K,V>
- Parameters:
limitHandler
- theLimitHandler
instance.
-
setQueueCallback
public void setQueueCallback(QueueCallback callback)
Sets the callback to be executed when a new record is queued or the queue is closed.- Specified by:
setQueueCallback
in interfaceBlockingRecordQueue<K,V>
- Parameters:
callback
- theQueueCallback
to execute.
-
poll
public KV<K,V> poll(Duration timeout) throws InterruptedException
- Specified by:
poll
in interfaceBlockingRecordQueue<K,V>
- Throws:
InterruptedException
- See Also:
BlockingQueue.poll(long, TimeUnit)
-
poll
public KV<K,V> poll()
- Specified by:
poll
in interfaceBlockingRecordQueue<K,V>
- See Also:
Queue.poll()
-
drainTo
public void drainTo(Collection<? super KV<K,V>> collection)
- Specified by:
drainTo
in interfaceBlockingRecordQueue<K,V>
- See Also:
BlockingQueue.drainTo(Collection)
-
size
public int size()
- Specified by:
size
in interfaceBlockingRecordQueue<K,V>
- Returns:
- the number of records queued.
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceBlockingRecordQueue<K,V>
- Returns:
true
if the queue is empty.
-
open
public void open()
Open the queue.- Specified by:
open
in interfaceBlockingRecordQueue<K,V>
-
close
public void close()
Close the queue. The records sent after the queue is closed will be ignored.- Specified by:
close
in interfaceBlockingRecordQueue<K,V>
-
send
public void send(KV<K,V> record)
Sends a key-value record into this queue.- Specified by:
send
in interfaceBlockingRecordQueue<K,V>
- Parameters:
record
- theKV
record.
-
clear
public void clear()
- Specified by:
clear
in interfaceBlockingRecordQueue<K,V>
- See Also:
Collection.clear()
-
-