actor-id-hive
actor-id-string
- actor-am-i-alive?
+ actor-alive?
build-actions
message-auto-reply?
- <- <-wait <-wait* <-reply <-reply-wait <-reply-wait*
+ <- <-* <-wait <-wait* <-reply <-reply* <-reply-wait <-reply-wait*
call-with-message msg-receive msg-val
;; confusing.
(8sync (hive-process-message hive new-message)))))
-
-(define (<- from-actor to-id action . message-body-args)
+(define (<- to-id action . message-body-args)
"Send a message from an actor to another actor"
- (send-message '() from-actor to-id action
+ (send-message '() (%current-actor) to-id action
#f #f message-body-args))
-(define (<-wait* send-options from-actor to-id action . message-body-args)
- "Like <-wait, but allows extra parameters, for example whether to
-#:accept-errors"
- (apply wait-maybe-handle-errors
- (send-message send-options from-actor to-id action
- #f #t message-body-args)
- send-options))
+(define (<-* send-options to-id action . message-body-args)
+ "Like <-*, but allows extra parameters via send-options"
+ (define* (really-send #:key (actor (%current-actor))
+ #:allow-other-keys)
+ (send-message send-options actor to-id action
+ #f #f message-body-args))
+ (apply really-send send-options))
-(define (<-wait from-actor to-id action . message-body-args)
+(define (<-wait to-id action . message-body-args)
"Send a message from an actor to another, but wait until we get a response"
- (apply <-wait* '() from-actor to-id action message-body-args))
+ (wait-maybe-handle-errors
+ (send-message '() (%current-actor) to-id action
+ #f #t message-body-args)))
+
+(define (<-wait* send-options to-id action . message-body-args)
+ "Like <-wait, but allows extra parameters, for example whether to
+#:accept-errors"
+ (define* (really-send #:key (actor (%current-actor))
+ #:allow-other-keys)
+ (apply wait-maybe-handle-errors
+ (send-message send-options actor to-id action
+ #f #t message-body-args)
+ send-options))
+ (apply really-send send-options))
;; TODO: Intelligently ~propagate(ish) errors on -wait functions.
;; We might have `send-message-wait-brazen' to allow callers to
;; not have an exception thrown and instead just have a message with
;; the appropriate '*error* message returned.
-(define (<-reply from-actor original-message . message-body-args)
+(define (<-reply original-message . message-body-args)
"Reply to a message"
- (send-message '() from-actor (message-from original-message) '*reply*
+ (send-message '() (%current-actor) (message-from original-message) '*reply*
original-message #f message-body-args))
-(define (<-auto-reply from-actor original-message)
+(define (<-reply* send-options original-message . message-body-args)
+ "Like <-reply, but allows extra parameters via send-options"
+ (define* (really-send #:key (actor (%current-actor))
+ #:allow-other-keys)
+ (send-message send-options actor
+ (message-from original-message) '*reply*
+ original-message #f message-body-args))
+ (apply really-send send-options))
+
+(define (<-auto-reply actor original-message)
"Auto-reply to a message. Internal use only!"
- (send-message '() from-actor (message-from original-message) '*auto-reply*
+ (send-message '() actor (message-from original-message) '*auto-reply*
original-message #f '()))
-(define (<-reply-wait* send-options from-actor original-message
- . message-body-args)
+(define (<-reply-wait original-message . message-body-args)
"Reply to a messsage, but wait until we get a response"
- (apply wait-maybe-handle-errors
- (send-message send-options from-actor
- (message-from original-message) '*reply*
- original-message #t message-body-args)
- send-options))
+ (wait-maybe-handle-errors
+ (send-message '() (%current-actor)
+ (message-from original-message) '*reply*
+ original-message #t message-body-args)))
-(define (<-reply-wait from-actor original-message . message-body-args)
- "Reply to a messsage, but wait until we get a response"
- (apply <-reply-wait* '() from-actor original-message message-body-args))
+(define (<-reply-wait* send-options original-message
+ . message-body-args)
+ "Like <-reply-wait, but allows extra parameters via send-options"
+ (define* (really-send #:key (actor (%current-actor))
+ #:allow-other-keys)
+ (apply wait-maybe-handle-errors
+ (send-message send-options actor
+ (message-from original-message) '*reply*
+ original-message #t message-body-args)
+ send-options))
+ (apply really-send send-options))
(define* (wait-maybe-handle-errors message
#:key accept-errors
;; This is the default, "simple" way to inherit and process messages.
(actions #:init-value (build-actions
- ;; Default clean-up method is to do nothing.
- (*clean-up* (const #f)))
+ ;; Default cleanup method is to do nothing.
+ (*cleanup* (const #f)))
#:allocation #:each-subclass))
;;; So these are the nicer representations of addresses.
(define %current-actor
(make-parameter #f))
-(define (actor-am-i-alive? actor)
+(define (actor-alive? actor)
(hive-resolve-local-actor (actor-hive actor) (actor-id actor)))
;; This is in the case of an ambassador failing to forward a
;; message... it reports it back to the hive
(*failed-forward* hive-handle-failed-forward)
- (*clean-up-all* hive-handle-clean-up-all))))
+ (*cleanup-all* hive-handle-cleanup-all))))
(define-method (hive-handle-failed-forward (hive <hive>) message)
"Handle an ambassador failing to forward a message"
'TODO)
-(define-method (hive-handle-clean-up-all (hive <hive>) message)
+(define-method (hive-handle-cleanup-all (hive <hive>) message)
"Send a message to all actors in our registry to clean themselves up."
;; Unfortunately we have to do this hack and run over the list
;; twice, because hash-for-each would result in an unrewindable
(hash-map->list (lambda (actor-id actor) actor-id)
(hive-actor-registry hive)))
(for-each (lambda (actor-id)
- (<- hive actor-id '*clean-up*))
+ (<- actor-id '*cleanup*))
actor-ids))
(define* (make-hive #:key hive-id)
(define-method (hive-gen-actor-id (hive <hive>) cookie)
(make-address (if cookie
- (string-append cookie "-" (big-random-number-string))
+ (string-append cookie ":" (big-random-number-string))
(big-random-number-string))
(hive-id hive)))
actor-id))
(define* (hive-create-actor hive actor-class #:rest init)
+ "Create an actor on HIVE using ACTOR-CLASS passing in INIT args"
(%hive-create-actor hive actor-class
- init #f))
+ init (symbol->string (class-name actor-class))))
(define* (hive-create-actor* hive actor-class id-cookie #:rest init)
- "Create an actor, but also add a 'cookie' to the name for debugging"
+ "Create an actor, but also allow customizing a 'cookie' added to the id
+for debugging"
(%hive-create-actor hive actor-class
init id-cookie))
init id-cookie))
-(define (self-destruct actor)
- "Remove an actor from the hive."
+(define* (self-destruct actor #:key (cleanup #t))
+ "Remove an actor from the hive.
+
+Unless #:cleanup is set to #f, this will first have the actor handle
+its '*cleanup* action handler."
+ (when cleanup
+ (<-wait (actor-id actor) '*cleanup*))
(hash-remove! (hive-actor-registry (actor-hive actor))
(actor-id actor)))
;;; 8sync bootstrap utilities
;;; =========================
-(define* (run-hive hive initial-tasks)
+(define* (run-hive hive initial-tasks
+ #:key (cleanup #t))
"Start up an agenda and run HIVE in it with INITIAL-TASKS."
(dynamic-wind
(const #f)
(let* ((queue (list->q initial-tasks))
(agenda (make-agenda #:pre-unwind-handler print-error-and-continue
#:queue queue)))
- (start-agenda agenda)))
- ;; Run clean-up
+ (run-agenda agenda)))
+ ;; Run cleanup
(lambda ()
- (run-hive-clean-up hive))))
+ (when cleanup
+ (run-hive-cleanup hive)))))
-(define (run-hive-clean-up hive)
+(define (run-hive-cleanup hive)
(let ((queue (list->q (list (bootstrap-message hive (actor-id hive)
- '*clean-up-all*)))))
- (start-agenda
+ '*cleanup-all*)))))
+ (run-agenda
(make-agenda #:queue queue))))
(define (bootstrap-message hive to-id action . message-body-args)
(wrap
- (apply <- hive to-id action message-body-args)))
+ (apply <-* `(#:actor ,hive) to-id action message-body-args)))
\f