The Lambda Lab
/
projects
/
sam.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6406acb
)
Now using URLs and UUIDs for actor addressing.
author
Tim Vaughan
<plugd@thelambdalab.xyz>
Tue, 27 Apr 2021 08:39:47 +0000
(10:39 +0200)
committer
Tim Vaughan
<plugd@thelambdalab.xyz>
Tue, 27 Apr 2021 08:39:47 +0000
(10:39 +0200)
sam.scm
patch
|
blob
|
history
diff --git
a/sam.scm
b/sam.scm
index
656338d
..
c819ca5
100644
(file)
--- a/
sam.scm
+++ b/
sam.scm
@@
-8,44
+8,44
@@
matchable
srfi-18 ; threads
srfi-69 ; hash-table
matchable
srfi-18 ; threads
srfi-69 ; hash-table
+ uuid ; ids for actors
+ uri-generic
udp
fifo)
;; Actors
udp
fifo)
;; Actors
-(define (make-machine host port)
- (cons host port))
-(define (machine-host m) (car m))
-(define (machine-port m) (cdr m))
+(define this-host "localhost")
+(define this-port 1234)
-(define this-machine (make-machine "localhost" 1234))
+(define (make-address host port id)
+ (make-uri #:scheme "actor"
+ #:host host
+ #:port port
+ #:path (list '/ id)))
-(define next-actor-id
- (let ((mutex (make-mutex "actor id mutex"))
- (next-id 1))
+(define next-local-address
+ (let ((mutex (make-mutex "actor address mutex")))
(lambda ()
(let ((res #f))
(mutex-lock! mutex)
(lambda ()
(let ((res #f))
(mutex-lock! mutex)
- (set! res next-id)
- (set! next-id (+ next-id 1))
+ (set! res (make-address this-host this-port (uuid)))
(mutex-unlock! mutex)
res))))
(mutex-unlock! mutex)
res))))
-(define (address-id address) (car address))
-(define (address-machine address) (cdr address))
-(define (make-address id machine)
- (cons id machine))
+(define (address-id address) (cadr (uri-path address)))
(define (address-local? address)
(define (address-local? address)
- (
equal? (address-machine address
)
-
this-machine
))
+ (
and (equal? (uri-host address) this-host
)
+
(equal? (uri-port address) this-port)
))
(define actor-table (make-hash-table))
(define (make-actor beh)
(define actor-table (make-hash-table))
(define (make-actor beh)
- (let* ((id (next-actor-id)))
+ (let* ((address (next-local-address))
+ (id (address-id address)))
(hash-table-set! actor-table id beh)
(hash-table-set! actor-table id beh)
-
(make-address id this-machine)
))
+
address
))
(define (deliver-message address . message)
(let ((id (address-id address)))
(define (deliver-message address . message)
(let ((id (address-id address)))