eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ActiveObject':

Home

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

Class: ActiveObject


Inheritance:

   Object
   |
   +--ActiveObject

Package:
stx:libbasic2
Category:
Kernel-Processes
Version:
rev: 1.8 date: 2023/11/21 07:32:48
user: cg
file: ActiveObject.st directory: libbasic2
module: stx stc-classLibrary: libbasic2

Description:


an active object executes incoming messages in a serialized, synchronous manner,
enqueuing incoming messages, executing them one after the other, and returning results to the caller.
Messages are synchronous: the caller is blocked while I perform my duty.
Exceptions during execution are sent back to the caller.
This is an abstract framework class, to be subclassed for real workers.

The following is a not-yet-working experiment, using lookup objects to redirect automatically into a synchronizing
method. This does not work yet.

Notice the use of the lookup object here: all incoming messages from a process other than my worker-process
itself are forwarded to the #doesNotUnderstand: method. There is no need to inherit from nil, and subclasses can use
any messages they like locally, without them being enqueued.

For now, define methods which have to be synchronized by defining them as:
    methodX
        self synchronized:[
            ...
            do something
            ...
        ]

copyright

COPYRIGHT (c) 2013 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

initialization
o  initialize
self lookupObject: RedirectingLookup new

instance creation
o  new
(comment from inherited method)
return an instance of myself without indexed variables


Instance protocol:

accessing
o  process

message handling
o  messageHandlingLoop
Transcript showCR:'A: await message...'.

o  sendAction: aBlock
arrive here, when done with message

o  sendSelector: selector arguments: arguments
Transcript showCR:'send message...'.

o  startMessageHandlingLoopProcess
must check again because of possible raise

o  synchronized: aBlock
evaluate aBlock synchronized, i.e. use a monitor for this object;
return the value from aBlock

o  synchronizedMethod
marks calling methods as being handled via the queue


Private classes:

    MessageAndResponse
    RedirectingLookup

Examples:


normally, one would subclass ActiveObject and put protocol into it; here, for the example, an anon Printer is defined. It is slow printing to the Transcript for a demo. The interesting thing is the error handling which is demonstrated in printWithError: Any exception inside the worker object is returned back and raised in the active-object's client, not in the worker (take a look at the call-chain, when running the example below).
  |workerClass worker|

  workerClass := ActiveObject 
                      subclass:#Printer
                      instanceVariableNames:''
                      classVariableNames:''
                      poolDictionaries:''
                      category:nil
                      inEnvironment:nil.

  workerClass compile:'
print:aLine
  self synchronized:[.
      aLine do:[:ch |
          Transcript show:ch.
          Delay waitForSeconds:0.2.
      ].
      Transcript cr.
  ]
'.

  workerClass compile:'
printWithError:aLine
  self synchronized:[.
      aLine do:[:ch |
          Transcript show:ch.
          ch == $l ifTrue:[ self foo ].
          Delay waitForSeconds:0.2.
      ].
      Transcript cr.
  ]
'.

  worker := workerClass new.
  'now ready for printing'.
  worker printWithError:'abcdef'.
  worker printWithError:'hello world'.


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 15:45:34 GMT