ActiveObject.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5392 3f9ffab35f84
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5010
d1e8ce4f966c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4300
diff changeset
     1
"{ Encoding: utf8 }"
d1e8ce4f966c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4300
diff changeset
     2
2886
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 2013 by eXept Software AG
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
              All Rights Reserved
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
4300
9d3c61b5d387 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
    16
"{ NameSpace: Smalltalk }"
9d3c61b5d387 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
    17
2886
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
Object subclass:#ActiveObject
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	instanceVariableNames:'process messageQueue'
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	classVariableNames:'AccessLock'
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	poolDictionaries:''
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	category:'Kernel-Processes'
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
Message subclass:#MessageAndResponse
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
	instanceVariableNames:'action ok result exception ready'
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
	classVariableNames:''
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
	poolDictionaries:''
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
	privateIn:ActiveObject
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
Lookup subclass:#RedirectingLookup
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
	instanceVariableNames:''
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
	classVariableNames:'Instance'
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
	poolDictionaries:''
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
	privateIn:ActiveObject
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
!ActiveObject class methodsFor:'documentation'!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
copyright
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
 COPYRIGHT (c) 2013 by eXept Software AG
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
              All Rights Reserved
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
 This software is furnished under a license and may be used
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
 only in accordance with the terms of that license and with the
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
 inclusion of the above copyright notice.   This software may not
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
 be provided or otherwise made available to, or used by, any
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
 other person.  No title to or ownership of the software is
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
 hereby transferred.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
documentation
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    an active object executes incoming messages in a serialized, synchronous manner,
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
    enqueuing incoming messages, executing them one after the other, and returning results to the caller.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
    Messages are synchronous: the caller is blocked while I perform my duty.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    Exceptions during execution are sent back to the caller.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    This is an abstract framework class, to be subclassed for real workers.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
5392
3f9ffab35f84 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5030
diff changeset
    63
    The following is a not-yet-working experiment, using lookup objects to redirect automatically into a synchronizing
2886
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    method. This does not work yet.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
    Notice the use of the lookup object here: all incoming messages from a process other than my worker-process
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
    itself are forwarded to the #doesNotUnderstand: method. There is no need to inherit from nil, and subclasses can use
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
    any messages they like locally, without them being enqueued.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
    For now, define methods which have to be synchronized by defining them as:
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
        methodX
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
            self synchronized:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
                ...
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
                do something
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
                ...
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
            ]
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
    [Author:]
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
        Claus Gittinger
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
examples
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
  normally, one would subclass ActiveObject and put protocol into it;
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
  here, for the example, an anon Printer is defined. It is slow printing to the Transcript for a demo.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
  The interesting thing is the error handling which is demonstrated in printWithError:
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
  Any exception inside the worker object is returned back and raised in the active-object's client,
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
  not in the worker (take a look at the call-chain, when running the example below).
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
5030
8f13987273e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5010
diff changeset
    91
                                                                                [exBegin]
2886
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    |workerClass worker|
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
    workerClass := ActiveObject 
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
                        subclass:#Printer
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
                        instanceVariableNames:''
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
                        classVariableNames:''
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
                        poolDictionaries:''
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
                        category:nil
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
                        inEnvironment:nil.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
    workerClass compile:'
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
print:aLine
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    self synchronized:[.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
        aLine do:[:ch |
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
            Transcript show:ch.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
            Delay waitForSeconds:0.2.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
        ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
        Transcript cr.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    ]
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
'.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    workerClass compile:'
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
printWithError:aLine
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
    self synchronized:[.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
        aLine do:[:ch |
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
            Transcript show:ch.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
            ch == $l ifTrue:[ self foo ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
            Delay waitForSeconds:0.2.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
        ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
        Transcript cr.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
    ]
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
'.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
    worker := workerClass new.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
    'now ready for printing'.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    worker printWithError:'abcdef'.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
    worker printWithError:'hello world'.
5030
8f13987273e8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5010
diff changeset
   129
                                                                                [exEnd]
2886
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
! !
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
!ActiveObject class methodsFor:'initialization'!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
initialize
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
    AccessLock := Semaphore forMutualExclusion.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
    "/ self lookupObject: RedirectingLookup new
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
    self lookupObject: nil
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
! !
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
!ActiveObject class methodsFor:'instance creation'!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
new
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
    |newObject|
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
    newObject := self basicNew initialize.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
    ^  newObject.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
! !
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
!ActiveObject methodsFor:'accessing'!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
process
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
    ^ process
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
! !
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
!ActiveObject methodsFor:'message handling'!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
messageHandlingLoop
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
    |here|
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
    [ true ] whileTrue:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
        |paket|
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
        "/ Transcript showCR:'A: await message...'.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
        (messageQueue readWaitWithTimeoutMs:30000) ifTrue:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   167
            "/ inactive for 30 seconds - exit
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   168
            AccessLock critical:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   169
                messageQueue isEmpty ifTrue:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
                    "/ Transcript showCR:'A: inactive - stop worker'.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
                    process := nil.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
                    messageQueue := nil.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
                ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
            ].
4300
9d3c61b5d387 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
   175
            "exit the worker process loop"
9d3c61b5d387 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
   176
            ^ self
2886
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
        ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   178
        
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   179
        paket := messageQueue next.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   180
        "/ Transcript showCR:'A: got message: ', paket selector.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
        Exception handle:[:ex |
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
             |ex2 c c2|
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
             "create a copy of the sender chain, up to this frame here
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
              (cannot pass the original exception chain, because that one will be unwound, 
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
               thereby clearing the senders)"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
             ex2 := ex shallowCopy.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
             c := ex2 suspendedContext.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   190
             c2 := c shallowCopy.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
             ex2 suspendedContext: c2.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
             [ c sender ~~ here ] whileTrue:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
                c2 setSender:(c sender shallowCopy).
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
                c2 := c2 sender.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
                c := c sender
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
             ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
             paket ok: false.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
             paket exception: ex2.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
        ] do:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
            |rslt|
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
            here := thisContext.    
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
            rslt := paket action value. "<- here, an exception may occur"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
            paket ok: true.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
            paket result:rslt.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
        ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
        "/ Transcript showCR:'send reply.'.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
        paket ready signal
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
    ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
sendAction: aBlock
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
    |paket sema k|
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
    process isNil ifTrue:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
        AccessLock critical:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
            process isNil ifTrue:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
                "/ Transcript showCR:'starting worker thread'.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
                messageQueue := SharedQueue new.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
                process := [
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
                                [
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
                                    self messageHandlingLoop
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
                                ] ensure:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
                                    process := nil
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
                                ]
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
                           ] fork.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
            ]
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
        ]
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
    ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
    paket := MessageAndResponse new.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
    paket action: aBlock.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
    paket ready: (sema := Semaphore new).
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
    messageQueue nextPut: paket.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
    sema wait.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
    "arrive here, when done with message"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
    paket ok ifTrue:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
        ^ paket result
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
    ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    "/ exception
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
    "/ patch the sender chain by tacking my calling chain to the end of the exception chain (from the worker), 
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
    "/ so the debugger shows a picture as if the error happened here
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
    k := paket exception suspendedContext.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
    [ k sender notNil ] whileTrue:[ k := k sender ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
    k setSender: thisContext sender sender.  "/ hide sendAction and synchronized frames
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
    paket exception doRaise. "/ reraise, now in my context
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
sendSelector: selector arguments: arguments
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
    |paket sema|
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
    process isNil ifTrue:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
        AccessLock critical:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
            process isNil ifTrue:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
                "/ Transcript showCR:'starting worker thread'.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
                messageQueue := SharedQueue new.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
                process := [
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
                                [
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
                                    self messageHandlingLoop
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
                                ] ensure:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
                                    process := nil
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
                                ]
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
                           ] fork.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
            ]
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
        ]
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
    ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
    paket := MessageAndResponse new.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   272
    paket selector: selector.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
    paket arguments: arguments.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
    paket ready: (sema := Semaphore new).
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
    "/ Transcript showCR:'send message...'.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
    messageQueue nextPut: paket.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
    sema wait.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
    "/ Transcript showCR:'got reply...'.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
    "arrive here, when done with message"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
    paket ok ifTrue:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
        ^ paket result
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
    ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
    "/ exception
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
    paket exception raiseSignal. "/ reraise, now in my context
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
synchronized:aBlock
5010
d1e8ce4f966c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4300
diff changeset
   288
    "evaluate aBlock synchronized, i.e. use a monitor for this object;
d1e8ce4f966c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4300
diff changeset
   289
     return the value from aBlock"
d1e8ce4f966c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4300
diff changeset
   290
2886
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   291
    Processor activeProcess == process ifTrue:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   292
        ^ aBlock value
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   293
    ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   294
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   295
    ^ self sendAction:aBlock.
5010
d1e8ce4f966c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4300
diff changeset
   296
d1e8ce4f966c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4300
diff changeset
   297
    "Modified (comment): / 07-06-2019 / 13:51:28 / Claus Gittinger"
2886
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
synchronizedMethod
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   301
    "marks calling methods as being handled via the queue"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   302
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   303
    |retVal|
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   304
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   305
    Processor activeProcess == process ifTrue:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
        ^ self
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
    ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
    retVal := self sendSelector:(thisContext sender selector) arguments:(thisContext sender args).
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   310
    thisContext sender return:retVal.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   311
! !
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   312
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   313
!ActiveObject::MessageAndResponse methodsFor:'accessing'!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   314
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   315
action
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   316
    ^ action
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   317
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   318
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   319
action:something
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
    action := something.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
exception
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
    ^ exception
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
exception:something
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
    exception := something.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
ok
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
    ^ ok
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
ok:something
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
    ok := something.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
ready
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
    ^ ready
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
ready:something
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
    ready := something.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   345
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   346
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   347
result
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   348
    ^ result
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   349
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   350
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   351
result:something
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   352
    result := something.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   353
! !
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   354
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   355
!ActiveObject::RedirectingLookup class methodsFor:'instance creation'!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   357
new
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   358
    Instance isNil ifTrue: [Instance := self basicNew].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   359
    ^ Instance
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
! !
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
!ActiveObject::RedirectingLookup methodsFor:'lookup'!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   364
lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   365
    "redircet everything into the receiver's doesNotUnderstand method"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
Transcript show:'l '; showCR:aReceiver class name.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   368
    (aReceiver isNil "fake call from lookupMethodFor: - sigh"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   369
    or:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   370
        "insider messages are handled as usual"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   371
        "to avoid recursive lookup error..."
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
        ((ActiveObject compiledMethodAt:#process) valueWithReceiver: aReceiver arguments:#()) == Processor activeProcess]
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
    ) ifTrue:[
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
        ^  super lookupMethodForSelector:selector directedTo:initialSearchClass for:aReceiver withArguments:argArrayOrNil from:sendingContext
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   375
    ].
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   376
    "messages from the outside are forwarded to #doesNotUnderstand:"
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   377
    ^ aReceiver compiledMethodAt:#doesNotUnderstand.
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   378
! !
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
!ActiveObject class methodsFor:'documentation'!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
version
4300
9d3c61b5d387 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
   383
    ^ '$Header$'
2886
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   384
!
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   386
version_CVS
4300
9d3c61b5d387 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 2886
diff changeset
   387
    ^ '$Header$'
2886
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   388
! !
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   389
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   390
e0e5b1d68946 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
ActiveObject initialize!