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-JobQueue
Version:
rev: 1.24 date: 2022/03/17 06:59:58
user: cg
file: BackgroundQueueProcessingJob.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

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

copyright

COPYRIGHT (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.

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.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Mon, 18 Nov 2024 05:49:52 GMT