-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathactors-startup.lisp
88 lines (73 loc) · 3.14 KB
/
actors-startup.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
(in-package :actors-base)
;; ----------------------------------------------------------------------------
(defun install-actor-directory ()
(setf *actor-directory-manager*
(make-actor (&rest msg)
((directory (make-hash-table
:test 'equal
:single-thread t))
(rev-directory (make-hash-table
:test 'eq
:single-thread t)))
(labels ((clean-up ()
(setf *actor-directory-manager* #'lw:do-nothing)))
(um:dcase msg
(:clear ()
(clrhash directory))
(:register (actor name)
;; this simply overwrites any existing entry with actor
(um:when-let (key (acceptable-key name))
(setf (gethash key directory) actor
(gethash actor rev-directory) key)))
(:unregister (name-or-actor)
(cond ((typep name-or-actor 'Actor)
(um:when-let (key (gethash name-or-actor rev-directory))
(remhash key directory)
(remhash name-or-actor rev-directory)))
(t
(um:when-let (key (acceptable-key name-or-actor))
(um:when-let (actor (gethash key directory))
(remhash key directory)
(remhash actor rev-directory))))
))
(:get-all (replyTo)
(let (actors)
(maphash (lambda (k v)
(setf actors (acons k v actors)))
directory)
(send replyTo actors)))
(:find (name replyTo)
(send replyTo (um:when-let (key (acceptable-key name))
(gethash key directory))))
(:reverse-lookup (actor replyTo)
(send replyTo (gethash actor rev-directory)))
(:quit ()
(clean-up))
))))
(register-actor *actor-directory-manager* :ACTOR-DIRECTORY)
(pr "Actor Directory created..."))
(defun install-actor-printer ()
(setf *shared-printer-actor*
(make-actor (&rest msg)
()
(um:dcase msg
(:print (&rest things-to-print)
(dolist (item things-to-print)
(print item)))
(:quit ()
(setf *shared-printer-actor* #'blind-print))
)))
(register-actor *shared-printer-actor* :SHARED-PRINTER))
(defun install-actor-system (&rest ignored)
(declare (ignore ignored))
(install-actor-directory)
(install-actor-printer))
#||#
#+:LISPWORKS
(let ((lw:*handle-existing-action-in-action-list* '(:silent :skip)))
(lw:define-action "Initialize LispWorks Tools"
"Start up Actors"
'install-actor-system
:after "Run the environment start up functions"
:once))
#||#