eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'BackgroundQueueProcessingJob':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: BackgroundQueueProcessingJob


Inheritance:

   Object
   |
   +--AbstractBackgroundJob
      |
      +--BackgroundQueueProcessingJob

Package:
stx:libbasic2
Category:
System-Support
Version:
rev: 1.22 date: 2017/08/09 12:15:27
user: cg
file: BackgroundQueueProcessingJob.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Jan Vrany <jan.vrany@fit.cvut.cz>

Description:


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:]


Related information:

    BackgroundJob

Instance protocol:

adding & removing
o  add: object

o  add: object at: index
Modified (format): / 03-08-2011 / 16:43:01 / cg

initialization
o  initialize
Invoked when a new instance is created.

private
o  setupThread: t priority: p
Sets up worker thread

processing
o  process
(comment from inherited method)
Actually perform the job. This method is called from the background worker thread

o  processItem: item

queries
o  numberOfItemsInQueue
Returns number of items waiting to be processed.
May not be accurate as there is no synchronization
(intentionally, for performance reasons)

start & stop
o  stopAndRemoveAll
Terminates queue processing and remove all pending
items in a queue

utilities
o  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.


Examples:


| 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'.

ST/X 7.1.0.0; WebServer 1.663 at exept.de:8081; Sat, 17 Nov 2018 21:51:30 GMT