csys: basic dispatching mechanism working
This commit is contained in:
parent
0eb98e357e
commit
6cef655707
4 changed files with 21 additions and 6 deletions
|
@ -10,7 +10,7 @@
|
||||||
(:util :scopes/util)
|
(:util :scopes/util)
|
||||||
(:alx :alexandria))
|
(:alx :alexandria))
|
||||||
(:export #:action-spec #:define-actions
|
(:export #:action-spec #:define-actions
|
||||||
#:*root* #:make-setup #:actions
|
#:*root* #:make-setup #:actions #:select
|
||||||
#:find-service #:run-services #:setup-services #:shutdown
|
#:find-service #:run-services #:setup-services #:shutdown
|
||||||
#:base-context #:context #:add-action #:config #:mailbox #:name
|
#:base-context #:context #:add-action #:config #:mailbox #:name
|
||||||
#:handle-message
|
#:handle-message
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
(:shape :scopes/shape)
|
(:shape :scopes/shape)
|
||||||
(:util :scopes/util)
|
(:util :scopes/util)
|
||||||
(:alx :alexandria))
|
(:alx :alexandria))
|
||||||
(:export #:*dispatcher* #:setup #:start
|
(:export #:*dispatcher* #:setup #:start #:shutdown
|
||||||
#:printer
|
#:printer
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@ -31,9 +31,22 @@
|
||||||
:foreground t))
|
:foreground t))
|
||||||
|
|
||||||
(defun handle-message (msg)
|
(defun handle-message (msg)
|
||||||
(print msg))
|
(let ((hdlrs (core:select msg (core:actions *dispatcher*))))
|
||||||
|
(if hdlrs
|
||||||
|
(mapcar #'(lambda (hdlr) (run-action hdlr msg)) hdlrs)
|
||||||
|
(util:lgw "no action selected" msg)))
|
||||||
|
nil)
|
||||||
|
|
||||||
|
(defun run-action (job msg)
|
||||||
|
(let ((ch (async:make-ch)))
|
||||||
|
(async:submit-task ch (lambda () (funcall job msg)))))
|
||||||
|
|
||||||
|
(defun shutdown (msg &optional (delay 0.1))
|
||||||
|
(sleep delay)
|
||||||
|
(format t "~&*** shutdown ~a~%" msg)
|
||||||
|
(actor:stop (core:mailbox *dispatcher*)))
|
||||||
|
|
||||||
;;;; example behaviors / actions
|
;;;; example behaviors / actions
|
||||||
|
|
||||||
(defun printer (msg)
|
(defun printer (msg)
|
||||||
(print msg))
|
(format t "~&*** message: ~a~%" msg))
|
||||||
|
|
|
@ -4,7 +4,8 @@
|
||||||
|
|
||||||
(config:root)
|
(config:root)
|
||||||
|
|
||||||
(config:add-action '(test) #'csys:printer)
|
(config:add-action '(:test) #'csys:printer)
|
||||||
|
(config:add-action '(:stop) #'csys:shutdown)
|
||||||
|
|
||||||
(config:add :logger :class 'logging:config
|
(config:add :logger :class 'logging:config
|
||||||
:loglevel (config:from-env :loglevel :info)
|
:loglevel (config:from-env :loglevel :info)
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
(csys:setup)
|
(csys:setup)
|
||||||
(!= csys:*dispatcher* nil)
|
(!= csys:*dispatcher* nil)
|
||||||
(actor:send (core:mailbox csys:*dispatcher*) (message:create '(:test)))
|
(actor:send (core:mailbox csys:*dispatcher*) (message:create '(:test)))
|
||||||
(actor:stop (core:mailbox csys:*dispatcher*))
|
(actor:send (core:mailbox csys:*dispatcher*) (message:create '(:stop)))
|
||||||
|
;(actor:stop (core:mailbox csys:*dispatcher*))
|
||||||
(csys:start)
|
(csys:start)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue