|
Class: BackgroundQueueProcessingJob
Object
|
+--AbstractBackgroundJob
|
+--BackgroundQueueProcessingJob
- Package:
- stx:libbasic2
- Category:
- System-Support-JobQueue
- Version:
- rev:
1.24
date: 2022/03/17 06:59:58
- user: cg
- file: BackgroundQueueProcessingJob.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
A BackgroundQueueProcessingJob is a specialized form
of a BackgroundJob for background processing of a queue.
Each item in the queue (added by sending #add: item)
is processed (using the instance variable job).
Implementation notes:
The thread is running only if there is at least one item
to process. When the queue is empty, the thread teminates.
It is started again when a new item is added to the queue.
[instance variables:]
queue <OrderedCollection> the queue of items to be procesed
queueAccessLock<RecursionLock> a lock used to synchronize
access to the queue
queueProcessedSema<Semaphore> a semaphore signaled when the queue is
processed (and therefore empty).
[class variables:]
copyrightCOPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
All Rights Reserved
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
adding & removing
-
add: object
-
-
add: object at: index
-
Modified (format): / 03-08-2011 / 16:43:01 / cg
initialization
-
initialize
-
Invoked when a new instance is created.
private
-
setupThread: t priority: p
-
Sets up worker thread
processing
-
process
-
(comment from inherited method)
Actually perform the job. This method is called from the background worker thread
-
processItem: item
-
queries
-
numberOfItemsInQueue
-
Returns number of items waiting to be processed.
May not be accurate as there is no synchronization
(intentionally, for performance reasons)
start & stop
-
stopAndRemoveAll
-
Terminates queue processing and remove all pending
items in a queue
utilities
-
waitUntilProcessed
-
Blocks the receiver until all items from the queue are processed.
NOTE, that it may block forever if another thread is filling queue
fast enough.
| job text |
job := BackgroundQueueProcessingJob named: 'example job' on:[:text|
Delay waitForSeconds: 3.
Transcript showCR:'One guy said: ', text
].
job add:'Hello world'.
Delay waitForSeconds: 5.
job add:'Ahoj Svete!'.
job restart.
Delay waitForSeconds: 1.
job add:'Haya, looks like proper queue, you should see all greetings'.
|