eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Registry':

Home

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

Class: Registry


Inheritance:

   Object
   |
   +--Collection
      |
      +--Set
         |
         +--Dictionary
            |
            +--IdentityDictionary
               |
               +--WeakIdentityDictionary
                  |
                  +--Registry
                     |
                     +--CachingRegistry
                     |
                     +--HandleRegistry

Package:
stx:libbasic
Category:
Collections-Weak
Version:
rev: 1.72 date: 2016/11/18 15:24:51
user: stefan
file: Registry.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Claus Gittinger

Description:


Registries provide an easy interface to using WeakArrays.
A class, which wants to be informed of instance-death, can put a created object
into a registry. The registry will create an executor, which is a (shallow-)copy
of the object, and watch out for death of the original object. When it dies,
the executor will be sent a #finalize message.
The trick with the shallow copy is especially nice, you can think of it as
being the original object which died.

All objects, which keep external resources (such as fileDescriptors, fonts,
colormap-entries etc.) should be registered, so that the underlying resource
can be freed when the object goes away.

Of course, you too can use it to do whatever you need to do in case of the
death of an object.

Registries use #executor to acquire the copy of the original,
this can be redefined in individual classes for faster copying
(typically, not all internal state, but only some device handles are needed for
finalization). If the to-be-registered object is large, this method may also
return a stub (placeHolder) object. (i.e. there is no need for the copy to be
of the same class as the original, as long as it implements #finalize and frees
the relevant OS resources. Some classes return a specialized private-class instance,
which only holds on the handle and implements #finalize.)
Example uses are found in Form, Color, ExternalStream and Font


Related information:

    WeakArray
    WeakIdentityDictionary
    Font
    Form
    Color
    Cursor
    ExternalStream

Instance protocol:

accessing
o  contents
return the collection of registered objects

element disposal
o  clearDeadSlots
have to block here - dispose may be done at a low priority
from the background finalizer. If new items are added by a
higher prio process, the dictionary might get corrupted otherwise

o  informDispose: someHandle
send a dispose message - this is sent to the executor,
since the original is already gone

o  update: something with: aParameter from: changedObject
an instance has been destroyed - look which one it was

enumerating
o  detect: aBlock ifNone: exceptionValue
detect a key, for which aBlock answers true

o  do: aBlock
evaluate aBlock for each registered object

private
o  findKeyOrNil: key
Look for the key in the receiver.
If it is found, return the index,
otherwise the index of the first unused slot.
Grow the receiver, if key was not found, and no unused slots were present.

Warning: an empty slot MUST be filled by the sender - it is only to be sent
by at:put: / add: - like methods.

Redefined to not nil values of expired keys here.

o  findKeyOrNilOrDeletedEntry: key
Look for the key in the receiver.
If it is found, return the index,
otherwise the index of the first unused slot.
Grow the receiver, if key was not found, and no unused slots were present.

Redefined to not nil values of expired keys here.

registering objects
o  register: anObject
register anObject, so that a copy of it gets the disposed message
when anObject dies (some time in the future)

o  register: anObject as: aHandle
register anObject, so that I later receive informDispose: with aHandle
(some time in the future)

o  registerChange: anObject
a registered object has changed, create a new executor

o  unregister: anObject
remove registration of anObject, without telling the executor;
should be sent, if we are no more interested in destruction of
anObject (i.e. it no longer holds external resources).

o  unregisterAllForWhich: aBlock
remove registration of all entries, for which the argument block
evaluates to true.
should be sent, if we are no more interested in destruction of
a group of objects (i.e. it no longer holds external resources).

o  unregisterAllForWhichHandle: aBlock
remove registration of all handles, for which the argument block
evaluates to true.
should be sent, if we are no more interested in destruction of
a group of objects (i.e. it no longer holds external resources).



ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Thu, 25 Apr 2024 08:34:29 GMT