5.2.8. vlcp.event.pqueue¶
Note
This document is generated from the source file.
Created on 2015/06/02
author: | hubo |
---|
-
class
vlcp.event.pqueue.
AutoClassQueueCanWriteEvent
(queue, key, newonly, firstonly)¶ -
__init__
(queue, key, newonly, firstonly)¶ Parameters: - args – index values like 12,”read”,… content are type-depended.
- kwargs –
- indices
- input indices by name
- canignore
- if the event is not processed, whether it is safe to ignore the event.
If it is not, the processing queue might be blocked to wait for a proper event processor. Default to True.
- others
- the properties will be set on the created event
-
-
class
vlcp.event.pqueue.
CBQueue
(tree=None, parent=None, maxdefault=None, maxtotal=None, defaultQueueClass=<class 'vlcp.event.pqueue.CBQueue.FifoQueue'>, defaultQueuePriority=0)¶ A multi-queue model with priority and balance. When first created, there is a default queue with priority 0. More sub-queues maybe created with addSubQueue. Each sub-queue is a CBQueue which accepts more sub-queues. Sub-queues are considered as black-box to the outer parent.
-
class
AutoClassQueue
(parent=None, maxlength=None, key='owner', preserveForNew=1, maxstat=None, subqueuelimit=None)¶ A queue classify events into virtual sub-queues by key
-
__init__
(parent=None, maxlength=None, key='owner', preserveForNew=1, maxstat=None, subqueuelimit=None)¶ Each value are classified and put into virtual subqueues.
Parameters: - parent – parent queue
- maxlength – total limit for this queue
- key – classify value by this attribute
- preserveForNew – preserve some space for new subqueues. When putting values with old keys into the queue, the queue would block the value when it has size maxlength - preserveForNew. But, a value with new key (thus creates a new virtual queue) will be accepted by this queue. It makes sure a value with new key has enough priority to be enqueued.
- maxstat – Object passes each virtual queue lately are counted. When a virtual subqueue is passing less events, the priority of this queue is increased to make it fair. maxstat is the limit of objects counted
- subqueuelimit – limit of each subqueue
-
-
class
FifoQueue
(parent=None, maxlength=None)¶ A wrapper for a FIFO queue
-
__init__
(parent=None, maxlength=None)¶ Initialize self. See help(type(self)) for accurate signature.
-
-
class
MultiQueue
(parent=None, priority=0)¶ A multi-queue container, every queue in a multi-queue has the same priority, and is popped in turn.
-
class
CircleListNode
(value)¶ Circle link list
-
__init__
(value)¶ Initialize self. See help(type(self)) for accurate signature.
-
-
__init__
(parent=None, priority=0)¶ Initialize self. See help(type(self)) for accurate signature.
-
class
-
class
PriorityQueue
(parent=None, maxlength=None, key='priority')¶ A queue with inner built priority. Event must have a “priority” property to use with this type of queue. For fail-safe, events without “priority” property have the lowest priority.
NOTICE: different from the queue priority, the priority property is smaller-higher, and is not limited to integers. This allows datetime to be used as an increasing priority
-
__init__
(parent=None, maxlength=None, key='priority')¶ Initialize self. See help(type(self)) for accurate signature.
-
-
__getitem__
(name)¶ Get a sub-queue through q[‘sub-queue-name’]
-
__init__
(tree=None, parent=None, maxdefault=None, maxtotal=None, defaultQueueClass=<class 'vlcp.event.pqueue.CBQueue.FifoQueue'>, defaultQueuePriority=0)¶ Constructor
-
addSubQueue
(priority, matcher, name=None, maxdefault=None, maxtotal=None, defaultQueueClass=<class 'vlcp.event.pqueue.CBQueue.FifoQueue'>)¶ add a sub queue to current queue, with a priority and a matcher
Parameters: - priority – priority of this queue. Larger is higher, 0 is lowest.
- matcher – an event matcher to catch events. Every event match the criteria will be stored in this queue.
- name – a unique name to identify the sub-queue. If none, the queue is anonymous. It can be any hashable value.
- maxdefault – max length for default queue.
- maxtotal – max length for sub-queue total, including sub-queues of sub-queue
-
append
(event, force=False)¶ Append an event to queue. The events are classified and appended to sub-queues
Parameters: - event – input event
- force – if True, the event is appended even if the queue is full
Returns: None if appended successfully, or a matcher to match a QueueCanWriteEvent otherwise
-
block
(event, emptyEvents=())¶ Return a recently popped event to queue, and block all later events until unblock.
Only the sub-queue directly containing the event is blocked, so events in other queues may still be processed. It is illegal to call block and unblock in different queues with a same event.
Parameters: - event – the returned event. When the queue is unblocked later, this event will be popped again.
- emptyEvents – reactivate the QueueIsEmptyEvents
-
canAppend
()¶ Whether the queue is full or not. Only check the total limit. Sub-queue may still be full (even default).
Returns: False if the queue is full, True if not. If there are sub-queues, append() may still fail if the sub-queue is full.
-
canPop
()¶ Whether the queue is empty/blocked or not
Returns: False if the queue is empty or blocked, or True otherwise
-
clear
()¶ Clear all the events in this queue, including any sub-queues.
Returns: ((queueEvents,…), (queueEmptyEvents,…)) where queueEvents are QueueCanWriteEvents generated by clearing.
-
getPriority
(queue)¶ get priority of a sub-queue
-
notifyAppend
(queue, force)¶ Internal notify for sub-queues
Returns: If the append is blocked by parent, an EventMatcher is returned, None else.
-
notifyBlock
(queue, blocked)¶ Internal notify for sub-queues been blocked
-
notifyPop
(queue, length=1)¶ Internal notify for sub-queues been poped
Returns: List of any events generated by this pop
-
pop
()¶ Pop an event from the queue. The event in the queue with higher priority is popped before ones in lower priority. If there are multiple queues with the same priority, events are taken in turn from each queue. May return some queueEvents indicating that some of the queues can be written into.
Returns: (obj, (queueEvents,…), (queueEmptyEvents,…)) where obj is the popped event, queueEvents are QueueCanWriteEvents generated by this pop and queueEmptyEvents are QueueIsEmptyEvents generated by this pop
-
removeSubQueue
(queue)¶ remove a sub queue from current queue.
This unblock the sub-queue, retrieve all events from the queue and put them back to the parent.
Call clear on the sub-queue first if the events are not needed any more.
Parameters: queue – the name or queue object to remove Returns: ((queueevents,…), (queueEmptyEvents,…)) Possible queue events from removing sub-queues
-
setPriority
(queue, priority)¶ Set priority of a sub-queue
-
unblock
(event)¶ Remove a block
-
unblockall
()¶ Remove all blocks from the queue and all sub-queues
-
unblockqueue
(queue)¶ Remove blocked events from the queue and all subqueues. Usually used after queue clear/unblockall to prevent leak.
Returns: the cleared events
-
waitForEmpty
()¶ Make this queue generate a QueueIsEmptyEvent when it is empty
Returns: matcher for QueueIsEmptyEvent, or None if the queue is already empty
-
class
-
class
vlcp.event.pqueue.
QueueCanWriteEvent
(queue, **kwargs)¶ -
__init__
(queue, **kwargs)¶ Parameters: - args – index values like 12,”read”,… content are type-depended.
- kwargs –
- indices
- input indices by name
- canignore
- if the event is not processed, whether it is safe to ignore the event.
If it is not, the processing queue might be blocked to wait for a proper event processor. Default to True.
- others
- the properties will be set on the created event
-
-
class
vlcp.event.pqueue.
QueueIsEmptyEvent
(*args, **kwargs)¶