Replacing changed/update experiment..

Bob Arning arning at charm.net
Tue Jun 15 18:37:34 UTC 1999


Peter,

It's looking real good! I will do some poking around and see if I can break it.

On Tue, 15 Jun 1999 17:14:20 +0930 "Peter Smet" <peter.smet at flinders.edu.au> wrote: 
>A challenge for anybody reading this. 
[snip]
>I would like to implement it the second way, but getting the
>garbage collection right is likely to be messy..

See code at end of this email.

>The other challenge, which is well beyond me, is how to 
>deal with distributed events....

I'm not sure what you mean here.

Cheers,
Bob

===to be filed in after PostOffice===
'From Squeak 2.4b of April 23, 1999 on 15 June 1999 at 2:23:31 pm'!

!Object methodsFor: 'publish-subscribe' stamp: 'RAA 6/15/1999 13:12'!
subscribers

	self halt.	"temporary"
	"^self postOffice subscribersTo: self"! !


!PostOffice methodsFor: 'helper' stamp: 'RAA 6/15/1999 13:38'!
addPublisher: anObject 

	^ publishers at: anObject put: (WeakKeyDictionary new)! !

!PostOffice methodsFor: 'helper' stamp: 'RAA 6/15/1999 13:38'!
at: aPublisher 
	"create key if absent"
	^publishers at: aPublisher ifAbsent: [self addPublisher: aPublisher]! !

!PostOffice methodsFor: 'helper' stamp: 'RAA 6/15/1999 13:58'!
at: aPublisher at: aSubscriber 

self halt.		"no longer used"

">>>>
	| dict |
	dict _ self at: aPublisher.
	^ dict at: aSubscriber ifAbsent: [dict at: aSubscriber put: Dictionary new]
<<<<"! !

!PostOffice methodsFor: 'helper' stamp: 'RAA 6/15/1999 13:59'!
at: aPublisher at: aSubscriber at: anEvent 
	| events subscribers |

	events _ self at: aPublisher.
	subscribers _ events 
		at: anEvent 
		ifAbsent: [events at: anEvent put: WeakKeyDictionary new].
	^ subscribers at: aSubscriber ifAbsent: [subscribers at: aSubscriber put: Set new]! !

!PostOffice methodsFor: 'helper' stamp: 'RAA 6/15/1999 13:26'!
removeSubscriber: aSubscriber 

	self eventsDo: [ :eachEvent | 
		eachEvent removeKey: aSubscriber ifAbsent: []
	].! !

!PostOffice methodsFor: 'helper' stamp: 'RAA 6/15/1999 13:43'!
removeSubscriber: aSubscriber forEvent: eventSymbol 

	self publishersDo: [ :events |
		events 
			at: eventSymbol
			ifPresent: [ :subscribers | subscribers removeKey: aSubscriber ifAbsent: []]
	]! !

!PostOffice methodsFor: 'helper' stamp: 'RAA 6/15/1999 13:12'!
subscribersTo: aPublisher 

	self halt.	"temporary"

	"^ self protected: [(self publishers at: aPublisher ifAbsent: [Dictionary new]) keys]"! !

!PostOffice methodsFor: 'important' stamp: 'RAA 6/15/1999 13:43'!
eventsDo: aBlock 
	
	self protected: [self publishersDo: [ :events | events do: aBlock]]! !

!PostOffice methodsFor: 'important' stamp: 'RAA 6/15/1999 14:21'!
finalizeValues

	| deadPublishers deadEvents |
	self protected: [
		deadPublishers _ OrderedCollection new.
		publishers 
			keysAndValuesDo: [ :eachPublisher :events |
				deadEvents _ OrderedCollection new.
				events 
					keysAndValuesDo: [ :eachEvent :subscribers | 
						subscribers finalizeValues.
						subscribers isEmpty ifTrue: [deadEvents add: eachEvent].
					];
					finalizeValues.
				deadEvents do: [ :eachDeadEvent | events removeKey: eachDeadEvent ifAbsent: []].
				events isEmpty ifTrue: [deadPublishers add: eachPublisher].
			];
			finalizeValues.
		deadPublishers do: [ :eachDeadPublisher | 
			publishers removeKey: eachDeadPublisher ifAbsent: []
		].
	]! !

!PostOffice methodsFor: 'important' stamp: 'RAA 6/15/1999 13:40'!
incoming: aMessage from: aPublisher 

	self protected: [
		publishers 
			at: aPublisher 
			ifPresent: [ :events |
				events
					at: aMessage selector 
					ifPresent: [ :subscribers |
						subscribers keysAndValuesDo: [:subscriber :messages | 
							subscriber ifNotNil: [
								messages do: [ :msg | 
									aMessage passArgumentsTo: msg.
									msg sentTo: subscriber.
									mysends _ mysends + 1
								]
							]
						]
					]
			]
	]! !

!PostOffice methodsFor: 'important' stamp: 'RAA 6/15/1999 13:25'!
publishersDo: aBlock 

	self protected: [publishers do: aBlock]! !

!PostOffice methodsFor: 'important' stamp: 'RAA 6/15/1999 13:35'!
subscribersDo: aBlock 

	self halt.		"no longer used "

">>>>
	self protected: [publishers do: aBlock]
<<<<"! !

!PostOffice methodsFor: 'query' stamp: 'RAA 6/15/1999 13:40'!
publishers

	self halt.		"no longer used"

">>>
	^ publishers
<<<<"! !



"Postscript:
Filing this in will invalidate the existing PostOffice."
PostOffice reset; default.!





More information about the Squeak-dev mailing list