id
int64 0
45.1k
| file_name
stringlengths 4
68
| file_path
stringlengths 14
193
| content
stringlengths 32
9.62M
| size
int64 32
9.62M
| language
stringclasses 1
value | extension
stringclasses 6
values | total_lines
int64 1
136k
| avg_line_length
float64 3
903k
| max_line_length
int64 3
4.51M
| alphanum_fraction
float64 0
1
| repo_name
stringclasses 779
values | repo_stars
int64 0
882
| repo_forks
int64 0
108
| repo_open_issues
int64 0
90
| repo_license
stringclasses 8
values | repo_extraction_date
stringclasses 146
values | sha
stringlengths 64
64
| __index_level_0__
int64 0
45.1k
| exdup_ids_cmlisp_stkv2
sequencelengths 1
47
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
25,214 | fundamental.lisp | open-rsx_rsb-cl/test/converter/fundamental.lisp | ;;;; fundamental.lisp --- Unit tests for "fundamental" converters.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.converter.test)
(deftestsuite fundamental-root (converter-root)
()
(:documentation
"Root unit test suite for fundamental converters."))
;;; Converter fundamental-void
(deftestsuite fundamental-void-root (fundamental-root)
()
(:documentation
"Unit tests for the `fundamental-void' converter."))
(define-basic-converter-test-cases (:fundamental-void)
`((,(octetify #()) :void ,+no-value+)
(,(octetify #(1)) :void :not-applicable)
(:not-applicable :void t)
(:not-applicable :void ,(octetify #()))
(:not-applicable :void ,(octetify #(1)))))
;;; Converter fundamental-null
(deftestsuite fundamental-null-root (fundamental-root)
()
(:documentation
"Unit tests for the `fundamental-null' converter."))
(define-basic-converter-test-cases (:fundamental-null)
`((nil t nil)
(:foo t :foo)
("bar" t "bar")
(,(octetify #(65 65 65)) t ,(octetify #(65 65 65)))
(,(octetify #(65 65 65)) t ,(octetify #(65 65 65)))))
;;; Converter fundamental-bool
(deftestsuite fundamental-bool-root (fundamental-root)
()
(:documentation
"Unit tests for the `fundamental-bool' converter."))
(define-basic-converter-test-cases (:fundamental-bool)
`((,(octetify #(0)) :bool nil)
(,(octetify #(1)) :bool t)
(:not-applicable :bool "bar")
(,(octetify #(2)) :bool :error)))
;;; Converter fundamental-int32
(deftestsuite fundamental-int32-root (fundamental-root)
()
(:documentation
"Unit tests for the `fundamental-int32' converter."))
(define-basic-converter-test-cases (:fundamental-int32)
`((,(octetify #(0 0 0 0)) :int32 0)
(,(octetify #(1 0 0 0)) :int32 1)
(,(octetify #(255 255 255 255)) :int32 -1)
(:not-applicable :int32 "bar")
(,(octetify #(1)) :int32 :error)))
;;; Converter fundamental-ascii-string
(deftestsuite fundamental-ascii-string-root (fundamental-root)
()
(:documentation
"Unit tests for the `fundamental-ascii-string' converter."))
(define-basic-converter-test-cases (:fundamental-ascii-string)
`((,(octetify #()) :ascii-string "")
(:not-applicable :ascii-string :not-a-string)
(,(octetify #(65 65 65)) :ascii-string "AAA")
(:error :ascii-string "Aλ")
(,(octetify #(65 129)) :ascii-string :error)))
;;; Converter fundamental-utf-8-string
(deftestsuite fundamental-utf-8-string-root (fundamental-root)
()
(:documentation
"Unit tests for the `fundamental-utf-8-string' converter."))
(define-basic-converter-test-cases (:fundamental-utf-8-string)
`((,(octetify #()) :utf-8-string "")
(:not-applicable :utf-8-string :not-a-string)
(,(octetify #(65 65 65)) :utf-8-string "AAA")
(,(octetify #(65 206 187)) :utf-8-string "Aλ")
(,(octetify #(255)) :utf-8-string :error)))
;;; Converter fundamental-bytes
(deftestsuite fundamental-bytes-root (fundamental-root)
()
(:documentation
"Unit tests for the `fundamental-bytes' converter."))
(define-basic-converter-test-cases (:fundamental-bytes)
`((,(octetify #()) :bytes ,(octetify #()))
(:not-applicable :bytes :not-an-octet-vector)
(,(octetify #(65 65 65)) :bytes ,(octetify #(65 65 65)))))
;;; Converter fundamental-scope
(deftestsuite fundamental-scope-root (fundamental-root)
()
(:documentation
"Unit tests for the `fundamental-scope' converter."))
(define-basic-converter-test-cases (:fundamental-scope
:domain-test #'scope=)
`((,(octetify #()) :scope :error)
(,(octetify #(102 111 111)) :scope :error)
(:not-applicable :scope :not-a-scope)
(,(octetify #(47)) :scope ,(make-scope "/"))
(,(octetify #(47 102 111 111 47)) :scope ,(make-scope "/foo"))))
;; Local Variables:
;; coding: utf-8
;; End:
| 4,210 | Common Lisp | .lisp | 99 | 38.151515 | 70 | 0.620039 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | fdd30306990e15dfa7e7b821969db9db0e6af16bb91d34fbbeeba49d4509a840 | 25,214 | [
-1
] |
25,215 | reader.lisp | open-rsx_rsb-cl/test/converter/reader.lisp | ;;;; reader.lisp --- Unit tests for the read/print-based converter.
;;;;
;;;; Copyright (C) 2011, 2012, 2013 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.converter.test)
(deftestsuite reader-root (converter-root)
()
(:documentation
"Unit tests for the read/print-based converter."))
(define-basic-converter-test-cases (:reader)
`(("\"bla\"" string "bla")
("5" integer 5)
("5" string :error)))
| 489 | Common Lisp | .lisp | 14 | 32.071429 | 67 | 0.652542 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 08754595279ed517ddbc10fbcdeb56fec186bfa178f05741bfeb7d4f85982e51 | 25,215 | [
-1
] |
25,216 | annotating.lisp | open-rsx_rsb-cl/test/converter/annotating.lisp | ;;;; annotating.lisp --- Unit test for the annotating converter class.
;;;;
;;;; Copyright (C) 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.converter.test)
(deftestsuite annotating-root (converter-root)
()
(:documentation
"Unit tests for the `annotating' converter class."))
(define-basic-converter-test-cases (:annotating
:make-converter (make-instance 'rsb.converter::annotating))
`((:some-wire-data :some-wire-schema
,(rsb.converter::make-annotated :some-wire-data :some-wire-schema))
(:not-applicable :some-wire-schema :foo)))
| 655 | Common Lisp | .lisp | 15 | 38.466667 | 95 | 0.681319 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | c4d31767a33cc78c59fe54dddb7ccdae61b585645309fcf51304cfab3148bd36 | 25,216 | [
-1
] |
25,217 | caching.lisp | open-rsx_rsb-cl/test/converter/caching.lisp | ;;;; caching.lisp --- Unit test for the caching-converter class.
;;;;
;;;; Copyright (C) 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.converter.test)
(deftestsuite caching-root (converter-root)
()
(:documentation
"Unit tests for the `caching-converter' class."))
(define-basic-converter-test-cases
(:caching
:make-converter (make-instance 'rsb.converter:caching-converter
:target :fundamental-void)
:simple? nil)
`((,(octetify #()) :void ,+no-value+)
(,(octetify #(1)) :void :not-applicable)
(:not-applicable :void t)
(:not-applicable :void ,(octetify #()))
(:not-applicable :void ,(octetify #(1)))))
| 751 | Common Lisp | .lisp | 20 | 32.65 | 68 | 0.634615 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 203e85de5ee19ea188c81567102f8a9ea283a781651a4de70a48753b7bda71f0 | 25,217 | [
-1
] |
25,218 | restart-mixins.lisp | open-rsx_rsb-cl/test/transport/restart-mixins.lisp | ;;;; restart-mixins.lisp --- Unit tests for restart mixins.
;;;;
;;;; Copyright (C) 2012, 2013, 2014 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.test)
;;; Tests for `restart-notification-receiver-mixin' class
(deftestsuite restart-notification-receiver-mixin-root (transport-root)
((simple-connector (make-instance 'restart-notification-receiver-mixin)))
(:documentation
"Unit tests for the `restart-notification-receiver-mixin' class."))
(define-restart-test-method receive-notification
((connector restart-notification-receiver-mixin)
(block? t)))
(define-restart-test-case
(receive-notification/restart
:suite-name restart-notification-receiver-mixin-root)
(receive-notification simple-connector t))
(define-restart-test-method notification->event
((connector restart-notification-receiver-mixin)
(notification t)
(wire-schema t)))
(define-restart-test-case
(notification->event/restart
:suite-name restart-notification-receiver-mixin-root)
(notification->event simple-connector :does-not-matter :likewise))
;;; Tests for `restart-notification-sender-mixin' class
(deftestsuite restart-notification-sender-mixin-root (transport-root)
((simple-connector (make-instance 'restart-notification-sender-mixin)))
(:documentation
"Unit tests for the `restart-notification-sender-mixin' class."))
(define-restart-test-method send-notification
((connector restart-notification-sender-mixin)
(notification t)))
(define-restart-test-case
(send-notification/restart
:suite-name restart-notification-sender-mixin-root)
(send-notification simple-connector :ignored))
(define-restart-test-method event->notification
((connector restart-notification-sender-mixin)
(notification t)))
(define-restart-test-case
(event->notification/restart
:suite-name restart-notification-sender-mixin-root)
(event->notification simple-connector :does-not-matter))
| 2,025 | Common Lisp | .lisp | 45 | 41.511111 | 75 | 0.765125 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 56dc871f5235c5481668b5b49111b2448cf140e1a9560e0903393b6a3e3b3784 | 25,218 | [
-1
] |
25,219 | package.lisp | open-rsx_rsb-cl/test/transport/package.lisp | ;;;; package.lisp --- Package definition for unit tests of the transport module.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.transport.test
(:use
#:cl
#:alexandria
#:iterate
#:let-plus
#:lift
#:rsb
#:rsb.event-processing
#:rsb.transport
#:rsb.test)
(:export
#:transport-root)
(:export
#:check-connector-class
#:check-connector
#:define-basic-connector-test-cases)
(:documentation
"This package contains unit tests for the transport module."))
(cl:in-package #:rsb.transport.test)
(deftestsuite transport-root (root)
()
(:documentation
"Root unit test suite for the transport module."))
;;; Test utilities
(defun check-connector-class (class
expected-schemas
expected-wire-type
expected-remote?
expected-direction)
(let ((schemas (transport-schemas class))
(wire-type (transport-wire-type class))
(remote? (transport-remote? class))
(direction (connector-direction class))
(options (connector-options class)))
;; Check schemas.
(iter (for schema in schemas)
(ensure (typep schema 'keyword)))
(ensure-same schemas expected-schemas :test #'set-equal)
;; Check wire-type.
(ensure (typep wire-type 'wire-type))
(ensure-same wire-type expected-wire-type :test #'type=)
;; Check remote.
(ensure-same remote? expected-remote? :test #'eq)
;; Check direction.
(ensure (typep direction 'direction))
(ensure-same direction expected-direction
:test #'eq)
;; Check options.
(iter (for option in options)
(ensure (typep option 'list)))))
(defun check-connector (connector
expected-schemas
expected-wire-type
expected-remote?
expected-direction )
(let ((schemas (transport-schemas connector))
(wire-type (transport-wire-type connector))
(remote? (transport-remote? connector))
(direction (connector-direction connector))
(url (connector-url connector))
(rel-url (connector-relative-url connector "/foo")))
;; Check schemas.
(iter (for schema in schemas)
(ensure (typep schema 'keyword)))
(ensure-same schemas expected-schemas :test #'set-equal)
;; Check wire-type.
(ensure (typep wire-type 'wire-type))
(ensure-same wire-type expected-wire-type :test #'type=)
;; Check remote.
(ensure-same remote? expected-remote? :test #'eq)
;; Check direction.
(ensure (typep direction 'direction))
(ensure-same direction expected-direction :test #'eq)
;; Check URLs.
(ensure (typep url 'puri:uri))
(ensure (typep rel-url 'puri:uri))
(ensure (eq (puri:uri-scheme url) (first expected-schemas)))
(ensure-same (puri:uri-path rel-url) "/foo/"
:test #'string=)))
(defmacro define-basic-connector-test-cases
(class
&key
(name (%guess-connector-name class))
(suite-name (symbolicate class "-ROOT"))
initargs
expected-schemas
expected-wire-type
expected-remote?
expected-direction)
"Define basic test cases for the connector class CLASS.
NAME is a keyword designating TRANSPORT e.g. in calls to
`rsb.transport:make-connector'.
SUITE-NAME is a symbol naming the test suite part of which the
generated test cases should be.
INITARGS are initargs which should be used when making connector
instances.
EXPECTED-SCHEMAS specifies the list of expected schemas of the
connector class.
EXPECTED-WIRE-TYPE specifies the expected wire-type of the
connector class.
EXPECTED-REMOTE? specifies whether CLASS is expected to belong to a
remote transport.
EXPECTED-DIRECTION specifies the expected direction of the
connector class. "
`(progn
(addtest (,suite-name
:documentation
,(format nil "Test whether `find-connector-class' can find ~
the ~A connector class."
class))
find-connector-class
(let* ((transport (service-provider:find-provider
'rsb.transport::transport ',name))
(provider (service-provider:find-provider
transport ,expected-direction))
(class (service-provider:provider-class provider)))
(ensure-same (find-class ',class) class :test #'eq)))
(addtest (,suite-name
:documentation
,(format nil "Test basic properties of the ~A connector ~
class."
class))
class
(check-connector-class (find-class ',class)
,expected-schemas
,expected-wire-type
,expected-remote?
,expected-direction))
(addtest (,suite-name
:documentation
,(format nil "Test basic properties of a ~A connector ~
instance."
class))
construct
(let ((instance (apply #'make-instance ',class ,initargs)))
(check-connector instance
,expected-schemas
,expected-wire-type
,expected-remote?
,expected-direction)))
(addtest (,suite-name
:documentation
,(format nil "Test printing a ~A connector instance."
class))
print
(let ((instance (apply #'make-instance ',class ,initargs)))
(with-output-to-string (stream)
(print-object instance stream))))))
;;; Utility functions
(defun %guess-connector-name (class-name)
"Guess the keyword naming the connector class named CLASS-NAME."
(let* ((package-name (package-name (symbol-package class-name)))
(.-position (position #\. package-name :from-end t)))
(make-keyword (subseq package-name (1+ .-position)))))
| 6,295 | Common Lisp | .lisp | 160 | 29.80625 | 80 | 0.598592 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | d421bc604e53030eaca5520ced4c6024a6d9fcc175cadf0aeae5ea44ae01c29c | 25,219 | [
-1
] |
25,220 | error-handling-mixins.lisp | open-rsx_rsb-cl/test/transport/error-handling-mixins.lisp | ;;;; error-handling-mixins.lisp --- Unit tests for the transport-related error handling mixins.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.test)
(macrolet
((define-error-handling-mixin-tests (class
(method-name (&rest method-args) &body method-body)
&body invoke)
(let ((suite-name (symbolicate class "-ROOT")))
`(progn
(defmethod ,method-name ((connector ,class) ,@method-args)
,@method-body)
(deftestsuite ,suite-name (transport-root)
((simple-handler (make-instance ',class)))
(:documentation
,(format nil "Unit tests for the `~(~A~)' class."
class)))
(addtest (,suite-name
:documentation
`(format nil "Smoke test for the error handling ~
performed by the `~(~A~)' class."
class))
smoke
;; See rsb.event-processing.test:error-policy-mixin-root
;; for an explanation of the test logic.
(ensure-condition 'simple-error
,@invoke)
(setf (processor-error-policy simple-handler) #'continue)
,@invoke)))))
(define-error-handling-mixin-tests
error-handling-pull-receiver-mixin
(emit ((block? t))
(restart-case
(error "~@<emit signaled an error.~@:>")
(continue (&optional condition)
(declare (ignore condition))
nil)))
(emit simple-handler t))
(define-error-handling-mixin-tests
error-handling-push-receiver-mixin
(receive-messages ()
(restart-case
(error "~@<receive-messages signaled an error.~@:>")
(continue (&optional condition)
(declare (ignore condition))
nil)))
(receive-messages simple-handler))
(define-error-handling-mixin-tests
error-handling-sender-mixin
(handle ((event event))
(restart-case
(error "~@<handle signaled an error.~@:>")
(continue (&optional condition)
(declare (ignore condition))
nil)))
(handle simple-handler (make-event "/" "bla"))))
| 2,494 | Common Lisp | .lisp | 58 | 29.62069 | 95 | 0.530528 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 797a61c499405353cf7056da221ad9eeb5fc5f514aa40f100e20555014ad36e9 | 25,220 | [
-1
] |
25,221 | connector-class.lisp | open-rsx_rsb-cl/test/transport/connector-class.lisp | ;;;; connector-class.lisp --- Unit tests for the connector-class class.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.test)
(deftestsuite connector-class-root (transport-root)
()
(:documentation
"Test suite for the `connector-class' class."))
(defgeneric mock-connector-class (which))
(defun call-with-mock-connector-class (thunk which)
(let+ (((&values superclasses slots options)
(mock-connector-class which)))
(eval
`(defclass ,which ,superclasses
,slots
(:metaclass connector-class)
,@options))
(unwind-protect
(funcall thunk (find-class which))
(setf (find-class which) nil))))
(defmacro with-mock-connector-class ((which class-var) &body body)
(let+ (((&values name ignored?) (if class-var
(values class-var nil)
(values (gensym) t))))
`(call-with-mock-connector-class
(lambda (,name)
,@(when ignored? `((declare (ignore ,name))))
,@body)
',which)))
(addtest (connector-class-root
:documentation
"Test error behavior for an invalid constructing an instance
of `connector-class'.")
construction/invalid
;; We request the option no-such-option to be constructed from the
;; slot of the same name. Since there is no such slot, an error has
;; to be signaled.
(eval `(defclass bar ()
()
(:metaclass connector-class)
(:options
(:no-such-option &slot))))
(unwind-protect
(ensure-condition 'error
(closer-mop:finalize-inheritance (find-class 'bar)))
(eval `(defclass bar ()
()
(:metaclass connector-class)
(:options)))
(setf (find-class 'bar) nil)))
(defmethod mock-connector-class ((which (eql 'foo)))
(values '()
'((an-option :initarg :an-option
:type boolean
:initform t
:documentation
"doc"))
'((:transport :mock)
(:direction :in-push)
(:options (:an-option &slot)))))
(addtest (connector-class-root
:documentation
"Test constructing an instance of `connector-class'.")
construction/valid
(register-transport
:mock
:schemas :whoop
:wire-type 'string)
(with-mock-connector-class (foo class)
(ensure-same (transport-schemas class) '(:whoop))
(ensure-same (transport-wire-type class) 'string)
(ensure-same (connector-direction class) :in-push)
(ensure-same (connector-options class) '((:an-option boolean
:default t
:description "doc")))))
(defmethod mock-connector-class ((which (eql 'sub)))
(values '(foo)
'((another-option :initarg :another-option
:type integer))
'((:options (:another-option &slot)))))
(addtest (connector-class-root
:documentation
"Test constructing an instance of `connector-class'.")
inheritance
(register-transport
:mock
:schemas :whoop
:wire-type 'string)
(with-mock-connector-class (foo nil)
(with-mock-connector-class (sub class)
(ensure-same (transport-schemas class) '(:whoop))
(ensure-same (transport-wire-type class) 'string)
(ensure-same (connector-direction class) :in-push)
(ensure-same (connector-options class) '((:another-option integer)
(:an-option boolean
:default t
:description "doc"))))))
| 3,854 | Common Lisp | .lisp | 99 | 28.89899 | 74 | 0.570588 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 1912fb2518f243a2292ecd374a1c3a6e5b677cf36e702f4bea66b8eb4c508ef9 | 25,221 | [
-1
] |
25,222 | connector.lisp | open-rsx_rsb-cl/test/transport/connector.lisp | ;;;; connector.lisp --- Unit tests for the connector class.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.test)
(deftestsuite connector-root (transport-root)
()
(:documentation
"Unit test for the `connector' class."))
(addtest (connector-root
:documentation
"Test `connector-relative-url'.")
connector-relative-url
(ensure-cases (initargs scope expected-url)
'(((:schema :mock :host "azurit") "/foo/bar/"
"mock://azurit/foo/bar/")
((:schema :mock :port 5003) "/foo/bar/"
"mock://localhost:5003/foo/bar/")
((:schema :mock :host "azurit" :port 5003) "/foo/bar/"
"mock://azurit:5003/foo/bar/")
((:schema :spread :host "azurit") "/foo/bar/"
"spread://azurit/foo/bar/")
((:schema :spread :port 5003) "/foo/bar/"
"spread://localhost:5003/foo/bar/")
((:schema :spread :host "azurit" :port 5003) "/foo/bar/"
"spread://azurit:5003/foo/bar/"))
(let+ ((connector (apply #'make-instance 'connector initargs))
((&flet do-it (relative-part)
(connector-relative-url connector relative-part))))
(ensure-same (do-it scope) (puri:uri expected-url)
:test #'puri:uri=)
(ensure-same (do-it (make-scope scope)) (puri:uri expected-url)
:test #'puri:uri=)
(ensure-same (do-it (puri:uri scope)) (puri:uri expected-url)
:test #'puri:uri=))))
| 1,633 | Common Lisp | .lisp | 36 | 37.555556 | 69 | 0.567108 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | a625c305ae0c5417a4203497d1591012c4679110cb28556bb50ed54c380b9a72 | 25,222 | [
-1
] |
25,223 | threaded-receiver-mixin.lisp | open-rsx_rsb-cl/test/transport/threaded-receiver-mixin.lisp | ;;;; threaded-receiver-mixin.lisp --- Unit tests for the threaded-receive-mixin class.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.test)
(defclass mock-receiver (threaded-receiver-mixin) ())
(defmethod receive-messages ((receiver mock-receiver))
;; This causes a timeout of the test case, if the interruption does
;; not work properly.
(sleep most-positive-fixnum))
(deftestsuite threaded-receiver-mixin-root (transport-root)
()
(:documentation
"Unit tests for the `threaded-receiver-mixin' class."))
(addtest (threaded-receiver-mixin-root
:documentation
"Smoke test for the `threaded-receiver-mixin' class.")
smoke
;; We try attaching and detaching with different timing behaviors.
(let ((receiver (make-instance 'mock-receiver)))
(iter (repeat 4)
(start-receiver receiver)
(stop-receiver receiver)
(ensure-null (connector-thread receiver))
(start-receiver receiver)
(sleep .001)
(stop-receiver receiver)
(ensure-null (connector-thread receiver)))))
| 1,191 | Common Lisp | .lisp | 29 | 35.931034 | 86 | 0.69697 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | f251db7b5020f61eb14ff4ebf6e71da2297120d90411a7e1088a894ba57de8ff | 25,223 | [
-1
] |
25,224 | connectors.lisp | open-rsx_rsb-cl/test/transport/inprocess/connectors.lisp | ;;;; connectors.lisp --- Unit tests for the connector classes.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.inprocess.test)
;;; `in-pull-connector'
(deftestsuite in-pull-connector-root (transport-inprocess-root)
()
(:documentation
"Root unit tests suite for the `in-pull-connector' class."))
(define-basic-connector-test-cases in-pull-connector
:initargs '(:schema :inprocess)
:expected-schemas '(:inprocess)
:expected-wire-type 't
:expected-remote? nil
:expected-direction :in-pull)
;;; `in-push-connector'
(deftestsuite in-push-connector-root (transport-inprocess-root)
()
(:documentation
"Root unit tests suite for the `in-push-connector' class."))
(define-basic-connector-test-cases in-push-connector
:initargs '(:schema :inprocess)
:expected-schemas '(:inprocess)
:expected-wire-type 't
:expected-remote? nil
:expected-direction :in-push)
;;; `out-connector'
(deftestsuite out-connector-root (transport-inprocess-root)
()
(:documentation
"Root unit tests suite for the `out-connector' class."))
(define-basic-connector-test-cases out-connector
:initargs '(:schema :inprocess)
:expected-schemas '(:inprocess)
:expected-wire-type 't
:expected-remote? nil
:expected-direction :out)
| 1,395 | Common Lisp | .lisp | 39 | 33.051282 | 63 | 0.716418 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 5af2456cc96f46ae7f315ce608ac4d1f7e237ebe50f316f2c518b703706d2ae1 | 25,224 | [
-1
] |
25,225 | package.lisp | open-rsx_rsb-cl/test/transport/inprocess/package.lisp | ;;;; package.lisp --- Package definition for unit tests of the transport.inprocess module.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.transport.inprocess.test
(:use
#:cl
#:lift
#:rsb.transport.inprocess
#:rsb.transport.test)
(:import-from #:rsb.transport.inprocess
#:in-pull-connector
#:in-push-connector
#:out-connector)
(:documentation
"This package contains unit tests for the transport.inprocess
module."))
(cl:in-package #:rsb.transport.inprocess.test)
(deftestsuite transport-inprocess-root (transport-root)
()
(:documentation
"Root unit test suite for the transport.inprocess module."))
| 734 | Common Lisp | .lisp | 23 | 28.826087 | 90 | 0.730114 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 469b579c54d194551fee5f17d848031a8b18e075195729c15becd51aab302399 | 25,225 | [
-1
] |
25,226 | connectors-unix.lisp | open-rsx_rsb-cl/test/transport/socket/connectors-unix.lisp | ;;;; connectors.lisp --- Unit tests for UNIX connector classes.
;;;;
;;;; Copyright (C) 2017, 2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.socket.test)
;;; `connector' class
(deftestsuite unix-connector-root (transport-socket-root)
()
(:documentation
"Unit tests for the `unix-connector' class."))
(addtest (unix-connector-root
:documentation
"Test constructing instances of the `unix-connector' class.")
construction/smoke
(flet ((do-it (&rest args)
(apply #'make-instance 'unix-connector
:schema :unix-socket
:name "foo"
:converter nil
args)))
(ensure-condition 'error
(do-it :if-leftover-connections :foo))
(ensure-condition 'error
(do-it :if-leftover-connections "foo")))
(flet ((do-it (server?)
(make-instance 'unix-connector
:schema :unix-socket
:name "foo"
:converter nil
:server? server?)))
(do-it nil)
(do-it :auto)))
;;; Connector subclasses
(macrolet
((define-connector-suite (direction)
(let ((class-name (format-symbol :rsb.transport.socket "UNIX-~A-CONNECTOR" direction))
(suite-name (format-symbol *package* "UNIX-~A-CONNECTOR-ROOT" direction)))
`(progn
(deftestsuite ,suite-name (transport-socket-root)
()
(:documentation
,(format nil "Test suite for the `~(~A~)' class."
class-name)))
(define-basic-connector-test-cases ,class-name
:name :unix-socket
:initargs (list :schema :unix
:name "foo"
:converter :fundamental-null)
:expected-schemas '(:unix :unix-socket)
:expected-wire-type 'octet-vector
:expected-remote? nil
:expected-direction ,(make-keyword direction))
(addtest (,suite-name
:documentation
,(format nil "Test constructing `~(~A~)' instances."
class-name))
construct/invalid
;; Missing :converter initarg.
(ensure-condition 'missing-required-initarg
(make-instance ',class-name)))))))
(define-connector-suite :out)
(define-connector-suite :in-pull)
(define-connector-suite :in-push))
| 2,651 | Common Lisp | .lisp | 64 | 29.28125 | 93 | 0.536159 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | ec115bc102003bf3ccb95a6a95d746a98552702bea72935161697768df6bb630 | 25,226 | [
-1
] |
25,227 | transport-unix.lisp | open-rsx_rsb-cl/test/transport/socket/transport-unix.lisp | ;;;; transport-unix.lisp --- Unit tests for UNIX transport and bus.
;;;;
;;;; Copyright (C) 2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.socket.test)
(deftestsuite transport-socket-unix-root (transport-socket-root)
()
(:documentation
"Unit tests for the UNIX transport and bus."))
(addtest (transport-socket-unix-root
:documentation
"Test creating `bus-client' instances and attaching and
detaching connectors to them.
Try multiple connectors of different classes which also
causes the test case to be repeated without a fresh
port. This helps ensuring proper cleanup.")
client/smoke
(ensure-cases (connector-class schema address)
(mappend (lambda+ ((class schema address))
(make-list 10 :initial-element `(,class ,schema ,address)))
(let ((name (funcall (random-string (constantly 8)))))
`((unix-in-pull-connector :unix-socket (:name ,name))
(unix-in-push-connector :unix-socket (:name ,name))
(unix-out-connector :unix-socket (:name ,name)))))
(let ((transport (service-provider:find-provider
'rsb.transport:transport schema))
(connector-1 (make-socket-connector connector-class schema address))
(connector-2 (make-socket-connector connector-class schema address)))
;; There is no server yet, so this has to signal an error.
(ensure-condition 'usocket:connection-refused-error ; TODO(jmoringe): keep this condition type?
(transport-ensure-bus transport :client! connector-1 address))
;; Create a bus server.
(with-participant (nil :reader (make-socket-url :unix-socket t address)
:converters '((t . :fundamental-null)))
;; We should be able to create a bus clients now. We create
;; two connectors and request a bus client for each of
;; them. The first request should cause the bus client to be
;; created, while the second should just return the existing
;; bus client.
(let ((bus-1 (transport-ensure-bus
transport :client! connector-1 address))
(bus-2 (transport-ensure-bus
transport :client! connector-2 address)))
(check-buses-and-connectors
(list bus-1 bus-2) (list connector-1 connector-2) t))))))
(addtest (transport-socket-unix-root
:documentation
"Test creating `bus-server' instances and attaching and
detaching connectors to them.
Try multiple connectors of different classes which also
causes the test case to be repeated without a fresh
port. This helps ensuring proper cleanup.") server/smoke
(ensure-cases (connector-class schema address)
(mappend (lambda+ ((class schema address))
(make-list 10 :initial-element `(,class ,schema ,address)))
(let ((name (funcall (random-string (constantly 8)))))
`((unix-in-pull-connector :unix-socket (:name ,name))
(unix-in-push-connector :unix-socket (:name ,name))
(unix-out-connector :unix-socket (:name ,name)))))
(let ((transport (service-provider:find-provider
'rsb.transport:transport :unix-socket))
(connector-1 (make-socket-connector
connector-class schema address :server? t))
(connector-2 (make-socket-connector
connector-class schema address :server? t)))
;; Create two connectors and request a bus server for each of
;; them. The first request should cause the bus server to be
;; created, while the second should just return the existing bus
;; server. Creating a bus server should succeed unless the port
;; is in use.
(let ((bus-1 (transport-ensure-bus
transport :server! connector-1 address))
(bus-2 (transport-ensure-bus
transport :server! connector-2 address)))
(check-buses-and-connectors
(list bus-1 bus-2) (list connector-1 connector-2))))))
| 4,279 | Common Lisp | .lisp | 77 | 44.480519 | 101 | 0.628551 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | f5fac15a2c555275dae76265ed4b0a756a93e3c46cb3ac1941702117752dd233 | 25,227 | [
-1
] |
25,228 | connectors-tcp.lisp | open-rsx_rsb-cl/test/transport/socket/connectors-tcp.lisp | ;;;; connectors-tcp.lisp --- Unit tests for TCP connector classes.
;;;;
;;;; Copyright (C) 2012-2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.socket.test)
;;; `connector' class
(deftestsuite tcp-connector-root (transport-socket-root)
()
(:documentation
"Unit tests for the `tcp-connector' class."))
(addtest (tcp-connector-root
:documentation
"Test constructing instances of the `tcp-connector' class.")
construction/smoke
(flet ((do-it (&rest args)
(apply #'make-instance 'tcp-connector
:schema :tcp-socket
:host "localhost"
:port 1
:converter nil
args)))
(ensure-condition 'incompatible-initargs
(do-it :server? nil :portfile "-"))
(ensure-condition 'incompatible-initargs
(do-it :server? :auto :portfile "-"))
(ensure-condition 'error
(do-it :if-leftover-connections :foo))
(ensure-condition 'error
(do-it :if-leftover-connections "foo")))
(let ((instance (make-instance 'tcp-connector
:schema :tcp-socket
:host "foo"
:port 1
:converter nil)))
(ensure-same (connector-host instance) "foo" :test #'equal)
(ensure-same (connector-port instance) 1 :test #'eql)))
;;; Connector subclasses
(macrolet
((define-connector-suite (direction)
(let ((class-name (format-symbol :rsb.transport.socket "TCP-~A-CONNECTOR" direction))
(suite-name (format-symbol *package* "TCP-~A-CONNECTOR-ROOT" direction)))
`(progn
(deftestsuite ,suite-name (transport-socket-root)
()
(:documentation
,(format nil "Test suite for the `~(~A~)' class."
class-name)))
(define-basic-connector-test-cases ,class-name
:name :tcp-socket
:initargs (list :schema :tcp-socket
:host "localhost"
:port *next-port*
:converter :fundamental-null)
:expected-schemas '(:tcp-socket :socket)
:expected-wire-type 'octet-vector
:expected-remote? t
:expected-direction ,(make-keyword direction))
(addtest (,suite-name
:documentation
,(format nil "Test constructing `~(~A~)' instances."
class-name))
construct/invalid
;; Missing :converter initarg.
(ensure-condition 'missing-required-initarg
(make-instance ',class-name)))))))
(define-connector-suite :out)
(define-connector-suite :in-pull)
(define-connector-suite :in-push))
| 3,024 | Common Lisp | .lisp | 69 | 31.115942 | 92 | 0.535034 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | d4957b42ba75f27850b254a70e8057dc3a7eb5b3f97f003f63060b4bc5718ef5 | 25,228 | [
-1
] |
25,229 | transport-tcp.lisp | open-rsx_rsb-cl/test/transport/socket/transport-tcp.lisp | ;;;; transport-tcp.lisp --- Unit tests for TCP transport and bus.
;;;;
;;;; Copyright (C) 2012-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.socket.test)
(deftestsuite transport-socket-tcp-root (transport-socket-root)
()
(:documentation
"Unit tests for the TCP transport and bus."))
(addtest (transport-socket-tcp-root
:documentation
"Test supplying incompatible options for a single
connection.")
incompatible-options
;; Has to signal an error since the incompatible options are
;; supplied for a single host-port combination.
(ensure-condition participant-creation-error
(with-participants
((nil :reader (make-socket-url :tcp-socket t nil))
(nil :reader (make-socket-url :tcp-socket nil '("tcpnodelay" "0")))
(nil :reader (make-socket-url :tcp-socket nil nil)))))) ; body is not important
(addtest (transport-socket-tcp-root
:documentation
"Test creating `bus-client' instances and attaching and
detaching connectors to them.
Try multiple connectors of different classes which also
causes the test case to be repeated without a fresh
port. This helps ensuring proper cleanup.")
client/smoke
(ensure-cases (connector-class schema address)
(mappend (lambda+ ((class schema address))
(make-list 10 :initial-element `(,class ,schema ,address)))
`((tcp-in-pull-connector :tcp-socket
(:host "localhost" :port ,*next-port*))
(tcp-in-push-connector :tcp-socket
(:host "localhost" :port ,*next-port*))
(tcp-out-connector :tcp-socket
(:host "localhost" :port ,*next-port*))))
(let ((transport (service-provider:find-provider
'rsb.transport:transport schema))
(connector-1 (make-socket-connector connector-class schema address))
(connector-2 (make-socket-connector connector-class schema address)))
;; There is no server yet, so this has to signal an error.
(ensure-condition 'usocket:connection-refused-error ; TODO(jmoringe): keep this condition type?
(transport-ensure-bus transport :client! connector-1 address))
;; Create a bus server.
(with-participant (nil :reader (make-socket-url :tcp-socket t nil)
:converters '((t . :fundamental-null)))
;; We should be able to create a bus clients now. We create
;; two connectors and request a bus client for each of
;; them. The first request should cause the bus client to be
;; created, while the second should just return the existing
;; bus client.
(let ((bus-1 (transport-ensure-bus
transport :client! connector-1 address))
(bus-2 (transport-ensure-bus
transport :client! connector-2 address)))
(check-buses-and-connectors
(list bus-1 bus-2) (list connector-1 connector-2) t))))))
(addtest (transport-socket-tcp-root
:documentation
"Test creating `bus-server' instances and attaching and
detaching connectors to them.
Try multiple connectors of different classes which also
causes the test case to be repeated without a fresh
port. This helps ensuring proper cleanup.") server/smoke
(ensure-cases (connector-class schema address)
(mappend (lambda+ ((class schema address))
(make-list 10 :initial-element `(,class ,schema ,address)))
`((tcp-in-pull-connector :tcp-socket
(:host "localhost" :port ,*next-port*))
(tcp-in-push-connector :tcp-socket
(:host "localhost" :port ,*next-port*))
(tcp-out-connector :tcp-socket
(:host "localhost" :port ,*next-port*))))
(let ((transport (service-provider:find-provider
'rsb.transport:transport :tcp-socket))
(connector-1 (make-socket-connector
connector-class schema address :server? t))
(connector-2 (make-socket-connector
connector-class schema address :server? t)))
;; Create two connectors and request a bus server for each of
;; them. The first request should cause the bus server to be
;; created, while the second should just return the existing bus
;; server. Creating a bus server should succeed unless the port
;; is in use.
(let ((bus-1 (transport-ensure-bus
transport :server! connector-1 address))
(bus-2 (transport-ensure-bus
transport :server! connector-2 address)))
(check-buses-and-connectors
(list bus-1 bus-2) (list connector-1 connector-2))))))
(addtest (transport-socket-tcp-root
:documentation
"Test automatically assigned ports and the portfile option
using the -[2] syntax.")
server/automatic-port.1
(let* ((host "localhost")
(port 0)
(address (list :host host :port port))
(transport (service-provider:find-provider
'rsb.transport:transport :tcp-socket))
(connector-1 (make-socket-connector
'tcp-connector :tcp-socket address
:server? t :portfile "-"))
(connector-2 (make-socket-connector
'tcp-connector :tcp-socket address
:server? t :portfile "-2")))
;; Create two connectors and request a bus server with automatic
;; port assignment for each of them. The first request should
;; cause the bus server to be created, while the second should
;; just return the existing bus server. Creating a bus server
;; should succeed unless the port is in use.
(let+ (((&flet ensure-bus (connector stream-name)
(let+ ((bus)
(port (with-output-to-string (stream)
(progv (list stream-name) (list stream)
(setf bus (transport-ensure-bus
transport :server! connector
address))))))
(values bus port))))
((&values bus-1 port-1)
(ensure-bus connector-1 '*standard-output*))
((&values bus-2 port-2)
(ensure-bus connector-2 '*error-output*)))
;; Make sure that both connectors got the same port via their
;; respective "portfile" outputs.
(ensure-same port-1 port-2 :test #'string=)
(check-buses-and-connectors
(list bus-1 bus-2) (list connector-1 connector-2)))))
(addtest (transport-socket-tcp-root
:documentation
"Test automatically assigned ports and the portfile option
with multiple/mixed portfile options.")
server/automatic-port.2
(let* ((host "localhost")
(port 0)
(address (list :host host :port port))
(transport (service-provider:find-provider
'rsb.transport:transport :tcp-socket))
(connector-1 (make-socket-connector
'tcp-connector :tcp-socket address
:server? t))
(connector-2 (make-socket-connector
'tcp-connector :tcp-socket address
:server? t :portfile "-"))
(connector-3 (make-socket-connector
'tcp-connector :tcp-socket address
:server? t :portfile "-")))
;; Create three connectors and request a bus server with automatic
;; port assignment for each of them. The first connector does not
;; specify a port-file while the second and third do. The correct
;; behavior is writing the port-file once for the second connector
;; (i.e. not a second time for the third connector).
(let+ (((&flet ensure-bus (connector)
(let+ ((bus)
(output (with-output-to-string (*standard-output*)
(setf bus (transport-ensure-bus
transport :server! connector
address)))))
(values bus output))))
((&values bus-1 output-1) (ensure-bus connector-1))
((&values bus-2 output-2) (ensure-bus connector-2))
((&values bus-3 output-3) (ensure-bus connector-3)))
;; Make sure that only the second connector caused the port-file
;; to be written.
(ensure-same output-1 "" :test #'string=)
(ensure-different output-2 "" :test #'string=)
(ensure-same output-3 "" :test #'string=)
(check-buses-and-connectors
(list bus-1 bus-2 bus-3) (list connector-1 connector-2 connector-3)))))
#+(and sbcl (not win32))
(addtest (transport-socket-tcp-root
:documentation
"Test automatically assigned ports and the portfile option
with custom file descriptors.")
server/automatic-port.portfile-fd
(let+ (((&values read-fd write-fd) (sb-posix:pipe))
(portfile (format nil "-~D" write-fd))
(host "localhost")
(port 0)
(address (list :host host :port port))
(transport (service-provider:find-provider
'rsb.transport:transport :tcp-socket))
(connector (make-socket-connector
'tcp-connector :tcp-socket address
:server? t :portfile portfile))
(bus (transport-ensure-bus
transport :server! connector address))
(output (with-open-stream (stream (sb-sys:make-fd-stream
read-fd :input t))
(read-line stream))))
(ensure (typep (parse-integer output) '(unsigned-byte 16)))))
(defvar *port-promise*)
(defun note-port (port)
(lparallel:fulfill *port-promise* port))
(addtest (transport-socket-tcp-root
:documentation
"Test automatically assigned ports and the portfile
option using the call:NAME syntax.")
server/automatic-port.call
(let* ((host "localhost")
(port 0)
(address (list :host host :port port))
(transport (service-provider:find-provider
'rsb.transport:transport :tcp-socket))
(connector-1 (make-socket-connector
'tcp-connector :tcp-socket address
:server? t
:portfile "call:rsb.transport.socket.test::note-port"))
(connector-2 (make-socket-connector
'tcp-connector :tcp-socket address
:server? t
:portfile "call:rsb.transport.socket.test::note-port")))
;; Create two connectors and request a bus server with automatic
;; port assignment for each of them. The first request should
;; cause the bus server to be created, while the second should
;; just return the existing bus server. Creating a bus server
;; should succeed unless the port is in use.
(let+ ((promise (lparallel:promise))
((&flet ensure-bus (connector)
(values (let ((*port-promise* promise))
(transport-ensure-bus
transport :server! connector address))
(lparallel:force promise))))
((&values bus-1 port-1)
(ensure-bus connector-1))
((&values bus-2 port-2)
(ensure-bus connector-2)))
;; Make sure that both connectors got the same port via their
;; respective "portfile" outputs.
(ensure-same port-1 port-2 :test #'=)
(check-buses-and-connectors
(list bus-1 bus-2) (list connector-1 connector-2)))))
| 12,170 | Common Lisp | .lisp | 235 | 38.987234 | 101 | 0.583333 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 12b1f8c902ff707370ad65d53dc530cce654a93a0480c2df798f2fb774a06775 | 25,229 | [
-1
] |
25,230 | bus.lisp | open-rsx_rsb-cl/test/transport/socket/bus.lisp | ;;;; bus.lisp --- Unit tests for the bus* classes.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.socket.test)
(defun make-socket-connector (class schema address
&rest options &key server? &allow-other-keys)
(let ((connector (apply #'make-instance class
:schema schema
:converter :fundamental-null
:server? server?
(append address
(remove-from-plist options :server?)))))
(when (typep connector 'rsb.transport.socket::in-connector)
(setf (rsb.transport.socket::connector-scope connector)
(make-scope "/rsbtests/transport/socket/bus/")))
connector))
(defun check-bus (bus expected-connections expected-connectors)
(flet ((check-thing (title reader expected)
(etypecase expected
(list
(ensure-same (funcall reader bus) expected
:test (rcurry #'set-equal :test #'eq)))
(number
(let ((num (length (funcall reader bus))))
(ensure-same num expected
:test #'=
:report "~@<Bus was expected to have ~
~D ~(~A~)~:P (not ~D)~:@>"
:arguments (expected title num)))))))
;; Ensure that connections of BUS match EXPECTED-CONNECTIONS.
(check-thing :connection #'bus-connections expected-connections)
;; Ensure that connectors of BUS match EXPECTED-CONNECTORS.
(check-thing :connector #'bus-connectors expected-connectors)))
(defun check-buses-and-connectors (buses connectors
&optional expect-connection?)
(let ((expected-connection-count (if expect-connection? 1 0)))
;; Make sure that both connectors got the same bus server.
(loop :for (bus-1 bus-2) :on buses :do
(check-bus bus-1 expected-connection-count connectors)
(when bus-2
(ensure-same bus-1 bus-2 :test #'eq)))
;; Detach connectors one-by-one and check the resulting state.
(let ((bus (first buses)))
(loop :for (connector . rest) :on connectors :do
(notify connector bus :detached)
(check-bus bus (if rest expected-connection-count 0) rest)))))
| 2,460 | Common Lisp | .lisp | 48 | 38.6875 | 75 | 0.576236 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | c83e967303afd002ec72e5b7575297ce90a3a8ff9732f51adff8400d61f59350 | 25,230 | [
-1
] |
25,231 | connectors.lisp | open-rsx_rsb-cl/test/transport/spread/connectors.lisp | ;;;; connectors.lisp --- Unit tests for connector classes.
;;;;
;;;; Copyright (C) 2012-2019 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.spread.test)
;;; `in-connector' superclass
(deftestsuite in-connector-root (transport-spread-root)
((a-string (octetify "foobarbaz"))
(empty-notification (nth-value 1 (pb:pack (make-instance
'rsb.protocol:notification)))))
(:documentation
"Tests for the `in-connector' class and associated methods."))
(addtest (in-connector-root
:documentation
"Test `notification->event' method.")
notification->event/in-connector
(ensure-cases (payload-data wire-schema connector-args expected)
`(;; In these cases, protocol buffer unpacking fails.
(,a-string "foo" (:error-policy nil) decoding-error)
(,a-string "foo" (:error-policy ,#'continue) nil)
;; Protocol buffer unpacking succeeds, but conversion to event
;; fails.
(,a-string "utf-8-string" () "foobarbaz"))
(let+ ((connector (apply #'make-instance 'in-pull-connector
:converter :fundamental-utf-8-string
(append common-args connector-args)))
(notification (rsb.transport.spread::make-incoming-notification
(a-notification 0 payload-data :wire-schema wire-schema)
payload-data))
((&flet do-it ()
(rsb.ep:with-error-policy (connector)
(notification->event connector notification wire-schema)))))
(case expected
(decoding-error (ensure-condition 'decoding-error (do-it)))
((nil) (ensure-null (do-it)))
(t (ensure-same (event-data (do-it)) expected
:test #'equal))))))
;;; Connector classes
(macrolet
((define-connector-suite (direction)
(let ((class-name (format-symbol :rsb.transport.spread "~A-CONNECTOR" direction))
(suite-name (format-symbol *package* "~A-CONNECTOR-ROOT" direction)))
`(progn
(deftestsuite ,suite-name (transport-spread-root)
()
(:documentation
,(format nil "Test suite for the `~(~A~)' class."
class-name)))
(define-basic-connector-test-cases ,class-name
:initargs common-args
:expected-schemas '(:spread)
:expected-wire-type 'octet-vector
:expected-remote? t
:expected-direction ,(make-keyword direction))
(addtest (,suite-name
:documentation
,(format nil "Test constructing `~(~A~)' instances."
class-name))
construct/invalid
;; Missing :host, :port, :name or :bus initarg.
(ensure-condition 'missing-required-initarg
(make-instance ',class-name :schema :spread
:converter :fundamental-null
:port nil)))
(addtest (,suite-name
:documentation
,(format nil "Test connecting `~(~A~)' instances."
class-name))
connect/soke
(let ((connector (apply #'make-instance ',class-name common-args))
(scope (make-scope "/foo")))
(rsb.ep:notify connector scope :attached)
(rsb.ep:notify connector scope :detached)))))))
(define-connector-suite :out)
(define-connector-suite :in-pull)
(define-connector-suite :in-push))
| 3,899 | Common Lisp | .lisp | 77 | 36.883117 | 88 | 0.536662 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 5f2898bf094835ee7ba8732feda977d615fd9b8c3ee4cbfbc81661a65a01d369 | 25,231 | [
-1
] |
25,232 | package.lisp | open-rsx_rsb-cl/test/transport/spread/package.lisp | ;;;; package.lisp --- Package definition for unit tests of the transport.spread module.
;;;;
;;;; Copyright (C) 2011-2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.transport.spread.test
(:use
#:cl
#:alexandria
#:iterate
#:let-plus
#:more-conditions
#:lift
#:nibbles
#:rsb
#:rsb.transport
#:rsb.transport.spread
#:rsb.test
#:rsb.transport.test)
(:import-from #:rsb.transport.spread
#:normalize-daemon-endpoint
#:*scope->groups-cache*
#:*scope->groups-cache-max-size*
#:make-scope->groups-cache
#:scope->group
#:scope->groups/no-cache
#:scope->groups
#:assembly
#:assembly-complete?
#:assembly-concatenated-data
#:assembly-pool-count
#:merge-fragment
#:assembly-pool
#:pruning-assembly-pool
#:make-notification
#:split-notification
#:message-receiver
#:message-sender
#:connection
#:in-connector
#:in-pull-connector
#:out-connector)
(:documentation
"This package contains unit tests for the transport.spread
module"))
(cl:in-package #:rsb.transport.spread.test)
;;; Root test suite
(deftestsuite transport-spread-root (transport-root)
((spread-port rsb-system::*spread-port*)
common-args)
(:setup
(setf common-args `(:schema :spread
:port ,spread-port
:converter :fundamental-null)))
(:documentation
"Root unit test suite for the transport.spread module."))
;;; Test utilities
(defvar *simple-group-name*
(concatenate 'string "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" '(#\Nul)))
(defun octetify (data)
(etypecase data
(string (sb-ext:string-to-octets data))
(sequence (coerce data 'octet-vector))
(t data)))
(defun a-notification (sequence-number data &key (scope "/foo") wire-schema)
(let ((event-id (make-instance 'rsb.protocol:event-id
:sender-id (uuid:uuid-to-byte-array
(uuid:make-null-uuid))
:sequence-number sequence-number)))
(apply #'make-instance 'rsb.protocol:notification
:scope (octetify scope)
:event-id event-id
:data data
(when wire-schema
(list :wire-schema (octetify wire-schema))))))
(defun a-fragment (sequence-number length id data)
(make-instance 'rsb.protocol:fragmented-notification
:notification (a-notification sequence-number data)
:num-data-parts length
:data-part id))
(defun collect-fragments (generator)
(loop :for fragment = (funcall generator)
:while fragment
:collect fragment))
(defun make-event* (data)
(let ((event (make-event "/foo" (octetify data))))
(setf (event-origin event) (uuid:make-null-uuid)
(event-sequence-number event) 0)
event))
(defun call-with-connection (thunk
&key
port
(name (format nil "~D" port)))
(let ((connection (make-instance 'connection :name name)))
(unwind-protect
(funcall thunk connection)
(detach connection))))
(defmacro with-connection ((connection-var &rest args &key port name)
&body body)
(declare (ignore port name))
`(call-with-connection (lambda (,connection-var) ,@body) ,@args))
| 3,479 | Common Lisp | .lisp | 101 | 27.247525 | 87 | 0.621791 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 66a51f8b8cfb2dc76029b357ca777afe6a519001783c5b7b44488ef6c98b7a90 | 25,232 | [
-1
] |
25,233 | util.lisp | open-rsx_rsb-cl/test/transport/spread/util.lisp | ;;;; util.lisp --- Unit tests for utilities used in the spread backend.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.spread.test)
(deftestsuite util-root (transport-spread-root)
()
(:documentation
"Test suite for the utility functions used in the spread
backend."))
(addtest (util-root
:documentation
"Smoke test for the `normalize-daemon-endpoint' function.")
normalize-daemon-endpoint/smoke
(ensure-cases (name host port
expected-name &optional expected-host expected-port)
'((nil nil nil missing-required-argument)
("4803@host" nil nil "4803@host" "host" 4803)
(nil "host" 4803 "4803@host" "host" 4803)
(nil nil 4803 "4803" nil 4803))
(case expected-name
(missing-required-argument
(ensure-condition missing-required-argument
(normalize-daemon-endpoint name host port)))
(t
(ensure-same (normalize-daemon-endpoint name host port)
(values expected-name expected-host expected-port)
:test #'equal)))))
(addtest (util-root
:documentation
"Smoke test for the `scope->group' function.")
scope->group/smoke
(ensure-cases (string expected)
'(("/" "6666cd76f96956469e7be39d750cc7d")
("/foo/" "4f87be8f6e593d167f5fd1ab238cfc2")
("/foo/bar/" "1c184f3891344400380281315d9e738"))
(let ((result (scope->group (make-scope string))))
(ensure-same result (concatenate 'string expected '(#\Null))
:test #'string=))))
(addtest (util-root
:documentation
"Smoke test for the non-caching variant of the
`scope->groups' function.")
scope->groups/no-cache/smoke
(ensure-cases (scope expected-groups)
'(("/" ("6666cd76f96956469e7be39d750cc7d"))
("/foo" ("6666cd76f96956469e7be39d750cc7d"
"4f87be8f6e593d167f5fd1ab238cfc2"))
("/foo/bar" ("6666cd76f96956469e7be39d750cc7d"
"4f87be8f6e593d167f5fd1ab238cfc2"
"1c184f3891344400380281315d9e738")))
(let ((result (scope->groups/no-cache (make-scope scope)))
(expected (map 'list (lambda (name)
(concatenate 'string name '(#\Null)))
expected-groups)))
(ensure-same result expected
:test #'(rcurry #'set-equal :test #'string=)))))
(addtest (util-root
:documentation
"Smoke test for the `scope->groups' function.")
scope->groups/smoke
(let ((*scope->groups-cache* (make-scope->groups-cache)))
(ensure-cases (scope) '("/" "/foo" "/foo/bar")
(let ((result-1 (scope->groups (make-scope scope :intern? t)))
(result-2 (scope->groups (make-scope scope :intern? t)))
(result-3 (scope->groups (make-scope scope))))
(ensure-same result-1 result-2 :test #'eq)
(ensure-same result-1 result-3 :test #'equal)))))
(addtest (util-root
:documentation
"Test the cache flushing mechanism of the cache used by
`scope->groups'.")
scope->groups/cache-flush
(let ((*scope->groups-cache* (make-scope->groups-cache)))
(iter (repeat (* 10 *scope->groups-cache-max-size*))
(ensure (<= (hash-table-count *scope->groups-cache*)
*scope->groups-cache-max-size*))
(scope->groups (make-scope "/bla/bli/boo"))
(ensure (<= (hash-table-count *scope->groups-cache*)
*scope->groups-cache-max-size*)))))
| 3,679 | Common Lisp | .lisp | 81 | 36.691358 | 71 | 0.607083 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 8e33b604aea898b0b1a544e2593c4c5b620c22231df9c966c40f9e58a30d095e | 25,233 | [
-1
] |
25,234 | sender-receiver.lisp | open-rsx_rsb-cl/test/transport/spread/sender-receiver.lisp | ;;;; sender-receiver.lisp --- Unit tests for message sender/receiver classes.
;;;;
;;;; Copyright (C) 2012-2019 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.spread.test)
;;; `message-receiver'
(deftestsuite message-receiver-root (transport-spread-root)
((a-string (octetify "foobarbaz"))
(empty-notification (nth-value 1 (pb:pack (make-instance
'rsb.protocol:notification)))))
(:documentation
"Tests for the `message-receiver' class and associated methods."))
(addtest (message-receiver-root
:documentation
"Test `notification->event' method.")
notification->event/message-receiver
(ensure-cases (notification wire-schema args expected)
`(;; In these cases, protocol buffer unpacking fails.
(,a-string :foo (:error-policy nil) decoding-error)
(,a-string :foo (:error-policy ,#'continue) nil)
;; Protocol buffer unpacking succeeds, but conversion to event
;; fails.
(,empty-notification :foo (:error-policy nil) decoding-error)
(,empty-notification :foo (:error-policy ,#'continue) nil))
(let+ ((connector (apply #'make-instance 'message-receiver
:connection nil args))
(notification (rsb.transport:make-wire-notification
notification (length notification)))
((&flet do-it ()
(rsb.ep:with-error-policy (connector)
(notification->event connector notification wire-schema)))))
(case expected
(decoding-error (ensure-condition 'decoding-error (do-it)))
((nil) (ensure-null (do-it)))))))
;;; `message-sender'
(deftestsuite message-sender-root (transport-spread-root)
()
(:documentation
"Tests for the `message-sender' class and associated methods."))
(addtest (message-sender-root
:documentation
"Test `event->notification' method.")
event->notification
(let* ((connector (apply #'make-instance 'message-sender
:connection nil '()))
(data (octetify "bar"))
(notification (rsb.transport.spread::make-outgoing-notification
(make-scope "/foo") '() (a-notification 0 data) data)))
(collect-fragments (event->notification connector notification))))
| 2,466 | Common Lisp | .lisp | 50 | 40.56 | 79 | 0.62079 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | ff42fb884e88b7f3fc3450f56288f47979444f2ff8d5e82cfb9a692bc80442cf | 25,234 | [
-1
] |
25,235 | connection.lisp | open-rsx_rsb-cl/test/transport/spread/connection.lisp | ;;;; connection.lisp --- Unit tests for the connection class.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.spread.test)
;;; Utilities
(defun check-connection (connection expected-groups)
(ensure-same (connection-groups connection) expected-groups
:test (rcurry #'set-equal :test #'string=)))
;;; Tests
(deftestsuite spread-connection-root (transport-spread-root)
()
(:documentation
"Unit tests for the `connection' class."))
(addtest (spread-connection-root
:documentation
"Test construction of `connection' instances.")
construct
(let+ ((name (format nil "~D" spread-port))
((&flet connect ()
(network.spread:connect name))))
(ensure-cases (initargs expected)
`(;; Some invalid cases.
(() missing-required-initarg) ; Neither :connection nor :name
((:name "3333@localhost"
:connection ,(connect)) incompatible-initargs) ; Both :connection and :name
;; These are OK.
((:connection ,(connect)) t)
((:name ,name) t))
(let+ (((&flet+ do-it ()
(apply #'make-instance 'connection initargs))))
(case expected
(missing-required-initarg
(ensure-condition 'missing-required-initarg (do-it)))
(incompatible-initargs
(ensure-condition 'incompatible-initargs (do-it)))
(t
(detach (do-it))))))))
(addtest (spread-connection-root
:documentation
"Test printing `connection' instances.")
print
(with-connection (connection :port spread-port)
(ensure (not (emptyp (princ-to-string connection))))))
(addtest (spread-connection-root
:documentation
"Smoke test for `ref-group' and `unref-group' methods.")
ref/unref-group.smoke
(with-connection (connection :port spread-port)
(let ((group *simple-group-name*))
(ensure-same (ref-group connection group) (values 1 1 t))
(check-connection connection (list group))
(ensure-same (ref-group connection group) (values 2 1 nil))
(check-connection connection (list group))
(ensure-same (unref-group connection group) (values 1 1 nil))
(check-connection connection (list group))
(ensure-same (unref-group connection group) (values 0 0 t))
(check-connection connection '())
;; Invalid unreference should signal an error.
(ensure-condition error (unref-group connection group)))))
(addtest (spread-connection-root
:documentation
"Test for `ref-group' and `unref-group' methods in waitable
mode.")
ref/unref-group.waitatble
(with-connection (connection :port spread-port)
(let+ ((group *simple-group-name*)
((&flet ref ()
(ref-group connection group :waitable? t)))
((&flet unref ()
(unref-group connection group :waitable? t))))
(let+ (((&values member-count group-count promise) (ref)))
(ensure-same (values member-count group-count) (values 1 1))
(loop :until (lparallel:fulfilledp promise)
:do (receive-message connection nil)))
(check-connection connection (list group))
(ensure-same (ref) (values 2 1 nil))
(check-connection connection (list group))
(ensure-same (unref) (values 1 1 nil))
(check-connection connection (list group))
;; Make sure the join/leave notification skips unrelated
;; messages.
(let* ((data (octetify "foo"))
(notification (make-wire-notification data (length data))))
(send-message connection (list group) notification))
(let+ (((&values member-count group-count promise) (unref)))
(ensure-same (values member-count group-count) (values 0 0 t))
(loop :until (lparallel:fulfilledp promise)
:do (receive-message connection nil)))
(check-connection connection '()))))
(addtest (spread-connection-root
:documentation
"Roundtrip test for `connenction' class.")
roundtrip
(let ((group "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
(with-connection (sender :port spread-port)
(with-connection (receiver :port spread-port)
;; Join group and wait until it's done.
(lparallel:force (ref-group receiver group :waitable? t))
;; Then send, receive and verify a message.
(ensure-cases (payload-size)
'(3 1000 100000)
(let* ((payload (octetify (make-string payload-size
:initial-element #\b)))
(notification (make-wire-notification payload (length payload))))
(send-message sender (list group) notification)
(let* ((incoming (receive-message receiver t))
(incoming (subseq (wire-notification-buffer incoming)
0 (wire-notification-end incoming))))
(ensure-same incoming payload :test #'equalp))))))))
| 5,157 | Common Lisp | .lisp | 111 | 37.720721 | 98 | 0.621788 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | ce0485fa3866e87d79621c03fef2e5c47f99a1a32d2976d031ad979c69dc1ecb | 25,235 | [
-1
] |
25,236 | fragmentation.lisp | open-rsx_rsb-cl/test/transport/spread/fragmentation.lisp | ;;;; fragmentation.lisp --- Unit test for fragmentation/assembly.
;;;;
;;;; Copyright (C) 2011-2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transport.spread.test)
(deftestsuite fragmentation-root (transport-spread-root)
()
(:documentation
"Unit tests for the fragmentation and assembly of
data/notifications."))
(addtest (fragmentation-root
:documentation
"Smoke test for the `merge-fragment' with an `assembly-pool'
instance.")
assemble-smoke
(ensure-cases (sequence-number num-parts parts part-ids expected)
`((0
5
("foo" "bar" "baz" "a" "b")
(0 1 2 3 4)
"foobarbazab")
(1
2
("foo" "baz" "foo" "a" "bar")
(0 5 0 2 1)
"foobar"))
;; We repeat the assembly for all permutation of the fragments.
(let ((fragments (iter (for part in parts)
(for i in part-ids)
(collect (a-fragment
sequence-number num-parts i (octetify part))))))
(map-permutations
(lambda (permutation)
(let* ((pool (make-instance 'assembly-pool))
(returns (map 'list (curry #'merge-fragment pool)
permutation))
(assembly (find-if (complement #'null) returns))
(result (assembly-concatenated-data assembly)))
(ensure (assembly-complete? assembly))
(ensure-same result (octetify expected)
:test #'equalp)))
fragments))))
(addtest (fragmentation-root
:documentation
"Smoke test for the `split-notification' function.")
fragment-smoke
(ensure-cases (data fragment-size-limit &optional expected)
`(("" 90)
("foobarbazfezwhoop" 85)
("foobarbazb" 88)
("fooobaar" 89)
(,(make-string 1000) 100)
("" 20 insufficient-room)
("bla" 20 insufficient-room))
(let+ ((notification (make-notification
0 (uuid:make-null-uuid) (rsb:make-scope "/foo")
nil :utf-8-string '() `(:create ,(local-time:now))))
((&flet do-it ()
(collect-fragments (split-notification
notification (octetify data)
fragment-size-limit)))))
(case expected
(insufficient-room
(ensure-condition 'insufficient-room (do-it)))
(t
(ensure (every (compose (rcurry #'<= fragment-size-limit)
#'pb:packed-size)
(do-it))))))))
(addtest (fragmentation-root
:documentation
"Do full roundtrips of fragmenting data using
`split-notification' and then re-assemble the fragments
using `merge-fragments'.")
roundtrip
(ensure-cases (data fragment-size-limit)
`(("" 90)
("foobarbazfezwhoop" 85)
("foobarbazb" 88)
("fooobaar" 89)
(,(make-string 1000) 100))
(let* ((notification (make-notification
0 (uuid:make-null-uuid) (rsb:make-scope "/foo")
nil :utf-8-string '() `(:create ,(local-time:now))))
(notifications (collect-fragments
(split-notification
notification (octetify data)
fragment-size-limit)))
(pool (make-instance 'assembly-pool))
(result (assembly-concatenated-data
(lastcar (map 'list (curry #'merge-fragment pool)
(shuffle notifications))))))
(ensure-same (octetify data) result
:test #'equalp))))
(addtest (fragmentation-root
:documentation
"Ensure that warnings are signaled when invalid fragments
are added to an assembly.")
warnings
(let ((sequence-number 0)
(pool (make-instance 'assembly-pool)))
(merge-fragment pool (a-fragment
sequence-number 3 0 (octetify "foo")))
(ensure-condition 'invalid-fragment-id
(merge-fragment pool (a-fragment
sequence-number 3 5 (octetify "foo"))))
(ensure-condition 'duplicate-fragment
(merge-fragment pool (a-fragment
sequence-number 3 0 (octetify "foo"))))))
(deftestsuite assembly-root (fragmentation-root)
()
(:documentation
"Unit tests for the `assembly' class."))
(addtest (assembly-root
:documentation
"Test `print-object' method on `assembly'.")
print-smoke
(ensure (not (emptyp
(princ-to-string
(make-instance 'assembly
:id (cons 0 (uuid:uuid-to-byte-array
(uuid:make-null-uuid)))
:num-fragments 1))))))
(deftestsuite assembly-pool-root (fragmentation-root)
()
(:documentation
"Unit tests for the `assembly-pool' class."))
(addtest (assembly-pool-root
:documentation
"Test `print-object' method on `assembly-pool'.")
print-smoke
(ensure (not (emptyp (princ-to-string
(make-instance 'assembly-pool))))))
(deftestsuite pruning-assembly-pool-root (fragmentation-root)
()
(:documentation
"Unit tests for the `pruning-assembly-pool' class."))
(addtest (pruning-assembly-pool-root
:documentation
"Check that old incomplete assemblies actually get pruned.")
prune
(let ((pool (make-instance 'pruning-assembly-pool
:age-limit 1)))
(merge-fragment pool (a-fragment 0 2 0 (octetify "bla")))
(let ((count (assembly-pool-count pool)))
(ensure-same
count 1
:test #'=
:report "~@<After submitting a fragment, the count of the pool ~
was ~D, not ~D.~@:>"
:arguments (count 1)))
(sleep 2)
(let ((count (assembly-pool-count pool)))
(ensure-same
count 0
:test #'=
:report "~@<After submitting a fragment and waiting for it to ~
get pruned, the count of the pool was ~D, not ~D.~@:>"
:arguments (count 0)))))
(addtest (pruning-assembly-pool-root
:documentation
"Test `print-object' method on `pruning-assembly-pool'.")
print-smoke
(ensure (not (emptyp (princ-to-string
(make-instance 'pruning-assembly-pool))))))
| 6,799 | Common Lisp | .lisp | 165 | 30.006061 | 85 | 0.541768 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | acc31b8e64f3a6845f19f3993cadb0cfbe28d1c615703d1b4a72350f156899dd | 25,236 | [
-1
] |
25,237 | package.lisp | open-rsx_rsb-cl/test/model/package.lisp | ;;;; package.lisp --- Package definition for unit tests of the model module.
;;;;
;;;; Copyright (C) 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.model.test
(:use
#:cl
#:alexandria
#:let-plus
#:iterate
#:more-conditions
#:lift
#:rsb
#:rsb.model
#:rsb.test)
(:import-from #:rsb.model
#:basic-participant-node
#:basic-process-node
#:basic-host-node)
;; Root test suite
(:export
#:rsb-model-root)
(:documentation
"This package contains unit tests for the model module."))
(cl:in-package #:rsb.model.test)
;;; Test suite
(deftestsuite rsb-model-root (root)
()
(:documentation
"Root unit test suite of the model module."))
| 749 | Common Lisp | .lisp | 31 | 20.903226 | 76 | 0.676096 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | e1aee010d9c02dfac7a31e7e32d5bb01b7740c40485700d6d59481b1bef6f667 | 25,237 | [
-1
] |
25,238 | builder.lisp | open-rsx_rsb-cl/test/model/builder.lisp | ;;;; builder.lisp --- Tests for model (un)builder.
;;;;
;;;; Copyright (C) 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.model.builder.test
(:use
#:cl
#:let-plus
#:lift
#:rsb
#:rsb.model)
(:local-nicknames
(#:bp #:architecture.builder-protocol))
(:import-from #:rsb.model
#:basic-participant-node
#:basic-process-node
#:basic-host-node)
(:import-from #:architecture.builder-protocol.test
#:record-un-build-calls/peeking)
(:export
#:rsb-model-builder-root)
(:documentation
"This package contains test for the model.builder module."))
(cl:in-package #:rsb.model.builder.test)
(deftestsuite rsb-model-builder-root ()
()
(:documentation
"Unit test suite for the model (un)builder support."))
(defvar *stop-type* '(or number string uuid:uuid puri:uri scope))
(defun check-un-build-calls (builder atom-type cases)
(mapc (lambda+ ((object expected-calls))
(let+ (((&values &ign calls)
(record-un-build-calls/peeking
#'bp:walk-nodes builder atom-type object)))
(ensure-same calls expected-calls :test #'equal)))
cases))
(let* ((id (uuid:make-null-uuid))
(scope (make-scope "/" :intern? t))
(transport-uri (puri:uri "socket://foo"))
(initargs `(:kind :listener
:id ,id
:scope ,scope
:type t)))
(addtest (rsb-model-builder-root)
participant-info/smoke
(check-un-build-calls
t *stop-type*
`(,(let ((info (apply #'make-instance 'participant-info
:transports (list transport-uri)
initargs)))
`(,info ((:peek nil () ,info)
(:visit nil () ,info :participant ((:transports . *)) ,initargs)
(:peek :transports () ,transport-uri)))))))
(addtest (rsb-model-builder-root)
participant-node/smoke
(check-un-build-calls
t *stop-type*
`(,(let* ((info (apply #'make-instance 'participant-info
:transports (list transport-uri)
initargs))
(node (make-instance 'basic-participant-node :info info)))
`(,node ((:peek nil () ,node)
(:visit nil () ,node :participant ((:children . *)
(:transports . *))
,initargs)
(:peek :transports () ,transport-uri))))))))
(let* ((start-time (local-time:now))
(commandline-arguments '("a" "b"))
(transport "socket://foo")
(initargs `(:process-id 0
:program-name "foo"
:start-time ,start-time
:executing-user "user"
:rsb-version "1.2.3"
:display-name "Foo")))
(addtest (rsb-model-builder-root)
process-info/smoke
(check-un-build-calls
t *stop-type*
`(,(let ((info (apply #'make-instance 'process-info
:commandline-arguments commandline-arguments
initargs)))
`(,info ((:peek nil () ,info)
(:visit nil () ,info :process ((:commandline-arguments . *))
,initargs)
,@(mapcar (lambda (x) `(:peek :commandline-arguments () ,x))
commandline-arguments)))))))
(addtest (rsb-model-builder-root)
remote-process-info/smoke
(check-un-build-calls
t *stop-type*
`(,(let ((info (apply #'make-instance 'remote-process-info
:commandline-arguments commandline-arguments
:state :running
:transports (list transport)
initargs)))
`(,info ((:peek nil () ,info)
(:visit nil () ,info :process ((:transports . *)
(:commandline-arguments . *))
( :state :running ,@initargs))
(:peek :transports () ,transport)
,@(mapcar (lambda (x) `(:peek :commandline-arguments () ,x))
commandline-arguments)))))))
(addtest (rsb-model-builder-root)
process-node/smoke
(check-un-build-calls
t *stop-type*
`(,(let* ((info (apply #'make-instance 'process-info
:commandline-arguments commandline-arguments
initargs))
(node (make-instance 'basic-process-node :info info)))
`(,node ((:peek nil () ,node)
(:visit nil () ,node :process ((:children . *)
(:commandline-arguments . *))
,initargs)
,@(mapcar (lambda (x) `(:peek :commandline-arguments () ,x))
commandline-arguments))))))))
(let ((initargs '(:id "1"
:hostname "foo"
:machine-type "mt"
:machine-version "mv"
:software-type "st"
:software-version "sv")))
(addtest (rsb-model-builder-root)
host-info/smoke
(check-un-build-calls
t *stop-type*
`(,(let ((info (apply #'make-instance 'host-info initargs)))
`(,info ((:peek nil () ,info)
(:visit nil () ,info :host () ,initargs)))))))
(addtest (rsb-model-builder-root)
remote-host-info/smoke
(check-un-build-calls
t *stop-type*
`(,(let ((info (apply #'make-instance 'remote-host-info
:state :up initargs)))
`(,info ((:peek nil () ,info)
(:visit nil () ,info :host () (:state :up ,@initargs))))))))
(addtest (rsb-model-builder-root)
host-node/smoke
(check-un-build-calls
t *stop-type*
`(,(let* ((info (apply #'make-instance 'host-info initargs))
(node (make-instance 'basic-host-node :info info)))
`(,node ((:peek nil () ,node)
(:visit nil () ,node :host ((:children . *))
,initargs))))))))
| 6,605 | Common Lisp | .lisp | 148 | 31.108108 | 91 | 0.480859 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 6769116bf1654f7778bf74c41cd938f328cbee439471077a089b77c70e1430d4 | 25,238 | [
-1
] |
25,239 | classes.lisp | open-rsx_rsb-cl/test/model/classes.lisp | ;;;; classes.lisp --- Tests for model classes.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.model.test)
(deftestsuite rsb-model-classes-root (rsb-model-root)
()
(:documentation
"Unit test suite for the model classes."))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defmacro define-simple-model-class-tests (class-and-options &body cases)
(let+ (((class &key (suite-prefix '#:rsb-model-classes-))
(ensure-list class-and-options))
(parent-suite-name (symbolicate suite-prefix '#:root))
(suite-name (symbolicate suite-prefix class '#:-root)))
`(progn
(deftestsuite ,suite-name (,parent-suite-name)
()
(:documentation
,(format nil "Unit test suite for the `~(~A~)' model class."
class)))
(addtest (,suite-name
:documentation
,(format nil "Test constructing `~(~A~)' instances."
class))
construct
(ensure-cases (initargs &optional expected-result expected-printed)
(list ,@cases)
(let+ (((&flet do-it ()
(apply #'make-instance ',class initargs))))
(case expected-result
(missing-required-initarg
(ensure-condition missing-required-initarg (do-it)))
(t
(do-it))))))
(addtest (,suite-name
:documentation
,(format nil "Test printing `~(~A~)' instances." class))
print
(ensure-cases (initargs &optional expected-result (expected-printed t))
(list ,@cases)
(let+ (((&flet do-it ()
(princ-to-string (apply #'make-instance ',class initargs)))))
(cond
((eq expected-result 'missing-required-initarg))
((eq expected-printed t)
(do-it))
(t
(ensure-same (do-it) expected-printed
:test (lambda (x y) (search y x))))))))))))
;;; `participant-info' classes
(define-simple-model-class-tests participant-info
;; Missing required initargs.
`((:id ,(uuid:make-null-uuid)
:scope ,(make-scope "/foo")
:type "bar")
missing-required-initarg)
`((:kind :lintener
:scope ,(make-scope "/foo")
:type "bar")
missing-required-initarg)
`((:kind :lintener
:id ,(uuid:make-null-uuid)
:type "bar")
missing-required-initarg)
`((:kind :lintener
:id ,(uuid:make-null-uuid)
:scope ,(make-scope "/foo"))
missing-required-initarg)
;; These are OK.
`((:kind :listener
:id ,(uuid:make-null-uuid)
:scope ,(make-scope "/foo")
:type "bar")
t "LISTENER /foo/ (T 0) 00000000")
`((:kind :listener
:id ,(uuid:make-null-uuid)
:parent-id ,(uuid:make-null-uuid)
:scope ,(make-scope "/foo")
:type "bar")
t "LISTENER /foo/ (T 0) 00000000")
`((:kind :listener
:id ,(uuid:make-null-uuid)
:scope ,(make-scope "/foo")
:type "bar"
:transports ,(list (puri:uri "socket:/foo")))
t "LISTENER /foo/ (T 1) 00000000"))
;;; `process-info' classes
(define-simple-model-class-tests process-info
;; Missing required initargs.
'((:process-id 20) missing-required-initarg)
'((:program-name "foo") missing-required-initarg)
;; These are OK.
`((:process-id 20
:program-name "foo")
t "foo[20]")
`((:process-id 20
:program-name "foo"
:start-time ,(local-time:now))
t "foo[20]")
'((:process-id 20
:program-name "foo"
:executing-user "john")
t "foo[20]")
'((:process-id 20
:program-name "foo"
:rsb-version "0.11")
t "foo[20]")
'((:process-id 20
:program-name "foo"
:display-name "bar")
t "bar(foo)[20]"))
(define-simple-model-class-tests remote-process-info
;; Missing required initargs.
'((:process-id 1 :program-name "foo") missing-required-initarg)
;; These are OK.
'((:process-id 1
:program-name "foo"
:transports ())
t "foo[1] UNKNOWN")
'((:process-id 20
:program-name "foo"
:state :crashed
:transports ())
t "foo[20] CRASHED")
`((:process-id 20
:program-name "foo"
:transports (,(puri:uri "socket://localhost:12345"))
:state :running
:start-time ,(local-time:now))
t "foo[20] RUNNING"))
;;; `host-info' classes
(define-simple-model-class-tests host-info
;; Missing required initargs.
'((:id "foo") missing-required-initarg)
'((:hostname "bar") missing-required-initarg)
;; These are OK.
'((:id "foo" :hostname "bar") t "bar ? ?")
'((:id "foo" :hostname "bar" :machine-type "x86") t "bar x86 ?")
'((:id "foo" :hostname "bar" :machine-version "foo") t "bar ? ?")
'((:id "foo" :hostname "bar" :software-type "linux") t "bar ? linux")
'((:id "foo" :hostname "bar" :software-version "3.16.30") t "bar ? ?"))
(define-simple-model-class-tests remote-host-info
;; These are OK.
'((:id "foo"
:hostname "bar"
:clock-offset 0.000001)
t "bar ? ? UNKNOWN")
'((:id "foo"
:hostname "bar"
:state :up
:clock-offset 0.000001)
t "bar ? ? UP")
'((:id "foo"
:hostname "bar"
:state :up
:clock-offset 0.002)
t "bar ? ? UP +0.002 s"))
;;; Node classes
(defvar *simple-participant-info*
(make-instance 'participant-info
:kind :listener
:id (uuid:make-null-uuid)
:scope "/foo"
:type t))
(define-simple-model-class-tests basic-participant-node
;; Missing required initargs
'(() missing-required-initarg)
;; These are OK.
`((:info ,*simple-participant-info*)
t "LISTENER /foo/ (T 0) (C 0) 00000000")
`((:info ,*simple-participant-info*
:children ,(list *simple-participant-info*))
t "LISTENER /foo/ (T 0) (C 1) 00000000"))
(defvar *simple-process-info*
(make-instance 'process-info
:process-id 5
:program-name "foo"))
(defvar *remote-process-info*
(make-instance 'remote-process-info
:process-id 5
:program-name "foo"
:transports '()))
(define-simple-model-class-tests basic-process-node
;; Missing required initargs
'(() missing-required-initarg)
;; These are OK.
`((:info ,*simple-process-info*)
t "foo[5] (C 0)")
`((:info ,*simple-process-info*
:children ,(list *simple-participant-info*))
t "foo[5] (C 1)")
`((:info ,*remote-process-info*)
t "foo[5] (C 0) UNKNOWN")
`((:info ,*remote-process-info*
:children ,(list *simple-participant-info*))
t "foo[5] (C 1) UNKNOWN"))
(defvar *simple-host-info*
(make-instance 'host-info
:id "bar"
:hostname "foo"))
(defvar *remote-host-info*
(make-instance 'remote-host-info
:id "bar"
:hostname "foo"
:state :up))
(define-simple-model-class-tests basic-host-node
;; Missing required initargs
'(() missing-required-initarg)
;; These are OK.
`((:info ,*simple-host-info*)
t "foo ? ? (C 0)")
`((:info ,*simple-host-info*
:children ,(list *simple-process-info*))
t "foo ? ? (C 1)")
`((:info ,*remote-host-info*)
t "foo ? ? (C 0) UP")
`((:info ,*remote-host-info*
:children ,(list *simple-process-info*))
t "foo ? ? (C 1) UP"))
| 7,950 | Common Lisp | .lisp | 221 | 28.868778 | 85 | 0.53926 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 34a21dbe6d50d3c9fdc8388ba12473417f07a082d42d53307632d972db5025cb | 25,239 | [
-1
] |
25,240 | package.lisp | open-rsx_rsb-cl/test/model/inference/package.lisp | ;;;; package.lisp --- Package definition for unit tests of the model.inference module.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.model.inference.test
(:use
#:cl
#:alexandria
#:let-plus
#:iterate
#:more-conditions
#:lift
#:rsb.model
#:rsb.model.inference
#:rsb.test)
(:import-from #:rsb
#:make-scope)
(:import-from #:rsb.model
#:basic-participant-node
#:basic-process-node
#:basic-host-node)
(:import-from #:rsb.model.inference
#:tri-and #:tri-or)
;; Root test suite
(:export
#:rsb-model-inference-root)
(:documentation
"This package contains unit tests for the introspection module."))
(cl:in-package #:rsb.model.inference.test)
;;; Test suite
(deftestsuite rsb-model-inference-root (rsb-model-root)
()
(:documentation
"Root unit test suite of the model.inference module."))
| 951 | Common Lisp | .lisp | 35 | 23.828571 | 86 | 0.693245 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 6122efa6ae31fcb54b10a8ecf8ee87b160bb7527dbc4e504d0ee6d3dbedacf12 | 25,240 | [
-1
] |
25,241 | util.lisp | open-rsx_rsb-cl/test/model/inference/util.lisp | ;;;; util.lisp --- Tests for the utilities used in the model.inference module.
;;;;
;;;; Copyright (C) 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.model.inference.test)
(addtest (rsb-model-inference-root
:documentation
"Smoke test for the `tri-and' macro.")
tri-and/smoke
(%call-with-tri-test-cases
(lambda (left left-definitive? right right-definitive?)
(tri-and (values left left-definitive?)
(values right right-definitive?)))
'(((nil nil) (nil nil) (nil nil))
((nil nil) (nil t ) (nil t ))
((nil nil) (t nil) incompatible-arguments)
((nil nil) (t t ) (nil nil))
((nil t ) (nil nil) (nil t ))
((nil t ) (nil t ) (nil t ))
;; Would be an error but short-circuited.
;; ((nil t ) (t nil) incompatible-arguments)
((nil t ) (t t ) (nil t ))
((t nil) (nil nil) incompatible-arguments)
((t nil) (nil t ) incompatible-arguments)
((t nil) (t nil) incompatible-arguments)
((t nil) (t t) incompatible-arguments)
((t t ) (nil nil) (nil nil))
((t t ) (nil t ) (nil t ))
((t t ) (t nil) incompatible-arguments)
((t t ) (t t ) (t t )))))
(addtest (rsb-model-inference-root
:documentation
"Smoke test for the `tri-or' macro.")
tri-or/smoke
(%call-with-tri-test-cases
(lambda (left left-definitive? right right-definitive?)
(tri-or (values left left-definitive?)
(values right right-definitive?)))
'(((nil nil) (nil nil) (nil nil))
((nil nil) (nil t ) (nil nil))
((nil nil) (t nil) incompatible-arguments)
((nil nil) (t t ) (t t ))
((nil t ) (nil nil) (nil nil))
((nil t ) (nil t ) (nil t ))
((nil t ) (t nil) incompatible-arguments)
((nil t ) (t t ) (t t ))
((t nil) (nil nil) incompatible-arguments)
((t nil) (nil t ) incompatible-arguments)
((t nil) (t nil) incompatible-arguments)
((t nil) (t t) incompatible-arguments)
((t t ) (nil nil) (t t ))
((t t ) (nil t ) (t t ))
;; Would be an error but short-circuited.
;; ((t t ) (t nil) incompatible-arguments)
((t t ) (t t ) (t t )))))
;;; Utilities
(defun %call-with-tri-test-cases (function cases)
(ensure-cases (((left left-definitive?) (right right-definitive?)
expected))
cases
(flet ((do-it ()
(multiple-value-list
(funcall function
left left-definitive?
right right-definitive?))))
(case expected
(incompatible-arguments
(ensure-condition 'incompatible-arguments (do-it)))
(t
(ensure-same expected (do-it) :test #'equal))))))
| 2,860 | Common Lisp | .lisp | 71 | 33.549296 | 78 | 0.549605 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 1ffe9492906993f67a9247ea62f4ece17c10ed9c8fdf7c997a1af41270e9a85a | 25,241 | [
-1
] |
25,242 | inference.lisp | open-rsx_rsb-cl/test/model/inference/inference.lisp | ;;;; inference.lisp --- Tests for the inference functions provided by the model.inference module.
;;;;
;;;; Copyright (C) 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.model.inference.test)
;;; Utilities
(defun make-participant-info (kind scope transports)
(make-instance 'participant-info
:kind kind
:id (uuid:make-v1-uuid)
:scope scope
:transports (mapcar #'puri:uri transports)
:type t))
(defun make-participant-node (info &rest children)
(make-instance 'basic-participant-node
:info (apply #'make-participant-info info)
:children (mapcar (curry #'apply #'make-participant-node)
children)))
(defun+ check-communication?-cases
(from to (expected-result expected-definitive? expected-uris))
(let+ ((expected-uris (mapcar (lambda+ ((left . right))
(cons (puri:uri left) (puri:uri right)))
expected-uris))
((&values result definitive? uris)
(communication? from to))
((&flet uri-pairs-set-equal (left right)
(set-equal left right
:test (lambda+ ((from-left . to-left)
(from-right . to-right))
(and (puri:uri= from-left from-right)
(puri:uri= to-left to-right)))))))
(ensure-same result expected-result)
(ensure-same definitive? expected-definitive?)
(ensure-same uris expected-uris :test #'uri-pairs-set-equal)))
;;; `communication?'
(deftestsuite rsb-model-inference-communication?-root
(rsb-model-inference-root)
()
(:documentation
"Root unit test suite for the `communication?' generic function."))
(addtest (rsb-model-inference-communication?-root
:documentation
"Smoke test for the `communication?' generic function
focusing on scope and URI inputs.")
smoke/scope+uri
(ensure-cases (from to expected)
`(;; Scopes
(,(make-scope "/foo") ,(make-scope "/foo") (t t ()))
(,(make-scope "/foo") ,(make-scope "/bar") (nil t ()))
(,(make-scope "/foo") ,(make-scope "/foo/bar") (nil nil ()))
;; URIs
(,(puri:uri "socket:/foo") ,(puri:uri "socket:/foo") (t t ()))
(,(puri:uri "socket:/foo") ,(puri:uri "socket:/bar") (nil t ()))
(,(puri:uri "socket:/foo") ,(puri:uri "socket:/foo/bar") (nil nil ()))
(,(puri:uri "socket:/foo") ,(puri:uri "socket://baz/foo") (nil t ()))
(,(puri:uri "socket:/foo") ,(puri:uri "socket://baz/bar") (nil t ()))
(,(puri:uri "socket:/foo") ,(puri:uri "socket://baz/foo/bar") (nil t ()))
(,(puri:uri "socket:/foo") ,(puri:uri "spread:/foo") (nil t ()))
(,(puri:uri "socket:/foo") ,(puri:uri "spread:/bar") (nil t ()))
(,(puri:uri "socket:/foo") ,(puri:uri "spread:/foo/bar") (nil t ()))
;; Mixed
(,(puri:uri "/foo") ,(make-scope "/foo") (nil nil ()))
(,(puri:uri "/foo") ,(make-scope "/bar") (nil t ()))
(,(puri:uri "/foo") ,(make-scope "/foo/bar") (nil nil ()))
(,(make-scope "/foo") ,(puri:uri "/foo") (nil nil ()))
(,(make-scope "/foo") ,(puri:uri "/bar") (nil t ()))
(,(make-scope "/foo") ,(puri:uri "/foo/bar") (nil nil ())))
(check-communication?-cases from to expected)))
(addtest (rsb-model-inference-communication?-root
:documentation
"Smoke test for the `communication?' generic function
focusing on `participant-info' inputs.")
smoke/participant-info
(ensure-cases (from to expected)
`(;; Kinds that do not communicate.
((:listener "/foo" ("socket:")) (:listener "/foo" ("socket:"))
(nil t ()))
((:informer "/foo" ("socket:")) (:informer "/foo" ("socket:"))
(nil t ()))
((:listener "/foo" ("socket:")) (:informer "/foo" ("socket:"))
(nil t ()))
;; informer -> listener
((:informer "/foo" ("socket:")) (:listener "/foo" ("spread:"))
(nil t ()))
((:informer "/foo" ("socket:")) (:listener "/bar" ("socket:"))
(nil t ()))
((:informer "/foo" ("socket:")) (:listener "/foo/bar" ("socket:"))
(nil nil (("socket:" . "socket:"))))
((:informer "/foo" ("socket:")) (:listener "/foo" ("socket:"))
(t t (("socket:" . "socket:"))))
;; remote-method <-> local-method
((:remote-method "/foo" ("socket:")) (:local-method "/bar" ("socket:"))
(nil t ()))
((:remote-method "/foo" ("socket:")) (:local-method "/foo/bar" ("socket:"))
(nil t ()))
((:remote-method "/foo" ("socket:")) (:local-method "/foo" ("socket:"))
(t t (("socket:" . "socket:"))))
((:local-method "/foo" ("socket:")) (:remote-method "/bar" ("socket:"))
(nil t ()))
((:local-method "/foo" ("socket:")) (:remote-method "/foo/bar" ("socket:"))
(nil t ()))
((:local-method "/foo" ("socket:")) (:remote-method "/foo" ("socket:"))
(t t (("socket:" . "socket:"))))
;; Multiple transports
((:informer "/foo" ("socket:" "spread:" "inprocess:"))
(:listener "/foo" ("socket://localhost:40" "spread:" "inprocess:"))
(t t (("spread:" . "spread:") ("inprocess:" . "inprocess:"))))
;; No transports.
((:informer "/foo" ()) (:listener "/foo" ()) (t t ())))
(let ((from (apply #'make-participant-info from))
(to (apply #'make-participant-info to)))
(check-communication?-cases from to expected))))
(addtest (rsb-model-inference-communication?-root
:documentation
"Smoke test for the `communication?' generic function
focusing on node inputs.")
smoke/nodes
(ensure-cases (from to expected)
'(;; Unknown participant kind.
(((:some-participant "/foo" ("socket:")))
((:some-participant "/bar" ("socket:")))
(nil nil ()))
;; Unknown participant kind with children.
(((:some-participant "/foo" ("socket:"))
((:informer "/foo" ("socket:"))))
((:some-participant "/bar" ("socket:"))
((:listener "/foo" ("socket:"))))
(t t (("socket:" . "socket:"))))
;; Same with multiple children and transports.
(((:some-participant "/foo" ("socket:" "spread:"))
((:informer "/foo" ("socket:" "spread:")))
((:informer "/bar" ("socket:" "spread:"))))
((:some-participant "/bar" ("spread:" "socket:"))
((:listener "/foo" ("spread:" "socket:")))
((:listener "/bar/baz" ("spread:" "socket:"))))
(t t (("socket:" . "socket:") ("spread:" . "spread:"))))
;; Local- and remote-server.
(((:remote-server "/foo" ("socket:"))
((:remote-method "/foo/bar" ("socket:"))))
((:local-server "/foo" ("socket:"))
((:local-method "/foo/bar" ("socket:"))))
(t t (("socket:" . "socket:")))))
(let ((from (apply #'make-participant-node from))
(to (apply #'make-participant-node to)))
(check-communication?-cases from to expected))))
| 7,589 | Common Lisp | .lisp | 146 | 42.287671 | 97 | 0.508358 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | b2dab16a95f498ecd99aea1a7f609bf218209c8c573765570a51c7bd690f40de | 25,242 | [
-1
] |
25,243 | informer.lisp | open-rsx_rsb-cl/examples/informer.lisp | ;;;; informer.lisp --- An example program demonstrating the informer.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
;; mark-start::body
;; For managing the lifetime of informers (e.g. for short-lived
;; informers), the `with-participant' macro can used. It will take
;; care of disposing of the `informer' instance after it has been
;; used, also in case of non-local exist.
;; mark-start::with-participant
(rsb:with-participant (informer :informer "/example/informer"
:type 'string)
(format t "Sending first event~%")
(rsb:send informer "example payload"))
;; mark-end::with-participant
;; The following code will create an `informer' instance that
;; publishes events to the channel designated by the scope
;; "/example/informer" and is restricted to event payloads of type
;; string. The informer will use all transports which are enabled in
;; the configuration with their respective configured options.
;;
;; This will publish the string "data" to the channel in which the
;; informer participates.
;;
;; mark-start::variable
(defvar *informer* (rsb:make-participant :informer "/example/informer"
:type 'string))
(format t "Sending second event~%")
(rsb:send *informer* "example payload")
;; The informer will participate in the channel until it is garbage
;; collected or explicitly detached using the `rsb:detach' function.
(rsb:detach *informer*)
;; mark-end::variable
;; mark-end::body
| 1,565 | Common Lisp | .lisp | 35 | 41.342857 | 70 | 0.718504 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 9e9deacf773947e10bc752ec937f865e7f238b0823a6c2fd0cc0e973e90fd307 | 25,243 | [
-1
] |
25,244 | reader.lisp | open-rsx_rsb-cl/examples/reader.lisp | ;;;; reader.lisp --- An example program demonstrating the reader.
;;;;
;;;; Copyright (C) 2011-2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
;;;; Loading this file does not terminate.
;; mark-start::body
;; For managing the lifetime of readers (e.g. for short-lived
;; readers), the `with-participant' macro can used. It will take care
;; of disposing of the `reader' instance after it has been used, also
;; in case of non-local exist.
;;
;; Note: this form will block until an event is received.
;; mark-start::with-participant
(rsb:with-participant (reader :reader "/example/informer")
(let ((event (rsb.patterns.reader:receive reader)))
(format t "Received event: ~A~%" event)
event)) ; return the event
;; mark-end::with-participant
;; This will create a `reader' instance that receives events which are
;; sent to the channel designated by the scope "/example/reader". The
;; reader will use all transports which are enabled in the
;; configuration with their respective configured options.
;;
;; Note: the `receive' call will block until an event is received.
;;
;; mark-start::variable
(defvar *reader* (rsb:make-participant :reader "/example/informer"))
;; mark-start::receive/block
(let ((event (rsb.patterns.reader:receive *reader* :block? t))) ; block? defaults to t
(format t "Received event: ~A~%" event)
event) ; return the event
;; mark-end::receive/block
;; It is also possible to use `rsb.patterns.reader:receive' in a
;; non-blocking mode. In that case, an `event' or nil is returned.
;; mark-start::receive/noblock
(let ((event (rsb.patterns.reader:receive *reader* :block? nil)))
(format t "~:[Did not receive an event~;Received event: ~:*~A~]~%"
event)
event) ; return the event, or nil
;; mark-end::receive/noblock
;; The reader will participate in the channel until it is garbage
;; collected or explicitly detached using the `rsb:detach' function.
(rsb:detach *reader*)
;; mark-end::variable
;; mark-end::body
| 2,010 | Common Lisp | .lisp | 46 | 41.913043 | 86 | 0.725971 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 7cd736ba7f229013bf885565f09ca8b7dfaa816feffe8e9afe87b87739d8796b | 25,244 | [
-1
] |
25,245 | listener.lisp | open-rsx_rsb-cl/examples/listener.lisp | ;;;; informer.lisp --- An example program demonstrating the listener.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
;; mark-start::body
;; For managing the lifetime of listeners (e.g. for short-lived
;; listeners), the `with-participant' macro can used. It will take care
;; of disposing of the `listener' instance after it has been used,
;; also in case of non-local exist.
;;
;; To register a handler with limited lifetime, the `with-handler'
;; macro can be used.
;; mark-start::with-participant
(rsb:with-participant (listener :listener "/example/informer")
(rsb:with-handler listener
((event)
(format t "Received event: ~A~%" event))
(format t "Waiting for events~%")
(sleep 20)))
;; mark-end::with-participant
;; This will create a `listener' instance that receives events which
;; are sent to the channel designated by the scope
;; "/example/listener". The listener will use all transports which are
;; enabled in the configuration with their respective configured
;; options.
;;
;; mark-start::variable
(defvar *listener* (rsb:make-participant :listener "/example/informer"))
;; Just after creation, the listener will not act upon received
;; events. In order to process received events, handlers have to be
;; added to the listener. A handler is a function of one argument, the
;; event.
(push (lambda (event)
(format t "Received event: ~A~%" event))
(rsb.ep:handlers *listener*))
;; The listener will participate in the channel until it is garbage
;; collected or explicitly detached using the `rsb:detach' function.
(rsb:detach *listener*)
;; mark-end::variable
;; In order to be notified about and react on event receiving errors,
;; additional error handlers can to be registered.
(rsb:with-participant (listener :listener "/example/informer")
(push (lambda (condition)
(format t "Error: ~A~%" condition))
(hooks:hook-handlers (rsb:participant-error-hook listener))))
;; mark-end::body
| 2,051 | Common Lisp | .lisp | 47 | 41.255319 | 72 | 0.729459 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 3f40a77ab0541a6c644b1bfd7feb13d15ea1982bafc2d45fcdfdde10a59c99bf | 25,245 | [
-1
] |
25,246 | server.lisp | open-rsx_rsb-cl/examples/patterns/request-reply/server.lisp | ;;;; server.lisp --- An example program demonstrating the local server.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
;;;; Loading this file does not terminate.
;; mark-start::body
;; For managing the lifetime of `local-server' instances (e.g. for
;; short-lived clients), the `with-participant' macro can used. It
;; will take care of disposing of the `local-server' instance after it
;; has been used, also in case of non-local exist.
;;
;; Methods can be managed similarly. After the `with-methods' form,
;; the methods are removed.
;; mark-start::with-participant
(rsb:with-participant (server :local-server "/example/clientserver")
(rsb.patterns.request-reply:with-methods (server)
(("echo" (arg string)
arg))))
;; mark-end::with-participant
;; mark-start::setf-method
(rsb:with-participant (server :local-server "/example/clientserver")
(setf (rsb.patterns.request-reply:server-method server "echo")
(lambda (arg) arg)))
;; mark-end::setf-method
;; Create a `local-server' instance that offers its methods under the
;; scope "/example/clientserver".
;; The local server will use all transports which are enabled in the
;; global RSB configuration with their respective configured options.
;;
;; The new server instance initially does not have any methods. There
;; are several ways to add methods.
;;
;; mark-start::variable
(defvar *local-server* (rsb:make-participant :local-server
"/example/clientserver"))
(setf (rsb.patterns.request-reply:server-method *local-server* "echo")
(lambda (arg) arg))
;; The local server and its methods will remain connected to the bus
;; until they are garbage collected or explicitly detached using the
;; `rsb:detach' function.
(rsb:detach *local-server*)
;; mark-end::variable
;; mark-end::body
| 1,912 | Common Lisp | .lisp | 44 | 40.5 | 71 | 0.721505 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 82592a6e992029c19d0f7e078e0890782fb269872946e4f3185943a4aa9c6d06 | 25,246 | [
-1
] |
25,247 | client.lisp | open-rsx_rsb-cl/examples/patterns/request-reply/client.lisp | ;;;; client.lisp --- An example program demonstrating the remote- server.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
;;;; Loading this file does not terminate.
;; mark-start::body
;; For managing the lifetime of `remote-server' instances (e.g. for
;; short-lived clients), the `with-participant' macro can used. It
;; will take care of disposing of the `remote-server' instance after
;; it has been used, also in case of non-local exist.
;; mark-start::with-participant
(rsb:with-participant (remote-server :remote-server "/example/clientserver")
(format t "Server replied: ~A~%"
(rsb.patterns.request-reply:call remote-server "echo" "bla")))
;; mark-end::with-participant
;; mark-start::calls
(rsb:with-participant (remote-server :remote-server "/example/clientserver")
;; The default behavior of returning the reply payload can be
;; changed using the :return keyword parameter.
(rsb.patterns.request-reply:call remote-server "echo" "bla"
:return :event)
;; Non-blocking calls can be made using the :block? keyword
;; parameter. In that case, an object implementing the future
;; protocol is returned to represent the result of the computation.
(let ((future (rsb.patterns.request-reply:call remote-server "echo" "bla"
:block? nil)))
(rsb.patterns.request-reply:future-result future))
;; These behaviors can be combined:
(let ((future (rsb.patterns.request-reply:call remote-server "echo" "bla"
:block? nil
:return :event)))
(rsb.patterns.request-reply:future-result future)))
;; mark-end::calls
;; Another way of calling methods makes use of the fact that
;; `remote-method' instances are funcallable:
;;
;; mark-start::funcalls
(rsb:with-participant (remote-server :remote-server "/example/clientserver")
;; Blocking calls for a sequence of arguments:
(map 'list (rsb.patterns.request-reply:server-method remote-server "echo")
'("a" "b" "c"))
;; Keyword arguments work the same way they do when using `call':
(funcall (rsb.patterns.request-reply:server-method remote-server "echo")
"bla"
:return :event
:block? nil))
;; mark-end::funcalls
;; Create a `remote-server' instance that calls methods of the remote
;; server at "/example/clientserver".
;; The remote server will use all transports which are enabled in the
;; global RSB configuration with their respective configured options.
;;
;; Methods can be called without further preparation. Note that the
;; initial call of a method may take more time than subsequent methods
;; due to lazy initialization strategies.
;;
;; mark-start::variable
(defvar *remote-server* (rsb:make-participant :remote-server
"/example/clientserver"))
(rsb.patterns.request-reply:call *remote-server* "echo" "bla")
;; The remote server will remain connected to the bus until it is
;; garbage collected or explicitly detached using the `rsb:detach'
;; function.
(rsb:detach *remote-server*)
;; mark-end::variable
;; mark-end::body
| 3,285 | Common Lisp | .lisp | 67 | 43.134328 | 76 | 0.68633 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 253f10142f406ac952fd2e02d62f4892e009a1d8c033d185d88637d301d420d6 | 25,247 | [
-1
] |
25,248 | sender.lisp | open-rsx_rsb-cl/examples/protocol-buffers/sender.lisp | ;;;; sender.lisp --- An example program demonstrating the protocol buffer converter.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
;; mark-start::body
;; Note: depending on your RSB configuration, this example may require
;; a running Spread daemon for successful execution.
;; In order to be able to use a protocol buffer data definition, a
;; data-holder and corresponding (de)serialization code has to be
;; generated. When a textual definition is available, this can be done
;; at runtime like this:
#.(let ((descriptor (pbf:load/text (merge-pathnames
"Image.proto"
*compile-file-pathname*))))
(pbb:emit descriptor :class)
(pbb:emit descriptor :packed-size)
(pbb:emit descriptor :serializer)
(pbb:emit descriptor :deserializer)
(values))
;; Once the data-holder class and its (de)serialization methods have
;; been generated, any participant that is configured to use the
;; generic protocol buffer converter will be able to send and receive
;; events containing the protocol buffer message in question as a
;; payload:
(rsb:with-participant (informer :informer "/example/protobuf")
(rsb:send informer (make-instance 'example:image
:width 100
:height 100
:data (nibbles:octet-vector 1 2 3))))
;; mark-end::body
| 1,510 | Common Lisp | .lisp | 31 | 41.096774 | 84 | 0.661924 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | df81e71f7da666414d1370a850cf0e2dbba71135bddb57d7ebe486c1284ad479 | 25,248 | [
-1
] |
25,249 | receiver.lisp | open-rsx_rsb-cl/examples/protocol-buffers/receiver.lisp | ;;;; receiver.lisp --- An example program demonstrating the protocol buffer converter.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
;;;; Loading this file does not terminate.
;; mark-start::body
;; Note: depending on your RSB configuration, this example may require
;; a running Spread daemon for successful execution.
;; In order to be able to use a protocol buffer data definition, a
;; data-holder and corresponding (de)serialization code has to be
;; generated. When a textual definition is available, this can be done
;; at runtime like this:
#.(let ((descriptor (pbf:load/text (merge-pathnames
#P"Image.proto"
*compile-file-pathname*))))
(pbb:emit descriptor :class)
(pbb:emit descriptor :packed-size)
(pbb:emit descriptor :serializer)
(pbb:emit descriptor :deserializer)
(values))
;; Once the data-holder class and its (de)serialization methods have
;; been generated, any participant that is configured to use the
;; generic protocol buffer converter will be able to send and receive
;; events containing the protocol buffer message in question as a
;; payload:
(rsb:with-participant (reader :reader "/example/protobuf")
(let ((event (rsb:receive reader)))
(format t "Received ~A with payload ~%" event)
(describe event)))
;; mark-end::body
| 1,441 | Common Lisp | .lisp | 31 | 42.129032 | 86 | 0.707681 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 758bc89b1b56143b89e9f56cfd092705f57aac43e9e57504626f455cfd27980b | 25,249 | [
-1
] |
25,250 | logger.lisp | open-rsx_rsb-cl/examples/introspection/logger.lisp | ;;;; logger.lisp --- An example program demonstrating introspection.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:cl-user)
;;;; Loading this file does not terminate.
;; mark-start::body
#.(progn (require :rsb-introspection) (values))
(labels ((log-event (kind object event subject)
(format t "~8A ~56A ~20A ~A~%" kind object event subject))
(on-process-change (object subject event)
(log-event :process object event subject))
(on-host-change (object subject event)
(log-event :host object event subject)
(flet ((hook () (rsb.introspection:database-change-hook subject)))
(case event
(:process-added
(hooks:add-to-hook
(hook) (alexandria:curry #'on-process-change subject)))
(:process-removed
(hooks:clear-hook (hook))))))
(on-database-change (object subject event)
(log-event :database object event subject)
(flet ((hook () (rsb.introspection:database-change-hook subject)))
(case event
(:host-added
(hooks:add-to-hook
(hook) (alexandria:curry #'on-host-change subject)))
(:host-removed
(hooks:clear-hook (hook)))))))
(rsb:with-participant (introspection
:remote-introspection rsb.introspection:+introspection-scope+
:change-handler (alexandria:curry #'on-database-change :introspection))
(declare (ignore introspection))
(sleep most-positive-fixnum)))
;; mark-end::body
| 1,699 | Common Lisp | .lisp | 37 | 35.702703 | 96 | 0.600724 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 3b265eab0daa59e7cfd3f2bacb03df45f4703777852fb8a6739324b42b243a12 | 25,250 | [
-1
] |
25,251 | informer.lisp | open-rsx_rsb-cl/src/informer.lisp | ;;;; informer.lisp --- Informers put events onto a bus.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
(defclass informer (participant
direction-mixin
rsb.ep:client
rsb.ep:broadcast-processor)
((direction :allocation :class
:initform :out)
(type :initarg :type
:type (or symbol list)
:reader informer-type
:initform t
:documentation
"Stores the type specifying the type of
event payloads supported by the
informer.")
(sequence-number-generator :type function
:reader informer-%sequence-number-generator
:initform (make-sequence-number-generator)
:documentation
"Stores a thread-safe sequence number
generation function which is used to
generate sequence numbers for events
sent by this informer."))
(:documentation
"A participant that publishes events to a specific channel.
Other participants on the same channel or a channel that includes
the informer's channel can receive these events. It is possible
for multiple informers to send events for the same channel."))
(register-participant-class 'informer)
(defmethod print-items:print-items append ((object informer))
`((:type ,(informer-type object) " ~A")))
(declaim (inline %check-send-event))
(defun %check-send-event (informer-scope informer-type event)
(let+ (((&structure-r/o event- data scope) event))
;; Ensure that the type of DATA is a subtype of INFORMER-TYPE.
(unless (typep data informer-type)
(error 'event-type-error
:event event
:datum data
:expected-type informer-type))
;; Ensure that the destination scope of DATA is identical to
;; INFORMER-SCOPE.
(unless (sub-scope?/no-coerce scope informer-scope)
(error 'event-scope-error
:event event
:expected-scope scope))))
(defmethod send ((informer informer) (data event)
&rest meta-data ; TODO make this a keyword parameter
&key
method
timestamps
causes
unchecked?
no-fill?)
(let ((meta-data (remove-from-plist
meta-data :method :timestamps :causes
:unchecked? :no-fill?)))
;; Check the event w.r.t. to restrictions imposed by INFORMER.
(unless unchecked?
(%check-event-arguments timestamps meta-data causes)
(let ((informer-scope (participant-scope informer))
(informer-type (informer-type informer)))
(%check-send-event informer-scope informer-type data)))
;; Set DATA's sequence number to our next sequence number and
;; origin to our id.
(unless no-fill?
(setf (event-sequence-number data)
(funcall (informer-%sequence-number-generator informer))
(event-origin data)
(participant-id informer)))
;; Set method, additional timestamps, meta-data and causes, if
;; supplied.
(when method
(setf (event-method data) method))
(when timestamps
(appendf (slot-value data 'timestamp) timestamps))
(when meta-data
(appendf (slot-value data 'meta-data) meta-data))
(when causes
(appendf (event-causes data) causes))
;; Send the event and return it to the caller.
(rsb.ep:handle informer data)
data))
(defmethod send ((informer informer) (data t) &rest args &key)
(let ((event (make-instance 'event
:scope (participant-scope informer)
:data data)))
(apply #'send informer event args)))
;;; `informer' creation
(defmethod make-participant-using-class ((class class)
(prototype informer)
(scope scope)
&key)
;; Connect the processor of CONFIGURATOR to INFORMER as an event
;; handler and return the ready-to-use `informer' instance.
(let* ((informer (call-next-method))
(configurator (rsb.ep:client-configurator informer)))
(push (rsb.ep:configurator-processor configurator)
(rsb.ep:handlers informer))
informer))
| 4,805 | Common Lisp | .lisp | 105 | 33.304762 | 75 | 0.568837 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 143f97bcc4f09175081585cd503b763c668480239d60b10cc5d0506b572c9a6d | 25,251 | [
-1
] |
25,252 | package.lisp | open-rsx_rsb-cl/src/package.lisp | ;;;; package.lisp --- Main package definition for the rsb system.
;;;;
;;;; Copyright (C) 2010-2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb
(:use
#:cl
#:alexandria
#:split-sequence
#:iterate
#:let-plus
#:hooks
#:more-conditions)
;; Optimization settings
(:export
#:+optimization-fast+unsafe+)
;; Types
(:export
#:scope-component-character #:scope-component-character?
#:scope-component #:scope-component?
#:scope-components #:scope-components?
#:scope-designator
#:derive-scope-component
#:sequence-number
#:timestamp-designator
#:meta-data-designator
#:error-policy
#:timeout
#:implementation-feedback
#:direction
#:wire-type)
;; Conditions
(:export
#:rsb-condition
#:rsb-problem-condition
#:rsb-warning
#:rsb-error
#:scope-parse-error
#:scope-parse-error-string
#:scope-parse-error-position
#:communication-error
#:participant-creation-error
#:participant-creation-error-kind
#:participant-creation-error-scope
#:participant-creation-error-transports
#:no-transports-error
#:event-error
#:event-error-event
#:event-type-error
#:event-scope-error
#:event-error-expected-scope)
;; Restarts
(:export
#:retry
;; continue provided by CL
;; use-value likewise
;; abort likewise
#:use-scope
#:use-uri)
;; (Special) Variables
(:export
#:*reserved-scope*
#:*framework-timestamps*
#:*id-random-state*
#:*default-configuration*
#:*default-configuration-files*
#:*configuration*
#:*make-participant-hook*
#:*participant-state-change-hook*)
;; Reloading
(:export
#:enable-id-random-state-reseed)
;; Hooks
(:export
#:error-hook)
;; Error handling
(:export
#:call-with-restart-and-timeout
#:with-restart-and-timeout)
;; Meta data protocol
(:export
#:meta-data
#:meta-data-count
#:meta-data-keys
#:meta-data-values
#:meta-data-plist
#:meta-data-alist)
;; Timestamp protocol
(:export
#:timestamp
#:timestamp-count
#:timestamp-keys
#:timestamp-values
#:timestamp-plist
#:timestamp-alist)
;; Component URL protocol
(:export
#:relative-url
#:abstract-uri
#:transport-specific-urls)
;; Scope protocol
(:export
#:scope
#:scope-component
#:scope-components
#:scope-string
#:scope-interned?
#:scope= #:scope=/no-coerce
#:sub-scope? #:sub-scope?/no-coerce
#:super-scope? #:super-scope?/no-coerce
#:make-scope
#:super-scopes
#:merge-scopes
#:enough-scope
#:intern-scope)
;; Event id
(:export
#:event-id
#:event-id=
#:event-id->uuid)
;; Event
(:export
#:event
#:event-id
#:event-id/opaque
#:event-scope
#:event-origin
#:event-sequence-number
#:event-method
#:event-data
#:event-meta-data
#:event-timestamps
#:event-causes
#:make-event
#:event=
#:print-event-data)
;; Participant protocol and `participant' class
(:export
#:participant
#:participant-kind
#:participant-id
#:participant-scope
#:participant-converters
#:participant-converter
#:participant-transform
#:participant-error-hook
#:make-participant
#:make-participant-using-class
#:detach #:detach/ignore-errors)
;; Protocol for receiving participants
(:export
#:receiver-filters)
;; `listener' class
(:export
#:listener)
;; Reader protocol and `reader' class
(:export
#:receive
#:reader)
;; Send protocol and `informer' class
(:export
#:send
#:informer)
;; Configuration
(:export
#:options-from-environment
#:options-from-stream
#:options-from-default-sources
#:option-value
#:section-options
#:make-options
#:make-options-for-connector-classes
#:make-options-for-connector-class
#:&inherit
#:transport-options
#:default-converters
#:default-converter)
;; URI-related function
(:export
#:uri-options
#:uri->scope-and-options)
;; Macros
(:export
#:call-with-active-participant
#:with-active-participant
#:with-active-participants
#:with-participant
#:with-participants
#:call-with-handler
#:with-handler)
;; Timed executor protocol and classes
(:export
#:executor-interval ; also setf
#:timed-executor
#:timed-executor/weak)
;; Utility functions and macros
(:export
#:print-id
#:print-unreadable-id-object
#:uuid-mixin
#:scope-mixin
#:uri-mixin
#:maybe-shorten-sequence)
(:documentation
"This package contains most of the basic programming interface of rsb:
Scopes and events:
+ `scope' [class]
+ `event' [class]
+ `event-scope' [generic function]
+ `event-data' [generic function]
Participant classes and associated protocols:
+ `make-participant' [generic function]
+ `with-participant' [macro]
+ `reader' participant [class]
+ `receiver-filters' [generic function]
+ `receive' [generic function]
+ `listener' participant [class]
+ `receiver-filters' [generic function]
+ `informer' participant [class]
+ `send' [generic function]"))
| 5,444 | Common Lisp | .lisp | 221 | 20.493213 | 73 | 0.650942 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | f335e25974740a5935dfc493dcd1291d2fee0e17d1242905cfe61373034741aa | 25,252 | [
-1
] |
25,253 | util.lisp | open-rsx_rsb-cl/src/util.lisp | ;;;; util.lisp ---
;;;;
;;;; Copyright (C) 2011-2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defparameter +optimization-fast+unsafe+
(if (boundp '+optimization-fast+unsafe+)
(symbol-value '+optimization-fast+unsafe+)
'(optimize (speed 3) (compilation-speed 0) (space 0) (debug 0) (safety 0)))))
;;; Sequence number functions
(declaim (ftype (function (&optional sequence-number)
(function () sequence-number))
make-sequence-number-generator))
(defun make-sequence-number-generator (&optional (start 0))
"Return a function that returns increasing numbers starting with
START."
#.(if (subtypep 'sequence-number 'lparallel.counter:counter-value)
'(let ((current (lparallel.counter:make-counter start)))
(lambda ()
(declare #.+optimization-fast+unsafe+)
(mod (lparallel.counter:inc-counter current)
(ash 1 32))))
#+sbcl
;; We have to wrap the value in a cons.
'(let ((current (list (list start))))
(declare (type (cons (cons sequence-number null) null) current))
(lambda ()
(declare #.+optimization-fast+unsafe+)
;; Keep trying to store the incremented value until it
;; works.
(iter (for old next (car current))
(for new next (list (ldb (byte 32 0)
(1+ (the sequence-number
(car old))))))
(until (eq old (sb-ext:compare-and-swap
(car current) old new)))
(finally (return (car old))))))
#-sbcl
'(error "Not implemented")))
;;; UUID utility functions
(defun print-id (stream id &optional colon? at?)
"Print the UUID ID to STREAM. If COLON? is non-nil, all components
of ID are printed. Otherwise, just a block of 8 digits is printed. "
(declare (ignore at?))
(cond
((null id)
(format stream " NOID"))
((or colon? (not (typep id 'uuid:uuid)))
(format stream "~A" id))
(t
(format stream "~8,'0X" (slot-value id 'uuid::time-low)))))
(defmacro print-unreadable-id-object ((object stream &key (type t))
&body body)
"Print OBJECT to STREAM in a manner similar to
`print-unreadable-object' but use the `id' slot of OBJECT as object
identity."
(once-only (object stream)
`(print-unreadable-object (,object ,stream :type ,type)
,@body
(write-char #\Space stream)
(print-id ,stream (slot-value ,object 'id)))))
;;; Utility functions
(defun maybe-shorten-sequence (thing)
(if (typep thing 'sequence)
(let ((length (length thing)))
(values (subseq thing 0 (min length 200)) (> length 200)))
(values thing nil)))
;;; plist-mixin
(defmacro define-plist-data-mixin (name
&key
(slot-name name))
"Define a class `plist-NAME-mixin' which manages a plist in a
slot. Define the following accessors along with the class:
`NAME-count'
Return number of items.
`NAME-keys'
Return item keys.
`NAME-values'
Return item values.
`NAME-plist'
Return items as plist.
`NAME-alist'
Return items as alist."
(let+ ((class-name (symbolicate "PLIST-" name "-MIXIN"))
(initarg (make-keyword slot-name))
((count-name keys-name values-name plist-name alist-name)
(map 'list (curry #'symbolicate name)
'("-COUNT" "-KEYS" "-VALUES" "-PLIST" "-ALIST"))))
`(progn
(defclass ,class-name ()
((,slot-name :initarg ,initarg
:type list
:initform nil
:documentation
,(format nil "Stores the ~(~A~) items associated ~
to the instance."
name)))
(:documentation
"This mixin adds storage for a plist of items and associated
accessors. See `define-plist-data-mixin' for a description."))
(defgeneric ,count-name (object)
(:method ((object ,class-name))
(/ (length (slot-value object ',slot-name)) 2))
(:documentation
,(format nil "Return the number of ~(~A~) items stored in OBJECT."
name)))
(defgeneric ,keys-name (object)
(:method ((object ,class-name))
(iter (for (key) on (slot-value object ',slot-name)
:by #'cddr)
(collect key)))
(:documentation
,(format nil "Return a list of the keys of ~(~A~) items ~
stored in OBJECT."
name)))
(defgeneric ,values-name (object)
(:method ((object ,class-name))
(iter (for (key value) on (slot-value object ',slot-name)
:by #'cddr)
(collect value)))
(:documentation
,(format nil "Return a list of the values of ~(~A~) items ~
stored in OBJECT."
name)))
(defgeneric ,plist-name (object)
(:method ((object ,class-name))
(slot-value object ',slot-name))
(:documentation
,(format nil "Return a plist of the ~(~A~) items stored in ~
OBJECT."
name)))
(defgeneric ,alist-name (object)
(:method ((object ,class-name))
(plist-alist (slot-value object ',slot-name)))
(:documentation
,(format nil "Return an alist of the ~(~A~) items stored ~
in OBJECT."
name)))
(defgeneric ,name (object key)
(:method ((object ,class-name) (key t))
(getf (slot-value object ',slot-name) key))
(:documentation
,(format nil "Return the ~(~A~) item of OBJECT identified ~
by KEY."
name)))
(defgeneric (setf ,name) (new-value object key)
(:method ((new-value t) (object ,class-name) (key t))
(setf (getf (slot-value object ',slot-name) key) new-value))
(:documentation
,(format nil "Associate NEW-VALUE to OBJECT as the ~(~A~)
item identified by KEY."
name))))))
;;; `timed-executor'
(defun %maybe-unschedule-timer (timer)
(when (sb-ext:timer-scheduled-p timer)
(log:info "~@<Unscheduling timer ~A~@:>" timer)
(sb-ext:unschedule-timer timer)))
(defclass timed-executor (print-items:print-items-mixin)
((timer :accessor executor-%timer
:documentation
"Stores the timer used to trigger execution of the target
function.")
(interval :initarg :interval
:type positive-real
:accessor executor-interval
:documentation
"Stores the time in seconds between successive calls of
the target function."))
(:default-initargs
:interval (missing-required-initarg 'timed-executor :interval)
:function (missing-required-initarg 'timed-executor :function))
(:documentation
"Instances of this class repeatedly execute given functions at
regular intervals.
A finalizer is installed to unschedule the execution of the
function when the executor instances becomes garbage."))
(defmethod initialize-instance :after
((instance timed-executor)
&key
(name "Timed executor")
(interval nil interval?)
function
args
(effective-function (lambda ()
(values (apply function args) t))))
(declare (type function effective-function))
(let+ ((timer-cell (list nil))
((&flet finalize ()
(when-let ((timer (car timer-cell)))
(%maybe-unschedule-timer timer))))
((&flet execute ()
(unless (lastcar (multiple-value-list
(funcall effective-function)))
(finalize))))
(timer (sb-ext:make-timer #'execute
:name name
:thread t)))
(setf (car timer-cell) timer
(executor-%timer instance) timer)
(tg:finalize instance #'finalize))
(when interval?
(setf (executor-interval instance) interval)))
(defmethod (setf executor-interval) :after ((new-value real)
(thing timed-executor))
(let+ (((&structure-r/o executor- (timer %timer)) thing))
(%maybe-unschedule-timer timer)
(sb-ext:schedule-timer timer new-value :repeat-interval new-value)))
(defmethod print-items:print-items append ((object timed-executor))
(let+ (((&structure-r/o executor- (timer %timer) interval) object))
`((:name ,(sb-ext:timer-name timer) "~S")
(:update-interval ,interval " ~,3F s" ((:after :name))))))
(defmethod detach ((participant timed-executor))
(tg:cancel-finalization participant)
(%maybe-unschedule-timer (executor-%timer participant)))
;;; `timed-executor/weak'
(defun curry/weak (function &rest args)
"Like `alexandria:curry', return a function representing the partial
application of FUNCTION to ARGS, but use weak references to the
elements of ARGS.
The returned function behaves as follows w.r.t. ARGS:
* If it is called while all elements of ARGS are still reachable,
FUNCTION is called with those arguments and two values are
returned: 1) the result of calling function 2) t.
* If it is called after one or more elements of ARGS have become
garbage, FUNCTION is not called and two nil values are returned."
(let ((function (ensure-function function)))
(unless args
(return-from curry/weak
(lambda (&rest new-args)
(values (apply function new-args) t))))
(let ((args/weak (mapcar #'tg:make-weak-pointer args)))
(named-lambda call-when-reachable (&rest new-args)
(let+ (((&flet value-or-return (weak-pointer)
(or (tg:weak-pointer-value weak-pointer)
(return-from call-when-reachable (values nil nil)))))
(args (mapcar #'value-or-return args/weak)))
(declare (dynamic-extent args))
(values (apply function (nconc args new-args)) t))))))
(defclass timed-executor/weak (timed-executor)
()
(:documentation
"Like `timed-executor' but only keep weak references to the
arguments of the function.
As a result, this executor can be used as follows:
(let* ((my-object ...)
(my-executor (make-instance 'timed-executor/weak
:function #'my-object-slot
:args (list my-object))))
...)
with the effect that `my-executor' will stop calling
`my-object-slot' when `my-object' becomes garbage (Like
`timed-executor', the executor unschedules itself when it becomes
garbage)."))
(defmethod initialize-instance :around ((instance timed-executor/weak)
&rest args1 &key
function
args)
(apply #'call-next-method instance
:effective-function (apply #'curry/weak function args)
(remove-from-plist args1 :function :args)))
| 11,673 | Common Lisp | .lisp | 262 | 33.763359 | 85 | 0.573616 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 4cf02d86b642f7e97304bd2ebf07876d62e2c19376a9dc3da3f72711488b0084 | 25,253 | [
-1
] |
25,254 | event.lisp | open-rsx_rsb-cl/src/event.lisp | ;;;; event.lisp --- RSB event class.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
;; forward declaration
(declaim (special *framework-timestamps*))
(defclass event (scope-mixin
plist-meta-data-mixin
plist-timestamp-mixin)
((sequence-number :initarg :sequence-number
:type (or null sequence-number)
:accessor event-sequence-number
:initform nil
:documentation
"Stores a sequence number of the event \"within\"
the participant sending the event.")
(id :type (or null uuid:uuid)
:reader event-id
:writer (setf event-%id)
:documentation
"Stores a unique id that is lazily computed from
the unique id of the participant sending the event (stored in the
origin slot) and the sequence number of the event.")
(scope :accessor event-scope)
(origin :initarg :origin
:type (or null uuid:uuid)
:accessor event-origin
:initform nil
:documentation
"Stores the id of the participant by which the
event was published onto the bus.")
(method :initarg :method
:type (or null keyword)
:accessor event-method
:initform nil
:documentation
"Stores the name of a \"method category\" which
characterizes the role of the event in a communication
pattern (examples include \"request\", \"reply\", \"update\").")
(data :initarg :data
:type t
:accessor event-data
:documentation
"Stores the payload of the event as a \"domain
object\" (can be any Lisp object).")
(meta-data :accessor event-meta-data)
(timestamp :initarg :timestamps
:accessor event-timestamps)
(causes :initarg :causes
:type list
:accessor event-causes
:initform '()
:documentation
"Stores a list of `event-id's that identify events
which somehow caused the event."))
(:default-initargs
:intern-scope? nil)
(:documentation
"Basic unit of information that is exchanged between informers and
listeners. An event is a composite structure consisting of
+ a sequence number
+ an id (derived from the sequence number and the id of the sending
participant)
+ a scope
+ the id of the participant that sent the event
+ an optional \"method category\"
+ a payload
+ various timestamps
+ optional metadata
+ an optional list of events that caused the event"))
(defmethod shared-initialize :after ((instance event)
(slot-names t)
&key
(create-timestamp? t))
;; Initialize or invalidate id.
(setf (event-%id instance) nil)
;; Maybe set create timestamp.
(when create-timestamp?
(setf (timestamp instance :create) (local-time:now))))
(defmethod event-id/opaque ((event event))
(when-let* ((origin (event-origin event))
(sequence-number (event-sequence-number event)))
(cons origin sequence-number)))
(defmethod event-id :before ((event event))
(%maybe-set-event-id event))
(defmethod (setf event-sequence-number) :after ((new-value t) (event event))
(setf (event-%id event) nil))
(defmethod (setf event-origin) :after ((new-value t) (event event))
(setf (event-%id event) nil))
(defun event= (left right
&key
(compare-sequence-numbers? t)
(compare-origins? t)
(compare-methods? t)
(compare-timestamps t)
(compare-causes? t)
(data-test #'equal))
"Return non-nil if the events LEFT and RIGHT are equal.
If COMPARE-SEQUENCE-NUMBERS? is non-nil, return nil unless LEFT and
RIGHT have identical sequence numbers.
If COMPARE-ORIGINS? is non-nil, return nil unless LEFT and RIGHT have
identical origins.
If COMPARE-METHODS? is non-nil, return nil unless LEFT and RIGHT have
identical methods.
COMPARE-TIMESTAMPS can be nil, t or a list of timestamp keys to
compare. If it is t, all timestamps whose keys appear in
`rsb:*framework-timestamps*' are
compared (currently :create, :send, :receive and :deliver).
If COMPARE-CAUSES? is non-nil, return nil unless LEFT and RIGHT have
identical sets of causes.
DATA-TEST has to be a function of two arguments or nil. In the latter
case, the payloads of LEFT and RIGHT are not considered. It is assumed
that DATA-TEST, if supplied, returns non-nil if LEFT and RIGHT are
`eq'."
(or (eq left right)
(and (or (not compare-sequence-numbers?)
(eql (event-sequence-number left)
(event-sequence-number right)))
;; Scope and origin
(scope= (event-scope left) (event-scope right))
;; Origin
(or (not compare-origins?)
(let ((left-origin (event-origin left))
(right-origin (event-origin right)))
(or (and (not left-origin) (not right-origin))
(and left-origin right-origin
(uuid:uuid= left-origin right-origin)))))
;; Method
(or (not compare-methods?)
(eq (event-method left) (event-method right)))
;; Timestamps
(or (null compare-timestamps)
(iter (for key in (if (eq compare-timestamps t)
*framework-timestamps*
compare-timestamps))
(let ((value-left (timestamp left key))
(value-right (timestamp right key)))
(always (or (and (null value-left) (null value-right))
(local-time:timestamp=
value-left value-right))))))
;; Causes
(or (not compare-causes?)
(set-equal (event-causes left) (event-causes right)
:test #'event-id=))
;; Payload
(or (null data-test)
(funcall data-test (event-data left) (event-data right))))))
(defmethod print-object ((object event) stream)
(%maybe-set-event-id object) ; force id computation
(print-unreadable-id-object (object stream :type t)
(format stream "~@<~@[~A ~]~A ~:/rsb::print-event-data/~@:>"
(event-method object)
(scope-string (event-scope object))
(event-data object))))
;;; Construction
(declaim (inline %check-event-timestamp %check-event-meta-data
%check-event-cause %check-event-arguments))
(defun %check-event-timestamp (key value)
(unless (typep value 'local-time:timestamp)
(error 'simple-type-error
:datum value
:expected-type 'local-time:timestamp
:format-control "~@<The value ~S supplied for timestamp ~
key ~S is not a ~S.~@:>"
:format-arguments (list value key 'local-time:timestamp))))
(defun %check-event-meta-data (key value)
(unless (typep value '(or string keyword real))
(error 'simple-type-error
:datum value
:expected-type '(or string keyword real)
:format-control "~@<The value ~S supplied for meta-data key ~
~S is not of type ~S.~@:>"
:format-arguments (list value key '(or string keyword real)))))
(defun %check-event-cause (value)
(unless (typep value 'event-id)
(error 'simple-type-error
:datum value
:expected-type 'event-id
:format-control "~@<The value ~S as cause is not of type ~
~S.~@:>"
:format-arguments (list value 'event-id))))
(defun %check-event-arguments (timestamps meta-data causes)
;; Check timestamps.
(iter (for (key value) on timestamps :by #'cddr)
(%check-event-timestamp key value))
;; Check meta-data items.
(iter (for (key value) on meta-data :by #'cddr)
(%check-event-meta-data key value))
;; Check causes.
(mapc #'%check-event-cause causes))
(defun make-event (scope data
&rest meta-data
&key
method
causes
timestamps
(create-timestamp? t)
unchecked?
&allow-other-keys)
"Construct an event addressed at SCOPE with payload DATA and,
optionally, meta-data consisting of the keys and values in the
plist META-DATA.
CAUSES can be used to supply a list of causes.
TIMESTAMPS is an alist with elements of the form
(KEY . TIMESTAMP)
where TIMESTAMP is a `local-time:timestamp' instance.
CREATE-TIMESTAMP? controls whether a :create timestamp for the
current time is added to the event."
(let ((meta-data (remove-from-plist
meta-data :method :causes :timestamps
:create-timestamp? :unchecked?)))
(unless unchecked?
(%check-event-arguments timestamps meta-data causes))
(make-instance 'event
:scope (make-scope scope)
:method method
:data data
:meta-data meta-data
:causes causes
:timestamp timestamps
:create-timestamp? create-timestamp?)))
;;; Utility functions
(declaim (ftype (function (event-id event-id) t) event-id=))
(defun event-id= (left right)
"Return non-nil if the event ids LEFT and RIGHT refer to the same
event."
(or (eq left right)
(and (= (cdr left) (cdr right))
(uuid:uuid= (car left) (car right)))))
(declaim (ftype (function (event-id) (values uuid:uuid &optional))
event-id->uuid)
(inline event-id->uuid))
(defun event-id->uuid (event-id)
"Derive a UUID from EVENT-ID."
(uuid:make-v5-uuid
(car event-id) (format nil "~(~8,'0X~)" (cdr event-id))))
(defun %maybe-set-event-id (event)
"When the id slot of EVENT is nil compute a unique id based on the
origin id of EVENT and the sequence number of EVENT. If EVENT does not
have an origin, do nothing."
(unless (slot-value event 'id)
(when-let ((id (event-id/opaque event)))
(setf (event-%id event) (event-id->uuid id)))))
(defun print-event-data (stream data &optional colon? at?)
"Print the event payload DATA to stream in a type-dependent manner.
This function is intended for use with the / `format' control.
COLON? controls whether an indication of the size of DATA should be
printed.
AT? is ignored."
(declare (ignore at?))
(let+ ((*print-length* (or *print-length* 5))
((&flet maybe-shorten-string (string max)
;; Shorten STRING to obey `*print-length*'.
(let ((length (length string)))
(if (<= length max)
string
(concatenate
'string (subseq string 0 max) "...")))))
((&flet make-printable (string)
;; Replace unprintable characters in STRING with ".".
(substitute-if
#\. (lambda (char) (< (char-code char) 32)) string)))
((&flet print-string (string)
(make-printable (maybe-shorten-string string *print-length*)))))
(format stream "~:[~A~:;~S~]~@[ (~D)~]"
(stringp data)
(etypecase data
(string (print-string data))
(scope (print-string (scope-string data)))
(t data))
(when (and colon? (typep data 'sequence))
(length data)))))
| 12,182 | Common Lisp | .lisp | 274 | 34.105839 | 77 | 0.576375 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 0813c7ba1cd086d9c0f69373320a98bf4128a9d71dc2146c347e18ca18980022 | 25,254 | [
-1
] |
25,255 | protocol.lisp | open-rsx_rsb-cl/src/protocol.lisp | ;;;; protocol.lisp --- Main client-facing protocol provided by rsb.
;;;;
;;;; Copyright (C) 2011-2016, 2018, 2019 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
;;; Error handling
(defun retry ()
"Invoke the `retry' restart."
(if-let ((restart (find-restart 'retry)))
(invoke-restart restart)
(warn "~@<Restart ~S not found; Doing nothing.~@:>" 'retry)))
;; use-value restart and function are provided by CL.
;; continue restart and function are provided by CL.
;; abort restart and function are provided by CL.
;;; Scope protocol
(defgeneric scope-components (scope)
(:documentation
"Return a list containing the components of SCOPE."))
(defgeneric scope-string (scope)
(:documentation
"Return a string representation of SCOPE."))
(defgeneric make-scope (thing
&key
intern?)
(:documentation
"Parse string and return a `scope' instance."))
;; intern-scope
;;; Event protocol
(defgeneric event-id/opaque (event)
(:documentation
"Return an object that uniquely identifies EVENT."))
;;; Component URL protocol
(defgeneric relative-url (component)
(:documentation
"Return a relative URL that allows to locate COMPONENT when
anchored at an absolute location like a transport URL."))
(defgeneric abstract-uri (component)
(:documentation
"Return a URI with \"rsb\" scheme, no host and port information
merged with the relative URL of COMPONENT."))
(defgeneric transport-specific-urls (component)
(:documentation
"Return a list of URLs each of which describes the location and/or
reachability of COMPONENT in transport-specific way."))
;; Default behavior
(defmethod abstract-uri ((component t))
"Merge the relative URL of COMPONENT with a scheme-only \"anchor\"."
(puri:merge-uris (relative-url component)
(make-instance 'puri:uri
:scheme :rsb)))
(defmethod transport-specific-urls ((component t))
"For arbitrary COMPONENTs, location information is not available."
'())
;;; Common participant protocol
(defgeneric participant-kind (participant)
(:documentation
"Return a keyword designating the kind of PARTICIPANT."))
(defgeneric participant-id (participant)
(:documentation
"Return the unique id of PARTICIPANT."))
(defgeneric participant-scope (participant)
(:documentation
"Return the scope of the channel in which PARTICIPANT
participates."))
(defgeneric participant-converter (participant wire-type
&key
error?)
(:documentation
"Return the converter used by PARTICIPANT for WIRE-TYPE.
If PARTICIPANT does not have a converter for WIRE-TYPE, signal an
error if ERROR? is non-nil, otherwise return nil."))
(defgeneric participant-error-hook (participant)
(:documentation
"Return the error hook of PARTICIPANT. Handlers attached to the
returned hook are called when errors are signaled in PARTICIPANT
or an associated object."))
(defgeneric detach (participant)
(:documentation
"Detach PARTICIPANT from the channel in which it participates and
the transport or transports it uses for this participation."))
(defun detach/ignore-errors (participant)
"Like `detach' but handle errors that occur during detaching by
continuing in a best effort manner instead of signaling."
(handler-bind
(((or error bt:timeout)
(lambda (condition)
(warn "~@<Error during detaching of ~A: ~A~@:>"
participant condition)
(continue))))
(detach participant)))
;; Default behavior
(defclass participant () ()) ; forward declaration
(declaim (special *participant-state-change-hook*))
(defmethod participant-kind ((participant t))
(values (make-keyword (type-of participant))))
(defmethod participant-converter :around ((participant t) (wire-type t)
&key
(error? t))
"Signal an error if the next method could not retrieve the
converter."
(or (call-next-method)
(when error?
(error "~@<Participant ~A does not have a converter for ~
wire-type ~A.~@:>"
participant wire-type))))
(defmethod detach :around ((participant participant))
(if *participant-state-change-hook*
(unwind-protect
(call-next-method)
(hooks:run-hook '*participant-state-change-hook*
participant :detached))
(call-next-method)))
;;; Participant creation protocol
;;;
;;; 1. Clients of the protocol call `make-participant' to request the
;;; creation of an instance of a given participant kind.
;;;
;;; Methods on this generic function are in charge of:
;;; * Establishing appropriate restarts
;;; * Translating error conditions into
;;; `participant-creation-error' conditions
;;; * Parsing string designators or URIs and scopes
;;; * Splitting URIs into scopes and transport options
;;;
;;; 2. `service-provider:make-provider' is used to locate the
;;; requested participant class and obtain a prototype instance
;;; (e.g. via. `class-prototype').
;;;
;;; * In most cases, this is achieved by registering instances of
;;; the specialized `participant-provider' provider class
;;;
;;; 3. Normally, the provider calls `make-participant-using-class'
;;; with arguments augmented with the prototype instance.
;;;
;;; This allows methods on `make-participant-using-class' to
;;; customize participant creation for certain classes and their
;;; respective subclasses.
(defgeneric make-participant (kind scope &rest args
&key
transports
converters
transform
error-policy
parent
introspection?
&allow-other-keys)
(:documentation
"Make and return a participant instance of KIND that participates
in the channel designated by SCOPE.
In general, the keyword arguments ARGS are used as initargs for
the created CLASS instance. Some commonly accepted initargs are
described below.
All participant classes accept the keyword parameters
ERROR-POLICY has to be nil or a function to be installed in the
error hook of the created participant.
PARENT, if supplied, is a participant that should be considered
the parent of the created participant.
INTROSPECTION? controls whether the created participant
participates in the introspection machinery. Specifically,
whether it announces its creation and destruction and answers to
introspection queries.
Participant classes which directly send or receive
events (e.g. `reader', `listener' and `informer') support the
following keyword parameters:
TRANSPORTS is a list of connector classes.
CONVERTERS is an alist of converters for particular wire-types
with items of the form (WIRE-TYPE . CONVERTER).
Many, but not necessarily all, participant classes support the
keyword parameter
TRANSFORM, when non-nil, is a transform object usable with
`rsb.event-processing:transform!'.
Return the `participant' (more likely a subclass thereof)
instance.
If the participant cannot be created, an error of type
`participant-creation-error' is signaled."))
(defgeneric make-participant-using-class (class prototype scope
&rest args &key &allow-other-keys)
(:documentation
"Make and return a participant instance of CLASS, optionally using
PROTOTYPE for dispatch.
PROTOTYPE is an instance of CLASS intended for dispatch (it might
not be properly initialized but is guaranteed to be an instance of
CLASS).
See `make-participant' for a description of the remainder of the
parameters."))
;; Service
(defclass participant-provider (service-provider:class-provider)
()
(:documentation
"Provider class which implements `service-provider:make-provider'
by delegating to `make-participant-using-class'."))
(defmethod shared-initialize :after ((instance participant-provider)
(slot-names t)
&key)
(closer-mop:finalize-inheritance
(service-provider:provider-class instance)))
(defmethod service-provider:make-provider ((service t)
(provider participant-provider)
&rest args)
(let* ((class (service-provider:provider-class provider))
(prototype (closer-mop:class-prototype class)))
(apply #'make-participant-using-class class prototype args)))
(service-provider:define-service participant
(:documentation
"Providers of this service are classes conforming to the
participant protocol."))
(defun register-participant-class (class
&optional
(designator (make-keyword class)))
(service-provider:register-provider/class
'participant designator
:class class
:provider-class 'participant-provider))
;; Default behavior
(defclass scope () ()) ; forward declarations
(declaim (special *make-participant-hook*))
;; The variable `*make-participant-nesting*' is used to distinguish
;; "distinct" recursive calls to `make-participant' in order to
;; perform accurate condition translation.
;;
;; For example, if `make-participant' is called with a scope
;; designated by a string, the :around method establishes a condition
;; translating handler. Next, there is a recursive call to
;; `make-participant' with the parsed scope. This should not be
;; treated as a distinct call meaning that errors signaled in the
;; inner call should not be wrapped in multiple
;; `participant-creation-error' conditions. However, if the creation
;; of the requested participant involves creating another participant,
;; and the nested creation signals an, there should be a chain of
;; `participant-creation-error' conditions, one for each requested
;; participant.
(declaim (type (cons boolean integer) *make-participant-nesting*))
(defvar *make-participant-nesting* (cons nil 0))
(defmethod make-participant :around ((kind t) (scope t)
&key
transports)
;; Translate different kinds of errors into
;; `participant-creation-error' errors.
(if (car *make-participant-nesting*)
(call-next-method)
(let* ((depth (1+ (cdr *make-participant-nesting*)))
(*make-participant-nesting* (cons t depth)))
(handler-bind
((error (lambda (condition)
(when (or (/= depth (cdr *make-participant-nesting*))
(not (typep condition 'participant-creation-error)))
(error 'participant-creation-error
:kind kind
:scope scope
:transports transports ; TODO not always available
:cause condition)))))
(call-next-method)))))
(defmethod make-participant
((kind t) (scope scope)
&rest args &key
(introspection? (when (member (option-value '(:introspection :enabled)) '(t "1")
:test #'equal)
t)))
(let* ((*make-participant-nesting*
(cons nil (cdr *make-participant-nesting*)))
(participant (apply #'service-provider:make-provider
'participant kind scope args)))
(if *make-participant-hook*
;; When the hook returns anything but nil, use it as
;; replacement for PARTICIPANT. Otherwise use PARTICIPANT.
(or (hooks:run-hook
'*make-participant-hook* participant
(list* :introspection? introspection?
(remove-from-plist args :introspection?)))
participant)
participant)))
(defmethod make-participant-using-class ((class class)
(prototype t)
(scope scope)
&rest args &key)
(apply #'make-instance class :scope scope
(remove-from-plist args :parent :introspection?)))
;;; Common protocol for receiving participants
(defgeneric receiver-filters (receiver)
(:documentation
"Return the list of filters associated to the receiving participant
RECEIVER."))
(defgeneric (setf receiver-filters) (new-value receiver)
(:documentation
"Set the list of filters associated to the receiving participant
RECEIVER to NEW-VALUE."))
;;; Informer protocol
(defgeneric send (informer data
&rest meta-data
&key
method
timestamps
causes
unchecked?
&allow-other-keys)
(:documentation
"Send DATA to participants of the channel in which INFORMER
participates. Add key-value pairs in META-DATA to the meta-data of the
event created from DATA.
METHOD can be used to set the method of the sent event.
TIMESTAMPS, if supplied, is interpreted as a plist of named timestamps
in which values are `local-time:timestamp' instances.
CAUSES can be used to add a list of cause vectors to the sent
event. The cause vector have to be `event-id's.
UNCHECKED? controls whether the compatibility of INFORMER and DATA
should be validated. This mainly applies if data is an `event'
instance since properties like the scope of the event may conflict
with properties of INFORMER."))
;;; Timed executor protocol
(defgeneric executor-interval (executor)
(:documentation
"Return the interval in seconds between calls to EXECUTOR's task
function."))
(defgeneric (setf executor-interval) (new-value executor)
(:documentation
"Set the interval in seconds between calls to EXECTUOR's task
function to NEW-VALUE."))
| 14,286 | Common Lisp | .lisp | 318 | 37.056604 | 85 | 0.667338 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | a1c0b1462ec730876b359b22a705b2bba9b04987662e5e8f2a23a0e1127e4a23 | 25,255 | [
-1
] |
25,256 | types.lisp | open-rsx_rsb-cl/src/types.lisp | ;;;; types.lisp --- Types used in the rsb system.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
;;; Scope-related types
(declaim (inline scope-component-character?))
(defun scope-component-character? (character)
"Non-nil when character is valid within a scope component."
(or (char<= #\a character #\z)
(char<= #\A character #\Z)
(char<= #\0 character #\9)
(char= character #\_) (char= character #\-)))
(declaim (notinline scope-component-character?))
(deftype scope-component-character ()
'(and character (satisfies scope-component-character?)))
(defun scope-component? (string)
"Non-nil when STRING is a valid scope component."
(locally (declare (inline scope-component-character?))
(and (stringp string)
(plusp (length string))
(every #'scope-component-character? string))))
(deftype scope-component ()
'(and string (satisfies scope-component?)))
(defun scope-components? (sequence)
(every #'scope-component? sequence))
(deftype scope-components ()
'(and sequence (satisfies scope-components?)))
(deftype scope-designator ()
"A scope can be designated by a string, a list of scope components
or a `scope' instance."
'(or string scope-components scope))
(declaim (ftype (function (string) scope-component) derive-scope-component))
(defun derive-scope-component (string)
"Return a legal scope component string based on STRING."
(substitute-if-not #\_ #'scope-component-character? string))
;;; Event-related types
(deftype sequence-number ()
"Event sequence numbers are 32-bit unsigned integers."
'(unsigned-byte 32))
(deftype event-id ()
"A pair of an origin id and sequence that uniquely identifies and
event."
'(cons uuid:uuid sequence-number))
(deftype timestamp-designator ()
"Name of a timestamp."
'keyword)
(deftype meta-data-designator ()
"Name of a meta-data item."
'keyword)
;;; Event-processing-related types
(deftype error-policy ()
"Objects of this type designate behaviors in case of errors."
'(or null function))
(deftype timeout ()
"Amount of seconds to wait before a timeout should occur."
'non-negative-real)
(deftype implementation-feedback ()
'(member :implemented :not-implemented))
(deftype direction ()
'(member :in-push :in-pull :out))
(deftype wire-type ()
"A certain type of data exchanged \"on the wire\" of a transport
mechanism."
'(or symbol list))
| 2,488 | Common Lisp | .lisp | 66 | 34.878788 | 76 | 0.723865 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | e8f4c6c7c53b9df11bf2be1ec386b4efb97ffa39471fd0e9902dbab7508c6919 | 25,256 | [
-1
] |
25,257 | reloading.lisp | open-rsx_rsb-cl/src/reloading.lisp | ;;;; reloading.lisp --- Code to be executed at startup/shutdown.
;;;;
;;;; Copyright (C) 2013, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
;; Reseed the `random-state' stored in `*id-random-state*'.
;;
;; This code ensures that `*id-random-state*' is reseeded at image
;; startup thereby ensuring different pseudo random ids and such for
;; subsequent program runs.
(defun reseed-id-random-state ()
(setf *id-random-state* (make-random-state t)))
(uiop:register-image-restore-hook 'reseed-id-random-state nil)
| 578 | Common Lisp | .lisp | 14 | 39.928571 | 68 | 0.729055 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 94b2509fd1047d84943a39d02c2fdf376aa3834184fbd7cb34024af06b3b50b4 | 25,257 | [
-1
] |
25,258 | builder.lisp | open-rsx_rsb-cl/src/builder.lisp | ;;;; builder.lisp --- Builder support for event class.
;;;;
;;;; Copyright (C) 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.builder
(:use
#:cl
#:alexandria
#:let-plus
#:architecture.builder-protocol
#:rsb)
(:export
#:universal-builder-for-event-data)
(:documentation
"This package contains builder support for scopes and events."))
(cl:in-package #:rsb.builder)
;;; Builder support for scopes
(defmethod node-kind ((builder t) (node scope))
'rsb:scope)
(defmethod node-relations ((builder t) (node scope))
'((:component . *)))
(defmethod node-relation ((builder t)
(relation (eql :component))
(node scope))
(scope-components node))
;;; Builder support for events
(defmethod node-kind ((builder t) (node event))
'rsb:event)
(defmethod node-initargs ((builder t) (node event))
`(:scope ,(event-scope node)
,@(when-let ((number (event-sequence-number node)))
`(:sequence-number ,number))
,@(when-let ((id (event-id node)))
`(:id ,id))
,@(when-let ((origin (event-origin node)))
`(:origin ,origin))
,@(when-let ((method (event-method node)))
`(:method ,method))))
(defmethod node-relations ((builder t) (node event))
'((:meta-data . (:map . :key))
(:timestamp . (:map . :key))
(:cause . *)
(:data . 1)))
(let+ (((&flet handle-plist (plist)
(loop :for (key target) :on plist :by #'cddr
:collect target :into targets
:collect (list :key key) :into args
:finally (return (values targets args))))))
(defmethod node-relation ((builder t)
(relation (eql :meta-data))
(node event))
(handle-plist (meta-data-plist node)))
(defmethod node-relation ((builder t)
(relation (eql :timestamp))
(node event))
(handle-plist (timestamp-plist node))))
(defmethod node-relation ((builder t)
(relation (eql :cause))
(node event))
(event-causes node))
(defmethod node-relation ((builder t)
(relation (eql :data))
(node event))
(event-data node))
;;; Utility functions
(declaim (ftype (function * (values function &optional))
universal-builder-for-event-data))
(defun universal-builder-for-event-data ()
"Return a \"peek function\"[1] that switches to the universal
builder[2] for event data.
[1] See `architecture.builder-protocol:walk-nodes'
[2] See `architecture.builder-protocol.universal-builder' package."
(let ((universal (make-instance 'architecture.builder-protocol.universal-builder:universal-builder)))
(lambda (builder relation relation-args node)
(declare (ignore builder relation-args node))
(if (eq relation :data)
(values t nil nil nil universal)
t))))
| 3,073 | Common Lisp | .lisp | 79 | 31.316456 | 103 | 0.596096 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | da2dd3a6e5c60438b8dab43805c802889aa034410ceaf3db0f307d99f53f8f25 | 25,258 | [
-1
] |
25,259 | receiving-client.lisp | open-rsx_rsb-cl/src/receiving-client.lisp | ;;;; receiving-client.lisp --- Superclass for receiving, filtering clients.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
(defclass receiving-client (participant
direction-mixin
rsb.ep:client)
((filters :type list
:accessor receiver-filters
:initform '()
:documentation
"The list of filters that events have to match in order to
be received by the participant."))
(:documentation
"This class is intended to be used as a superclass of event
processing configuration clients that receive and filter
events."))
(defmethod shared-initialize :after ((instance receiving-client)
(slot-names t)
&key
(filters '() filters-supplied?))
(when filters-supplied?
(setf (receiver-filters instance) filters)))
(defmethod print-items:print-items append ((object receiving-client))
`((:num-filters ,(length (receiver-filters object)) " |(~D)")))
(defmethod (setf receiver-filters) :around ((new-value list)
(participant receiving-client))
;; Notify interested parties of the change in the set of listeners.
(let* ((configurator (rsb.ep:client-configurator participant))
(old-value (receiver-filters participant))
(added (set-difference new-value old-value))
(removed (set-difference old-value new-value)))
(prog1
(call-next-method)
(log:debug "~@<~A~@:_~
~2@Tadded filters ~:A~@:_~
~2@Tremoved filters ~:A~
~@:>"
participant added removed)
(iter (for filter in added)
(rsb.ep:notify configurator filter :filter-added))
(iter (for filter in removed)
(rsb.ep:notify configurator filter :filter-removed)))))
| 2,082 | Common Lisp | .lisp | 45 | 35.044444 | 75 | 0.582677 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 8859810103a2710686afbf8e4c9abb1d0316377fd488b707ad3b72425ad96d78 | 25,259 | [
-1
] |
25,260 | error-handling.lisp | open-rsx_rsb-cl/src/error-handling.lisp | ;;;; error-handling.lisp --- Error handling functions used in rsb.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
;;; Useful macros
(declaim (special *in-timeout?*))
(defvar *in-timeout?* nil
"Non-nil when a timeout is active for the current thread, nil otherwise.")
(declaim (ftype (function (positive-real function) *)
call-with-restart-and-timeout))
(defun call-with-restart-and-timeout (timeout thunk)
"Call THUNK signaling a `bt:timeout' if it does not complete within
TIMEOUT seconds. Install a `cl:continue' restart around the
timeout/execution of THUNK which can be used to ignore errors and
timeouts.
If `*in-timeout?*' indicates that some other timeout is already active
for the current thread, install the restart but do not establish a
timeout. This is intended to prevent recursive timeouts."
(restart-case
;; Give THUNK TIMEOUT seconds to complete. If it takes longer,
;; allow continuing via the CONTINUE restart. If another timeout
;; is active, call THUNK without timeout. This avoids race
;; conditions between timeouts and recursive timeout handling.
(if *in-timeout?*
(funcall thunk)
(let ((*in-timeout?* t))
(bt:with-timeout (timeout)
(funcall thunk))))
(continue ()
:report (lambda (stream)
(format stream "~@<Ignore the error and continue.~@:>")))))
(defmacro with-restart-and-timeout ((timeout) &body body)
"Execute BODY signaling a `bt:timeout' if it does not complete
within TIMEOUT seconds. Install a `cl:continue' restart around the
timeout/execution of BODY which can be used to ignore errors and
timeouts.
If `*in-timeout?*' indicates that some other timeout is already active
for the current thread, install the restart but do not establish a
timeout. This is intended to prevent recursive timeouts."
`(call-with-restart-and-timeout ,timeout (lambda () ,@body)))
| 2,020 | Common Lisp | .lisp | 42 | 43.833333 | 76 | 0.720163 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | fa8941f4d4ea33dfb43beb6cc495e693dda0df63a3f76a0ea2bd601a975e32d1 | 25,260 | [
-1
] |
25,261 | configuration.lisp | open-rsx_rsb-cl/src/configuration.lisp | ;;;; configuration.lisp --- Configuration of RSB participants.
;;;;
;;;; Copyright (C) 2011-2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
(defvar *config-debug?* nil)
;;; Environment variables and configuration files
(flet ((debug (format-control &rest format-arguments)
(when *config-debug?*
(apply #'format *error-output* format-control format-arguments))))
(defun options-from-environment (&key (prefix "RSB_"))
"Obtain configuration options from environment variables."
(debug "~2@T2. Environment variables with prefix ~S~%" prefix)
#+sbcl
(let+ (((&flet name->option-name (name)
(when (starts-with-subseq prefix name)
(string->option-name (subseq name 4) #\_))))
((&flet variable->option (string)
(let+ (((raw-name value) (split-sequence #\= string :count 2))
(name (name->option-name raw-name)))
(when name
(debug "~5@T~48@<~A (mapped to ~S)~> -> ~S~%"
raw-name name value)
(cons name value))))))
(remove-if #'null (mapcar #'variable->option (sb-ext:posix-environ)))))
(defun options-from-stream (stream)
"Obtain configuration options from STREAM."
(effective-options
(iter (for line in-stream stream :using #'read-line)
(for line-num :from 1)
(with section = nil)
(let+ (((&flet trim (string)
(string-trim '(#\Space #\Tab) string)))
(content (trim (subseq line 0 (position #\# line)))))
(cond
;; Empty/comment-only line
((emptyp content))
;; Section header
((and (starts-with #\[ content) (ends-with #\] content))
(setf section (string->option-name
(subseq content 1 (1- (length content))))))
;; Value
((find #\= content)
(let+ ((index (position #\= content))
(name (string->option-name
(trim (subseq content 0 index))))
(value (trim (subseq content (1+ index))))
(path (append section name)))
(debug "~8@T~45@<~S~> -> ~S~%" path value)
(collect (cons path value))))
;; Invalid
(t
(error "~@<Syntax error in line ~D, contents ~S.~@:>"
line-num line)))))))
(defun configuration-files ()
(let+ ((raw-specs (if-let ((specs (uiop:getenv "RSB_CONFIG_FILES")))
(split-sequence #\: specs)
*default-configuration-files*))
((&flet process-spec (spec)
(switch (spec :test #'equal)
(+config-file-pwd-placeholder+
(list #P"rsb.conf"
"Current directory file"))
(+config-file-user-placeholder+
(list (merge-pathnames ".config/rsb.conf"
(user-homedir-pathname))
"User config file"))
(+config-file-system-placeholder+
(list #+unix #P"/etc/rsb.conf"
#+win32 "/rsb.conf"
"System wide config file"))
(t
(list spec "User specified config file"))))))
(mapcar #'process-spec raw-specs)))
(defun options-from-default-sources (&key
(config-files (configuration-files)))
"Combine options from the configuration sources mentioned in
CONFIG-FILES.
Default:
+ System-wide rsb.conf file (e.g. /etc/rsb.conf on UNIX)
+ User-wide rsb.conf file (e.g. ~/.config/rsb.conf on UNIX)
+ $(PWD)/rsb.conf
+ Environment Variables"
(let ((*config-debug?* (uiop:getenv "RSB_CONFIG_DEBUG")))
(debug "Configuring with sources (lowest priority first)~%")
(reduce #'merge-options
(reverse
(append (progn
(debug "~2@T1. Configuration files~%")
(iter (for (file description) in (reverse config-files))
(for i :from 1)
(with-open-file (stream file :if-does-not-exist nil)
(debug "~5@T~D. ~A ~S ~:[does not exist~;exists~]~%"
i description (namestring file) stream)
(when stream
(collect (options-from-stream stream))))))
(list (options-from-environment))))
:initial-value *default-configuration*
:from-end t))))
;;;
(defun section-options (section &optional (config *configuration*))
(let+ ((section (ensure-list section))
((&flet strip-key (option)
(cons (nthcdr (length section) (car option))
(cdr option)))))
(mapcar #'strip-key
(remove section config
:test-not #'starts-with-subseq
:key #'car))))
(defun option-value (name &optional default (config *configuration*))
"Return the value of the option named NAME in CONFIG.
Return DEFAULT, if NAME does not exist in CONFIG."
(if-let ((option (assoc name config :test #'equal)))
(cdr option)
default))
;;; Transport configuration
(defun transport-options (&optional (config *configuration*))
"Collect and return options in CONFIG that apply to transports."
(let+ (((&flet options->plist (options)
(iter (for (key . value) in options)
(cond
((length= 1 key)
(collect (first key))
(collect value))
((starts-with-subseq '(:converter :lisp) key)
;; Ignore converter configuration for now.
)))))
(options (section-options :transport config))
(transports (remove-duplicates
(mapcar (compose #'first #'car) options))))
;; Collect options for all individual transport.
(mapcar (lambda (transport)
(cons transport (options->plist
(section-options transport options))))
transports)))
(let+ (((&flet find-transport (name options)
(find name options :test #'eq :key #'first)))
((&flet inherit? (options)
(ends-with '&inherit options)))
((&flet enabled? (options)
(member (getf options :enabled) '(t "1") :test #'equal)))
((&flet deinherit (options)
(if (inherit? options)
(butlast options)
options)))
((&flet inherit (options defaults)
(let ((result (copy-list (deinherit defaults))))
(iter (for (value key) on (reverse (deinherit options)) :by #'cddr)
(setf (getf result key) value))
result)))
((&flet+ merge-entries ((transport1 &rest options)
(transport2 &rest defaults))
(list* (if (eq transport1 t) transport2 transport1)
(if (inherit? options)
(append (inherit options defaults)
(when (inherit? defaults)
'(&inherit)))
options)))))
;; Assumes that &inherit has already been processed (but &inherit
;; markers may still be present).
(defun effective-transport-options (options)
(iter (for (transport . options*) in options)
(let ((options* (deinherit options*)))
(unless (or (eq transport t) (not (enabled? options*)))
(let ((effective-options (remove-from-plist options* :enabled)))
(collect (list* transport effective-options)))))))
(defun merge-transport-options (options defaults)
(let+ ((generic (find-transport t options))
(rest (if generic
(mapcar (rcurry #'merge-entries generic) options)
(copy-list options)))
((&flet merge-one-default (default)
(let ((intermediate (if generic
(merge-entries generic default)
default)))
(if-let ((entry (find-transport (first intermediate) rest)))
(progn
(removef rest entry)
(merge-entries entry intermediate))
intermediate)))))
(append (mapcar #'merge-one-default defaults) rest))))
;;; Converter configuration
(defvar *default-converters*
'((nibbles:octet-vector . (:fundamental-void
:fundamental-bool
:fundamental-int64
:fundamental-uint32
:fundamental-int32
:fundamental-uint64
:fundamental-double
:fundamental-float
:fundamental-utf-8-string
:fundamental-bytes
:fundamental-scope
:protocol-buffer))))
(defun default-converters (&key (config *configuration*))
"Return an alist of default converters for particular wire-types
with items of the form (WIRE-TYPE . CONVERTER).
If supplied, CONFIG specifies the configuration that should be used
to determine the set of default converters. if CONFIG is not
supplied, the value of `*configuration*' is used."
(declare (ignore config))
*default-converters*)
(defun default-converter (wire-type &key (config *configuration*))
"Return the default converter for WIRE-TYPE.
If supplied, CONFIG specifies the configuration that should be used
to determine the set of default converters. if CONFIG is not
supplied, the value of `*configuration*' is used."
(cdr (assoc wire-type (default-converters :config config))))
;;; Utility functions
(defun string->option-name (string &optional (separator #\.))
"Split STRING at all occurrences of SEPARATOR, producing an option
name."
(map 'list (compose #'make-keyword #'string-upcase)
(split-sequence separator string)))
(defun merge-options (&rest options)
"Return options that result from merging OPTIONS with options
occurring earlier taking precedence over later ones."
(effective-options (apply #'append options)))
(defun effective-options (options)
"Remove \"shadowed\" options in OPTIONS and return the resulting
options."
(remove-duplicates options
:key #'car
:test #'equal
:from-end t))
;;; Set default configuration
(eval-when (:load-toplevel :execute)
(setf *configuration* (options-from-default-sources)))
| 11,065 | Common Lisp | .lisp | 230 | 34.447826 | 85 | 0.541011 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 381b4d16e144e03a8e8bab1f4e9c48d5a3e00b443eb92a77af539bb51c6f7740 | 25,261 | [
-1
] |
25,262 | scope.lisp | open-rsx_rsb-cl/src/scope.lisp | ;;;; scope.lisp --- Scope class and related functions.
;;;;
;;;; Copyright (C) 2011-2021 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
;;; `scope' class
(defclass scope ()
((components :initarg :components
:type list ; actually scope-components
:reader scope-components
:documentation
"The name components of the scope.")
(interned? :initarg :interned?
:type boolean
:accessor scope-interned?
:initform nil
:documentation
"Non-nil if the scope has been interned.")
(%string :initarg :%string
:type (or null string)
:accessor scope-%string
:initform nil
:documentation
"Caches the string representation of the scope."))
(:default-initargs
:components (missing-required-initarg 'scope :components))
(:documentation
"Instances of this class consist of a hierarchy of zero or more
names."))
(defmethod scope-string ((scope scope))
(or (scope-%string scope)
(setf (scope-%string scope)
(with-output-to-string (stream)
(write-char #\/ stream)
(dolist (component (scope-components scope))
(write-string component stream)
(write-char #\/ stream))))))
(defmethod print-object ((object scope) stream)
(print-unreadable-object (object stream :type t :identity t)
(format stream "~A~:[~; !~]"
(scope-string object) (scope-interned? object))))
(defvar +root-scope+
(make-instance 'scope :components '() :interned? t)
"The singleton instance of the root scope.")
;; scope methods
(defmethod make-scope ((thing t) &key intern?)
(declare (ignore intern?))
(error 'type-error
:datum thing
:expected-type '(or scope string scope-components)))
(defmethod make-scope ((thing scope) &key intern?)
(if intern?
(intern-scope thing)
thing))
(defmethod make-scope ((thing null) &key intern?)
(if intern?
+root-scope+
(call-next-method)))
(defmethod make-scope ((thing list) &key intern?)
(check-type thing scope-components "a list of component strings")
(let ((scope (make-instance 'scope :components thing)))
(if intern?
(intern-scope scope)
scope)))
(defmethod make-scope ((thing sequence) &key intern?)
(make-scope (coerce thing 'list) :intern? intern?))
(defun starts-with-/ (string)
(starts-with #\/ string))
(defmethod make-scope ((thing string) &key intern?)
(declare (type (not (simple-array nil)) thing))
(when (or (zerop (length thing)) (char/= (aref thing 0) #\/))
(scope-parse-error
thing 0 "~@<\"~A\" does not start with a \"/\".~@:>" thing))
(let ((scope
(loop :with string = thing
:with length = (length thing)
:with from :of-type array-index = 1
:for to :of-type array-index :from 1 :below length
:for character = (aref thing to)
:if (char= character #\/)
:if (>= from to)
:do (setf from (1+ to) string nil)
:else :collect (subseq thing from to) :into components
:and :do (setf from (1+ to))
:else
:unless (scope-component-character? character)
:do (scope-parse-error
thing to
"~@<The character ~A (~A) at position ~D is illegal.~@:>"
character (char-name character) to)
:when (and (= to (1- length)) (> length from))
:collect (subseq thing from length) :into components
:and do (setf string nil)
:finally (return (make-instance 'scope
:components components
:%string string)))))
(if intern?
(intern-scope scope)
scope)))
(declaim (ftype (function (t) (values scope &optional)) ensure-scope)
(inline ensure-scope))
(defun ensure-scope (thing)
(if (typep thing 'scope)
thing
(the (values scope &optional) (make-scope thing))))
(declaim (ftype (function (scope scope) (values t &optional)) scope=/no-coerce)
(inline scope=/no-coerce))
(defun scope=/no-coerce (scope1 scope2)
(or (eq scope1 scope2)
(and (not (and (scope-interned? scope1) (scope-interned? scope2)))
(equal (scope-components scope1) (scope-components scope2)))))
(defun scope= (thing1 thing2)
"Return non-nil if THING1 is the same scope as THING2."
(scope=/no-coerce (ensure-scope thing1) (ensure-scope thing2)))
(declaim (ftype (function (scope scope) (values t &optional)) sub-scope?/no-coerce)
(inline sub-scope?/no-coerce))
(defun sub-scope?/no-coerce (scope1 scope2)
(or (eq scope1 scope2)
(values (starts-with-subseq
(scope-components scope2) (scope-components scope1)
:test 'string=))))
(defun sub-scope? (sub super)
"Return non-nil if SUB is a sub-scope of SUPER."
(sub-scope?/no-coerce (ensure-scope sub) (ensure-scope super)))
(declaim (ftype (function (scope scope) (values t &optional)) super-scope?/no-coerce)
(inline super-scope?/no-coerce))
(defun super-scope?/no-coerce (super sub)
(sub-scope?/no-coerce sub super))
(defun super-scope? (super sub)
"Return non-nil if SUPER is a super-scope of SUB."
(sub-scope? sub super))
(defun super-scopes (scope
&key
include-self?)
"Return the list of superscopes of SCOPE. If INCLUDE-SELF? is
non-nil, SCOPE is contained in the list. Otherwise, only proper
superscopes are returned."
(let ((components (reverse (scope-components scope))))
(list* +root-scope+
(iter (for current on (if include-self? components (rest components)))
(collect (make-instance 'scope
:components (reverse current))
:at :start)))))
(defun merge-scopes (thing1 thing2)
"Return a `scope' instance that consists of the concatenated
components of THING1 and THING2."
(cond
((eq thing1 +root-scope+)
(ensure-scope thing2))
((eq thing2 +root-scope+)
(ensure-scope thing1))
(t
(make-instance
'scope
:components (append (scope-components (ensure-scope thing2))
(scope-components (ensure-scope thing1)))))))
(defun enough-scope (thing &optional (defaults +root-scope+))
"Return a `scope' that yields THING when merged with DEFAULTS.
That is, if THING is a sub-scope of DEFAULTS, the following
invariant holds:
(merge-scopes (enough-scope thing defaults) defaults) ≡ thing
If THING is a sub-scope of DEFAULTS an error is signaled."
(cond
((eq thing +root-scope+)
thing)
((eq defaults +root-scope+)
(ensure-scope thing))
(t
(let* ((thing (ensure-scope thing))
(thing-components (scope-components thing))
(defaults (ensure-scope defaults))
(default-components (scope-components defaults))
(mismatch (mismatch thing-components default-components
:test #'string=)))
(cond
((not mismatch)
+root-scope+)
((length= 0 default-components)
thing)
((< mismatch (length default-components))
(error "~@<~A is not a sub-scope of ~A.~@:>"
thing defaults))
(t
(make-instance
'scope
:components (subseq thing-components mismatch))))))))
;;; Interning scopes
(defvar *scopes* (let ((table (make-hash-table :test #'equal)))
(setf (gethash '() table) +root-scope+)
table)
"Maps scope strings to canonical `scope' instances.")
(defvar *scopes-lock* (bt:make-lock "scopes lock")
"Protects accesses to `*scopes*' during interning.")
(declaim (ftype (function (scope) (values scope t &optional)) intern-scope))
(defun intern-scope (scope)
"Return the canonical `scope' instance for SCOPE. May return SCOPE,
if it becomes or already is the canonical instance."
(if (scope-interned? scope)
(values scope t)
(bt:with-lock-held (*scopes-lock*)
(ensure-gethash (scope-components scope) *scopes*
(progn
(scope-string scope) ; force cache
(setf (scope-interned? scope) t)
scope)))))
(defmethod relative-url ((scope scope))
(make-instance 'puri:uri :path (scope-string scope)))
| 8,739 | Common Lisp | .lisp | 208 | 33.355769 | 85 | 0.601719 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | b00f9d19f3e4e9bc8286992cb1613c0316368d4e9837ac9aab4ca472fd377d15 | 25,262 | [
-1
] |
25,263 | participant.lisp | open-rsx_rsb-cl/src/participant.lisp | ;;;; participant.lisp --- A superclass for participant classes.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
(defclass participant (uuid-mixin
scope-mixin
converters-mixin
error-hook-mixin)
((id :reader participant-id)
(scope :reader participant-scope)
(transform :initarg :transform
:reader participant-transform
:initform nil
:documentation
"Stores the transform which should be applied to
processed events."))
(:documentation
"Instances of this class participate in the exchange of
notifications on one channel of the bus."))
(defmethod relative-url ((participant participant))
(puri:merge-uris
(make-instance 'puri:uri
:fragment (prin1-to-string
(participant-id participant)))
(relative-url (participant-scope participant))))
(defmethod print-object ((object participant) stream)
(print-unreadable-id-object (object stream :type t)
(format stream "~A~@[~/print-items:format-print-items/~]"
(scope-string (participant-scope object))
(remove :id (print-items:print-items object) :key #'first))))
(defmethod initialize-instance :around ((instance participant) &key)
(unwind-protect-case ()
(call-next-method)
(:abort
(ignore-errors (detach instance)))))
;;; Participant creation
(defmethod make-participant-using-class :around
((class class)
(prototype rsb.ep:client)
(scope scope)
&rest args &key
(direction (participant-direction prototype))
(transports '())
(converters (default-converters))
transform)
;; The above keyword parameters perform defaulting of the TRANSPORTS
;; and CONVERTERS keyword arguments.
;; Instantiate configurator and connectors and set everything up.
(let* (;; Remove &inherit markers in transport options and select
;; enabled transports. Remove :enabled option from options of
;; enabled transports.
(transports (or (effective-transport-options
(merge-transport-options
transports (transport-options)))
;; Signal an error if no transports have
;; been supplied.
(error 'no-transports-error
:kind (participant-kind prototype)
:scope scope)))
;; Ensure that CONVERTERS is an alist of items of the form
;; (WIRE-TYPE . CONVERTER).
(converters (if (and (listp converters) (consp (first converters)))
converters
(list (cons t converters))))
(configurator (make-instance
(ecase direction
((:in-push :in-pull) 'rsb.ep:in-route-configurator)
(:out 'rsb.ep:out-route-configurator))
:scope scope
:direction direction
:transform transform))
(connectors (rsb.transport:make-connectors
transports direction converters))
(participant (apply #'call-next-method class prototype scope
:converters converters
:configurator configurator
(remove-from-plist
args :direction :transports :converters)))
(error-hook (participant-error-hook participant)))
;; Setup the error hook of PARTICIPANT to be run for all errors
;; intercepted by CONFIGURATOR.
(setf (rsb.ep:processor-error-policy configurator)
(lambda (condition)
(hooks:run-hook error-hook condition)))
;; Associate constructed CONNECTORS to CONFIGURATOR. This attaches
;; CONNECTORS to SCOPE, performing the respective initialization
;; work.
;;
;; Note that this has to be done after the error-policy has been
;; installed in CONFIGURATOR to avoid race conditions.
(setf (rsb.ep:configurator-connectors configurator) connectors)
participant))
;; This method operates on URIs.
(defmethod make-participant ((kind t) (scope puri:uri)
&rest args &key
(transports '())
(converters (default-converters)))
(let+ (((&values scope uri-transports) (uri->scope-and-options scope)))
(apply #'make-participant kind scope
:transports (merge-transport-options uri-transports transports)
:converters converters
(remove-from-plist args :transports :converters))))
;; This method operates on strings which it turns into either URIs (if
;; the string contains ":", "//", "#" or "?") or scopes.
(defmethod make-participant ((kind t) (scope string) &rest args &key)
(apply #'make-participant kind (parse-scope-or-uri scope) args))
(defun call-with-participant-creation-restarts (participant-kind designator
normal-thunk args-changed-thunk)
(declare (type function normal-thunk args-changed-thunk))
;; We use NORMAL-THUNK and ARGS-CHANGED-THUNK in order to implement
;; the common case of not invoking any restarts efficiently.
(let+ (((&values designator designator-kind label parser)
(etypecase designator
(puri:uri (values designator :uri "URI" #'puri:parse-uri))
(scope (values designator :scope "scope" #'make-scope))))
((&labels read-new-value ()
(format *query-io* "Specify ~A (not evaluated): " label)
(force-output *query-io*)
(list (funcall parser (read-line *query-io*)))))
((&labels report (stream)
(format stream "~@<Retry creating the ~(~A~) with a ~
different ~A.~@:>"
participant-kind label))))
(declare (dynamic-extent #'read-new-value #'report))
(iter (with thunk = normal-thunk)
(restart-case
(return (funcall thunk designator))
(retry ()
:report (lambda (stream)
(format stream "~@<Retry creating the ~(~A~) ~
for ~(~A~) ~S~@:>"
participant-kind designator-kind designator)))
(use-uri (new-value)
:test (lambda (condition)
(declare (ignore condition))
(eq designator-kind :uri))
:interactive read-new-value
:report report
(setf designator new-value
thunk args-changed-thunk))
(use-scope (new-value)
:test (lambda (condition)
(declare (ignore condition))
(eq designator-kind :scope))
:interactive read-new-value
:report report
(setf designator new-value
thunk args-changed-thunk))))))
(defmethod make-participant :around ((kind t) (scope scope)
&rest args &key)
;; Install restarts around the creation attempt.
(flet ((make-participant-normal-thunk (scope)
(declare (ignore scope))
(call-next-method))
(make-participant-args-changed-thunk (scope)
(apply #'make-participant kind scope args)))
(declare (dynamic-extent #'make-participant-normal-thunk
#'make-participant-args-changed-thunk))
(call-with-participant-creation-restarts
kind scope
#'make-participant-normal-thunk
#'make-participant-args-changed-thunk)))
(defmethod make-participant :around ((kind t) (scope puri:uri)
&rest args &key)
;; Install restarts around the creation attempt.
(flet ((make-participant-normal-thunk (scope)
(declare (ignore scope))
(call-next-method))
(make-participant-args-changed-thunk (scope)
(apply #'make-participant kind scope args)))
(declare (dynamic-extent #'make-participant-normal-thunk
#'make-participant-args-changed-thunk))
(call-with-participant-creation-restarts
kind scope
#'make-participant-normal-thunk
#'make-participant-args-changed-thunk)))
| 8,635 | Common Lisp | .lisp | 178 | 35.960674 | 80 | 0.583936 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | b96f32aa69337ffb09cd8c80402a96773f323fc4a6ea0c9f44410e61128d61e5 | 25,263 | [
-1
] |
25,264 | variables.lisp | open-rsx_rsb-cl/src/variables.lisp | ;;;; variables.lisp --- Global and special variables used within RSB.
;;;;
;;;; Copyright (C) 2010-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
;;; Framework scopes
(declaim (type scope *reserved-scope*))
(defvar *reserved-scope*
(make-scope "/__rsb/" :intern? t)
"All sub-scopes of this scope should be considered reserved for
private implementation purposes.")
;;; Framework timestamps
(declaim (type list *framework-timestamps*))
(defvar *framework-timestamps* '(:create :send :receive :deliver)
"Names of timestamps which are associated to certain points in the
life of RSB events.")
;;; Pseudo random state
;;;
;;; For uuid generation and such.
(declaim (type random-state *id-random-state*))
(defvar *id-random-state* (make-random-state nil)
"Stores a `random-state' object which should be used for generation
of random IDs and similar things requiring pseudo randomness.")
;;; Configuration
(define-constant +config-file-system-placeholder+ "%system" :test #'string=)
(define-constant +config-file-user-placeholder+ "%user" :test #'string=)
(define-constant +config-file-pwd-placeholder+ "%pwd" :test #'string=)
(declaim (type list *default-configuration-files*))
(defvar *default-configuration-files*
`(,+config-file-pwd-placeholder+
,+config-file-system-placeholder+
,+config-file-user-placeholder+)
"List of configuration file names in order of decreasing priority.")
(declaim (type list *default-configuration*))
(defvar *default-configuration*
'(((:transport :socket :enabled) . "1"))
"A list of default configuration option values: these are used when
no other configuration is performed.")
(declaim (type list *configuration*))
(defvar *configuration* '()
"A list of current configuration option values.")
;;; Participant lifecycle hooks
(defvar *make-participant-hook* '()
"Handlers registered for this hook are run when a new participant is
created.
The lambda-list of handlers is
(PARTICIPANT ARGS)
where PARTICIPANT is the new participant and ARGS are the initargs
with which the participant instance was created.
Handlers have to return PARTICIPANT unless PARTICIPANT should be
replaced by some other object in which case that object has to be
returned.")
(defvar *participant-state-change-hook* '()
"Handlers of this hook are run when the state of a participant changes.
The lambda-list of handlers is
(PARTICIPANT NEW-STATE)
where PARTICIPANT is the participant whose state changed to
NEW-STATE.
One NEW-STATE applicable to all kinds of participants
is :detached.")
| 2,670 | Common Lisp | .lisp | 61 | 40.95082 | 76 | 0.751938 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | b8deef2f227f12dae291c1c53ab86add8e9f194726bf9e0608b5c9595a5558d3 | 25,264 | [
-1
] |
25,265 | listener.lisp | open-rsx_rsb-cl/src/listener.lisp | ;;;; listener.lisp --- Listeners receive events that are broadcast on a bus.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
(defclass listener (receiving-client)
((direction :allocation :class
:initform :in-push)
(handlers :type list
:accessor rsb.ep:handlers
:initform '()
:documentation
"Stores the list of handlers two which events received
by this listener should be dispatched."))
(:documentation
"Pushes events received on a channel to handlers (push style).
Consists of a set of filters, a set of handlers and has a
mechanism for dispatching matching events to these handlers."))
(register-participant-class 'listener)
(defmethod shared-initialize :after ((instance listener)
(slot-names t)
&key
(handlers '() handlers-supplied?))
(when handlers-supplied?
(setf (rsb.ep:handlers instance) handlers)))
(defmethod (setf rsb.ep:handlers) :around ((new-value list)
(listener listener))
(let* ((configurator (rsb.ep:client-configurator listener))
(old-value (rsb.ep:handlers listener))
(added (set-difference new-value old-value))
(removed (set-difference old-value new-value)))
(prog1
(call-next-method)
(log:debug "~@<~A~@:_~
~2@Tadded handlers ~:A~@:_~
~2@Tremoved handlers ~:A~
~:>"
listener added removed)
(iter (for handler in added)
(rsb.ep:notify configurator handler :handler-added))
(iter (for handler in removed)
(rsb.ep:notify configurator handler :handler-removed)))))
| 1,944 | Common Lisp | .lisp | 43 | 34.27907 | 76 | 0.582586 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 9581d604d2a0af089485394ea1ad56d3428774fef1447c9e8ef3b7c9ed879be7 | 25,265 | [
-1
] |
25,266 | macros.lisp | open-rsx_rsb-cl/src/macros.lisp | ;;;; marcos.lisp --- Convenience marcos for RSB-related functionality.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
;;; Participants
(defun call-with-active-participant (participant thunk)
"Call THUNK with PARTICIPANT as the sole argument.
Deactivate PARTICIPANT when THUNK returns or a control transfer
occurs."
(declare (type function thunk))
(unwind-protect
(funcall thunk participant)
(detach/ignore-errors participant)))
(defmacro with-active-participant ((var participant-form) &body body)
"Execute BODY with VAR bound to the result of evaluating PARTICIPANT-FORM.
Deactivate the participant when the execution of BODY ends normally
or because of a control transfer.
VAR can be NIL to indicate that BODY does not access the created
participant."
(check-type var symbol)
(let ((effective-var (or var (gensym (string '#:var)))))
`(flet ((with-participant-thunk (,effective-var)
,@(unless var `((declare (ignore ,effective-var))))
,@body))
(declare (dynamic-extent #'with-participant-thunk))
(call-with-active-participant ,participant-form #'with-participant-thunk))))
(defmacro with-active-participants (bindings &body body)
"Execute BODY with participant bindings according to BINDINGS.
Elements of BINDINGS are of the form
(VAR PARTICIPANT-FORM)
Deactivate all already constructed participants when constructing a
participant causes a control transfer or when the execution of BODY
ends normally or because of a control transfer.
VAR can be NIL to indicate that BODY does not access the created
participant."
(destructuring-bind (&optional first &rest rest) bindings
(if first
`(with-active-participant ,first
(with-active-participants ,rest ,@body))
`(progn ,@body))))
(defmacro with-participant ((var kind scope
&rest initargs &key &allow-other-keys)
&body body)
"Execute BODY with VAR bound to the participant KIND, SCOPE, INITARGS.
Deactivate the participant when the execution of BODY ends normally
or because of a control transfer.
VAR can be NIL to indicate that BODY does not access the created
participant."
(check-type var symbol)
`(with-active-participant (,var (make-participant ,kind ,scope ,@initargs))
,@body))
(defmacro with-participants (bindings &body body)
"Execute BODY with participant bindings according to BINDINGS.
Elements of BINDINGS are of the form
(VAR KIND SCOPE &rest INITARGS &key &allow-other-keys)
Deactivate all already constructed participants when constructing a
participant causes a control transfer or when the execution of BODY
ends normally or because of a control transfer.
VAR can be NIL to indicate that BODY does not access the created
participant."
(destructuring-bind (&optional first &rest rest) bindings
(if first
`(with-participant ,first
(with-participants ,rest ,@body))
`(progn ,@body))))
;;; Handlers
(defun call-with-handler (listener handler thunk)
"Call THUNK with HANDLER temporarily added to the handlers of
LISTENER."
(declare (type function handler thunk))
(unwind-protect
(progn
(push handler (rsb.ep:handlers listener))
(funcall thunk))
(removef (rsb.ep:handlers listener) handler
:test #'eq :count 1)))
(defmacro with-handler (listener
((event-var) &body handler-body)
&body body)
"Execute BODY with a handler executing HANDLER-BODY added to the
handlers of LISTENER. The handler is of the form
(lambda (EVENT-VAR) HANDLER-BODY)"
(check-type event-var symbol "a symbol")
`(flet ((with-handler-handler (,event-var) ,@handler-body)
(with-handler-thunk () ,@body))
(declare (dynamic-extent #'with-handler-handler #'with-handler-thunk))
(call-with-handler
,listener #'with-handler-handler #'with-handler-thunk)))
| 4,115 | Common Lisp | .lisp | 90 | 39.766667 | 83 | 0.708073 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 980efb5ce500dd462ed17d6608c2cb4cda23449fd479b76a6a4739a83fc3aa97 | 25,266 | [
-1
] |
25,267 | mixins.lisp | open-rsx_rsb-cl/src/mixins.lisp | ;;;; mixins.lisp --- Mixins classes used/provided by the rsb module.
;;;;
;;;; Copyright (C) 2011-2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb)
;;; `uuid-mixin'
(defclass uuid-mixin ()
((id :type uuid:uuid
:documentation
"Stores the unique id of the object."))
(:documentation
"This class can be mixed into classes that need a uuid in there
instances."))
(defmethod shared-initialize :after ((instance uuid-mixin)
(slot-name t)
&key
id)
(cond
;; If ID has been supplied, set the slot value to it.
(id
(setf (slot-value instance 'id)
(if (stringp id) (uuid:make-uuid-from-string id) id)))
;; If ID has not been supplied and the slot is unbound, set
;; it. Use the value of `*id-random-state*' to give clients
;; control over the generated ids.
((not (slot-boundp instance 'id))
(setf (slot-value instance 'id)
(let ((uuid::*uuid-random-state* *id-random-state*))
(uuid:make-v4-uuid))))))
(defmethod print-items:print-items append ((object uuid-mixin))
(let+ (((&slots-r/o id) object))
`((:id ,id " ~/rsb::print-id/"))))
;;; `scope-mixin'
(defclass scope-mixin ()
((scope :type scope
:documentation
"Stores the scope that is associated to the instance. For
long-lived and reused objects, interned scopes should be
stored."))
(:default-initargs
:scope (missing-required-initarg 'scope-mixin :scope))
(:documentation
"This mixin class is intended to be mixed into classes instances of
which have a mandatory associated scope."))
(defmethod shared-initialize :after ((instance scope-mixin)
(slot-names t)
&key
scope
(intern-scope? t))
(when scope
(setf (slot-value instance 'scope)
(make-scope scope :intern? intern-scope?))))
;;; `uri-mixin'
(defclass uri-mixin ()
((uri :type puri:uri
:documentation
"Stores the URI of the object."))
(:documentation
"This mixin class is intended to be mixed into classes instance of
which have an associated URI."))
(defmethod shared-initialize :after ((instance uri-mixin)
(slot-names t)
&key
uri)
(when uri
(setf (slot-value instance 'uri) (puri:uri uri))))
;;; `direction-mixin'
(defclass direction-mixin ()
((direction :type direction
:allocation :class
:reader participant-direction))
(:documentation
"This mixin class is intended to be mixed into classes to which a
communication direction can be associated. Examples are
`reader' -> :in-pull
`listener' -> :in-push
`informer' -> :out"))
;;; meta-data and timestamp plist mixins
(define-plist-data-mixin meta-data)
(define-plist-data-mixin timestamp)
;;; `converters-mixin'
(defclass converters-mixin ()
((converters :initarg :converters
:type list
:initform '()
:reader participant-converters
:documentation
"Stores a list of the converters available for use in
connectors of the participant. Each element is of the
form
(WIRE-TYPE . CONVERTER)
."))
(:documentation
"This mixin class adds a list of converters associated to
wire-types."))
(defmethod participant-converter ((participant converters-mixin)
(wire-type t)
&key &allow-other-keys)
;; Return the converter for WIRE-TYPE that is used by the connectors
;; of PARTICIPANT.
(mapcar #'cdr
(remove wire-type (participant-converters participant)
:key #'car
:test-not #'subtypep)))
;;; `error-hook-mixin'
(defclass error-hook-mixin ()
((error-hook :type list #|of function|#
:initform '()
:documentation
"Stores a list of functions to call in case of
errors."))
(:documentation
"This mixin class adds an error hook which is automatically
connected to a specified error policy when an instance is
created."))
(defmethod participant-error-hook ((participant error-hook-mixin))
(hooks:object-hook participant 'error-hook))
(defmethod make-participant-using-class ((class class)
(prototype error-hook-mixin)
(scope scope)
&rest args &key
(error-policy nil error-policy-supplied?))
(let ((participant (if error-policy-supplied?
(apply #'call-next-method class prototype scope
(remove-from-plist args :error-policy))
(call-next-method))))
(when error-policy
(hooks:add-to-hook (participant-error-hook participant) error-policy))
participant))
| 5,352 | Common Lisp | .lisp | 130 | 30.453846 | 83 | 0.573518 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | b46684e4ee7ca201d1bd2a3d4f82df5020cefde15647eb75925c73753c7821ed | 25,267 | [
-1
] |
25,268 | out-route-configurator.lisp | open-rsx_rsb-cl/src/event-processing/out-route-configurator.lisp | ;;;; out-route-configurator.lisp --- Configurator class for out-direction processing.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.event-processing)
(defclass out-route-configurator (configurator)
()
(:default-initargs
:direction :out)
(:documentation
"Configure out-direction connectors and a processor for a client.
The client generally is an event-sending participant."))
(defmethod collect-processor-mixins append ((configurator out-route-configurator))
'(error-policy-handler-mixin
restart-handler-mixin
broadcast-processor))
;;; Connectors
(defmethod notify ((configurator out-route-configurator)
(connector t)
(action (eql :connector-added)))
(let+ (((&structure-r/o configurator- processor) configurator))
(call-next-method)
(log:trace "~@<~A is connecting ~A -> ~A~@:>"
configurator processor connector)
(push connector (handlers processor))))
(defmethod notify ((configurator out-route-configurator)
(connector t)
(action (eql :connector-removed)))
(let+ (((&structure-r/o configurator- processor) configurator))
(log:trace "~@<~A is disconnecting ~A -> ~A~@:>"
configurator processor connector)
(removef (handlers processor) connector :count 1)
(call-next-method)))
| 1,452 | Common Lisp | .lisp | 34 | 36.794118 | 85 | 0.673281 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 2fb0c82739c1c893fbee291d993b814d1f6ebe1e1d3fcf5680e04bb65af158f8 | 25,268 | [
-1
] |
25,269 | pull-processor.lisp | open-rsx_rsb-cl/src/event-processing/pull-processor.lisp | ;;;; pull-processor.lisp --- Pull-based processor implementation.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.event-processing)
(defclass pull-processor ()
((connectors :initarg :connectors
:type list
:accessor processor-connectors
:initform '()
:documentation
"Stores a list of connector instances from which the
processor retrieves events.")
(current-event :accessor processor-current-event
:initform nil
:documentation
"Stores the event currently being retrieved from a
connector."))
(:documentation
"Allows pull-based, blocking and non-blocking retrieval of events
from multiple connectors.
To achieve this, the processor is added to the handler list of
each connector. When asked to retrieve an event, it walks through
its list of connectors, asking each connector to emit an event
until one succeeds. The emitted event is dispatched to the
processor via the `handle' interface. This enables arbitrary event
processing by methods on `handle' in the usual way."))
(defmethod notify ((processor pull-processor)
(connector t)
(action (eql :connector-added)))
(log:trace "~@<~A is storing added connector ~A~@:>" processor connector)
(push connector (processor-connectors processor)))
(defmethod notify ((processor pull-processor)
(connector t)
(action (eql :connector-removed)))
(log:trace "~@<~A is deleting removed connector ~A~@:>" processor connector)
(removef (processor-connectors processor) connector :count 1))
(defmethod emit :before ((processor pull-processor)
(block? t))
;; Warn the caller that we cannot currently block on multiple
;; connectors properly.
(when (and (> (length (processor-connectors processor)) 1)
block?)
(warn "~@<Requested blocking emit for multiple connectors; This ~
does not work properly, yet.~@:>")))
(defmethod emit ((processor pull-processor)
(block? t))
;; Ask connectors associated to PROCESSOR to emit an event. Return
;; the event or maybe nil when BLOCK? is nil.
(let+ (((&structure processor- connectors current-event) processor))
(setf current-event nil)
;; Round-robin for multiple connectors in non-blocking mode.
(iter (some (rcurry #'emit block?)
(setf connectors (rotate connectors -1)))
(until (or current-event (not block?))))
current-event))
(defmethod handle ((processor pull-processor)
(event event))
;; Store EVENT in PROCESSOR so it can be returned from the
;; surrounding `emit' call.
(setf (processor-current-event processor) event))
| 2,973 | Common Lisp | .lisp | 62 | 39.516129 | 78 | 0.649328 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | d0e7f2c3f850dbdea3b3fd2f56889843f036d4f3574da76d5d73649c161381ae | 25,269 | [
-1
] |
25,270 | package.lisp | open-rsx_rsb-cl/src/event-processing/package.lisp | ;;;; package.lisp --- Package definition for event-processing module.
;;;;
;;;; Copyright (C) 2011-2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.event-processing
(:nicknames
#:rsb.ep)
(:use
#:cl
#:alexandria
#:iterate
#:let-plus
#:more-conditions
#:rsb)
;; Variables
(:export
#:*event-parts*)
;; Subscription-related types
(:export
#:subscription
#:subscription-scope
#:subscribed
#:unsubscribed)
;; Dispatching-related types
(:export
#:scope-and-event
#:scope-and-event-scope
#:scope-and-event-event)
;; Push source protocol
(:export
#:handlers)
;; Pull source protocol
(:export
#:emit)
;; Sink protocol
(:export
#:handle)
;; Dispatching processor protocol
(:export
#:dispatch)
;; Processor access protocol
(:export
#:access?)
;; Notification protocol
(:export
#:notify)
;; Processor class family
(:export
#:make-processor-class
#:ensure-processor-class
#:clear-processor-classes
#:processor-classes)
;; Configurator protocol
(:export
#:make-processor
#:collect-processor-mixins)
;; `configurator' class
(:export
#:configurator
#:configurator-scope
#:configurator-direction
#:configurator-processor
#:configurator-connectors
#:configurator-transform)
;; `in-route-configurator' class
(:export
#:in-route-configurator
#:configurator-filters)
;; `out-route-configurator' class
(:export
#:out-route-configurator)
;; `broadcast-processor' class
(:export
#:broadcast-processor)
;; `filtering-processor-mixin' class
(:export
#:filtering-processor-mixin
#:processor-filters)
;; `deliver-timestamp-mixin' class
(:export
#:deliver-timestamp-mixin)
;; `error-policy-mixin' class
(:export
#:error-policy-mixin
#:processor-error-policy
#:apply-error-policy
#:call-with-error-policy
#:with-error-policy)
;; `error-policy-dispatcher-mixin' class
(:export
#:error-policy-dispatcher-mixin)
;; `restart-dispatcher-mixin' class
(:export
#:restart-dispatcher-mixin)
;; `error-policy-handler-mixin' class
(:export
#:error-policy-handler-mixin)
;; `restart-handler-mixin' class
(:export
#:restart-handler-mixin)
;; `transform-mixin' class
(:export
#:transform-mixin
#:processor-transform)
;; `sink-dispatcher-mixin'
(:export
#:sink-dispatcher-mixin)
;; `client' class and protocol
(:export
#:client
#:client-configurator)
;; `scope-trie'
(:export
#:scope-trie
#:make-scope-trie
#:scope-trie-get ; also setf
#:scope-trie-rem
#:scope-trie-map
#:scope-trie-update)
;; `sink-scope-trie'
(:export
#:sink-scope-trie
#:make-sink-scope-trie
#:sink-scope-trie-add
#:sink-scope-trie-remove)
;; Exported for unit test
(:export
#:merge-implementation-infos)
(:documentation
"A protocol, classes and methods for routing and processing of
events."))
| 3,045 | Common Lisp | .lisp | 132 | 19.393939 | 69 | 0.685417 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 6afbcc89ffcba318d257269cbd9a9e60a6b877f60720c68433b881c4901d2342 | 25,270 | [
-1
] |
25,271 | processor-mixins.lisp | open-rsx_rsb-cl/src/event-processing/processor-mixins.lisp | ;;;; processor-mixins.lisp --- Mixin classes for processor classes.
;;;;
;;;; Copyright (C) 2013-2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.event-processing)
;;; `error-policy-mixin' class
(defclass error-policy-mixin ()
((error-policy :initarg :error-policy
:type (or null function)
:accessor processor-error-policy
:initform nil
:documentation
"Stores the policy that should be applied in case of
errors.
Nil or a function to be called in case of dispatch
errors. Functions will be called with the condition
object is sole argument. Functions installed here
should be prepared to be called from multiple
threads simultaneously."))
(:documentation
"Intended to be mixed into classes that need to handle conditions
according to a client-supplied policy."))
(defmethod apply-error-policy ((processor error-policy-mixin)
(condition t))
(if-let ((policy (processor-error-policy processor)))
(funcall policy condition)
(log:warn "~@<~A does not have a error handling policy installed; ~
unwinding~@:>"
processor)))
(defmacro with-error-policy ((processor) &body body)
"Execute BODY with a condition handler that applies the error policy
of processor."
`(flet ((with-error-policy-thunk () ,@body))
(declare (dynamic-extent #'with-error-policy-thunk))
(call-with-error-policy ,processor #'with-error-policy-thunk)))
(defun call-with-error-policy (processor thunk)
"Call THUNK with a handler that applies PROCESSOR's error policy.
While PROCESSOR's error policy is applied, an equivalent handler is
established allow error during application of the error policy to
be handle by the error policy."
(declare (type function thunk))
(flet ((apply-policy (condition)
(with-error-policy (processor)
(apply-error-policy processor condition))))
(declare (dynamic-extent #'apply-policy))
(handler-bind ((error #'apply-policy)) (funcall thunk))))
;; Mixin classes `{error-policy,restart}-{dispatcher,handler}-mixin'
(macrolet
((define-error-policy+restart-mixins (method name)
(let ((error-policy-class-name (symbolicate
'#:error-policy- name '#:-mixin))
(restart-class-name (symbolicate
'#:restart- name '#:-mixin)))
`(progn
(defclass ,error-policy-class-name ()
()
(:documentation
,(format nil "This mixin class is intended to be mixed ~
into processor classes that perform ~
potentially error signaling tasks in ~
their `~(~A~)' methods. This class adds ~
an :around method on ~:*`~(~A~)' that ~
installs restarts for error recovery and ~
optionally calls an error policy ~
function."
name)))
(defmethod ,method :around ((processor ,error-policy-class-name)
(data t))
;; In case of an error, call the error-policy
;; function of processor, if any.
(with-error-policy (processor) (call-next-method)))
(defclass ,restart-class-name ()
()
(:documentation
,(format nil "This mixin class is intended to be mixed ~
into processor class that want to ~
establish a `continue' restart around the ~
execution of the `~(~A~)' method"
name)))
(defmethod ,method :around ((processor ,restart-class-name)
(data t))
;; Establish `continue' restart around call to the next `handle'
;; method.
(restart-case
(call-next-method)
(continue (&optional condition)
:report (lambda (stream)
(format stream "~@<Ignore the failure to ~
~S datum ~A in ~A.~@:>"
',method data processor))
(declare (ignore condition)))))))))
(define-error-policy+restart-mixins dispatch dispatcher)
(define-error-policy+restart-mixins handle handler))
;;; Mixin class `filtering-processor-mixin'
(defclass filtering-processor-mixin ()
((filter :initarg :filter
:type (or null rsb.filter:conjoin-filter)
:accessor processor-%filter
:initform nil
:documentation
"When not null, the filter object is used to hold a list of
filters that act in a conjunctive manner."))
(:documentation
"Adds filtering of events before further processing.
Processors of this kind maintain a list of filters that can be
accessed and modified using the `processor-filters'
accessor. Events are dropped in a method on `handle' before any
further processing unless they match all filters."))
(defmethod processor-filters ((processor filtering-processor-mixin))
(when-let ((filter (processor-%filter processor)))
(rsb.filter:filter-children filter)))
(defmethod (setf processor-filters) ((new-value null)
(processor filtering-processor-mixin))
(setf (processor-%filter processor) nil))
(defmethod (setf processor-filters) ((new-value list)
(processor filtering-processor-mixin))
(if-let ((filter (processor-%filter processor)))
(setf (rsb.filter:filter-children filter) new-value)
(setf (processor-%filter processor)
(make-instance 'rsb.filter:conjoin-filter :children new-value)))
new-value)
(defmethod handle :around ((processor filtering-processor-mixin)
(event event))
;; Terminate processing of EVENT unless it matches PROCESSOR's
;; filters.
(if-let ((filter (processor-%filter processor)))
(when (rsb.filter:matches? filter event)
(call-next-method))
(call-next-method)))
;;; `deliver-timestamp-mixin' class
(defclass deliver-timestamp-mixin ()
()
(:documentation
"Can be mixed into event processor classes that used in event
delivery contexts to attach :deliver timmestamps to processed
events."))
(defmethod handle :before ((processor deliver-timestamp-mixin)
(event event))
;; Attach a :deliver timestamp to EVENT.
(setf (timestamp event :deliver) (local-time:now)))
;;; `transform-mixin' class
(defclass transform-mixin ()
((transform :initarg :transform
:reader processor-transform
:documentation
"Stores a transform (in the sense of being usable with
`transform!') that should be applied to all handled data."))
(:default-initargs
:transform (missing-required-initarg 'transform-mixin :transform))
(:documentation
"Adds the ability to apply a transform to all handled data."))
(defmethod handle :around ((sink transform-mixin) (data t))
(call-next-method sink (rsb.transform:transform! (processor-transform sink) data)))
;;; `sink-dispatcher-mixin'
(defclass sink-dispatcher-mixin ()
((sinks :accessor processor-%sinks
:initform (make-sink-scope-trie)
:documentation
"Maps scopes to subscribed sinks."))
(:documentation
"Intended to be mixed into classes which dispatch based on a scope tree."))
(defmethod notify ((recipient sink-dispatcher-mixin)
(subject t)
(action subscribed))
(let ((sinks (processor-%sinks recipient))
(scope (subscription-scope action)))
(sink-scope-trie-add sinks scope subject)
(log:debug "~@<Scope trie of ~A after adding ~
~A:~@:_~/rsb.ep::print-trie/~@:>"
recipient subject sinks)))
(defmethod notify ((recipient sink-dispatcher-mixin)
(subject t)
(action unsubscribed))
(let ((sinks (processor-%sinks recipient))
(scope (subscription-scope action)))
(sink-scope-trie-remove sinks scope subject)
(log:debug "~@<Scope trie of ~A after removing ~
~A:~@:_~/rsb.ep::print-trie/~@:>"
recipient subject sinks)))
(defmethod dispatch ((processor sink-dispatcher-mixin)
(event scope-and-event))
(let+ ((scope (scope-and-event-scope event))
((&flet do-scope (components sinks)
(declare (ignore components))
(handle sinks (scope-and-event-event event)))))
(declare (dynamic-extent #'do-scope))
(scope-trie-map #'do-scope scope (processor-%sinks processor))))
| 9,137 | Common Lisp | .lisp | 188 | 37.398936 | 85 | 0.604419 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | aa3d5b84bbeeb9aeedca775697e38b85d110faba78ead57bb3460219f31c527d | 25,271 | [
-1
] |
25,272 | util.lisp | open-rsx_rsb-cl/src/event-processing/util.lisp | ;;;; util.lisp --- Utility functions used in the event-processing module.
;;;;
;;;; Copyright (C) 2011, 2012, 2013 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.event-processing)
(defun merge-implementation-infos (&optional info1 info2)
(cond
((and (not info1) (not info2))
:implemented)
((and (eq info1 :implemented) (eq info2 :implemented))
:implemented)
(t
:not-implemented)))
| 466 | Common Lisp | .lisp | 14 | 30.071429 | 73 | 0.684444 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 30dc888b091941edb64a8f4cb4bf419a200f30913864a2492268816a4d759852 | 25,272 | [
-1
] |
25,273 | protocol.lisp | open-rsx_rsb-cl/src/event-processing/protocol.lisp | ;;;; protocol.lisp --- Protocols provided by the event-processing module.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.event-processing)
;;; Push source protocol
;;;
;;; This protocol is provided by event sources that emit events
;;; without requiring an external trigger, for example a thread
;;; polling a network connection.
(defgeneric handlers (source)
(:documentation
"Return the handlers associated to SOURCE."))
(defgeneric (setf handlers) (new-value source)
(:documentation
"Set the list of handlers associated to SOURCE to NEW-VALUE."))
;;; Pull source protocol
;;;
;;; This protocol is provided by event sources that emit events only
;;; after being triggered externally. This external triggering is
;;; achieve by calling `emit' with such a source.
(defgeneric emit (source block?)
(:documentation
"Block until an event is available from SOURCE."))
;;; Sink protocol
(defgeneric handle (sink data)
(:documentation
"Put DATA into SINK.
SINK may for example process, relay or discard DATA."))
;;; Default behavior
(defmethod handle ((sink function) (data t))
;; If SINK is a function, call it with DATA.
(funcall sink data))
(defmethod handle ((sink list) (data t))
;; If SINK is a list, treat it as a list of sinks and let each
;; contained sink handle DATA.
(map nil (rcurry #'handle data) sink))
;;; Dispatching processor protocol
(defgeneric dispatch (processor event)
(:documentation
"Dispatch EVENT in the manner implemented by PROCESSOR.
This may imply calling some handlers, for example."))
;;; Processor access protocol
;;;
;;; This protocol allows determining which parts of events are not
;;; accessed (read or written) by given processes (such as filters,
;;; transforms, or converters) and thus potentially omitting creating,
;;; transmitting or (de)serializing these parts.
(defvar *event-parts*
'((:scope . (:accessors ((event-scope () (:read :write)))))
(:origin . (:accessors ((event-origin () (:read :write))
(event-id () (:read )))))
(:sequence-number . (:accessors ((event-sequence-number () (:read :write))
(event-id () (:read )))))
(:method . (:accessors ((event-method () (:read :write)))))
(:data . (:accessors ((event-data () (:read :write)))))
(:meta-data . (:accessors ((rsb:meta-data-plist () (:read ))
(rsb:meta-data-alist () (:read ))
(rsb:meta-data (key) (:read :write)))))
(:timestamp . (:accessors ((rsb:timestamp-plist () (:read ))
(rsb:timestamp-alist () (:read ))
(rsb:timestamp (key) (:read :write)))))
(:causes . (:accessors ((event-causes () (:read :write))))))
"Parts of events with access and mode information.
Entries are of the form:
(PART . (:accessors ACCESSORS)
where PART is a symbol naming the part and ACCESSORS is a list of
elements of the form
(ACCESSOR-NAME LAMBDA-LIST MODES)
where ACCESSOR-NAME is the name of the read function for accessing
PART of an event and LAMBDA-LIST is the lambda-list of that
function. MODES is a list containing one or both of :read
and :write.")
(defgeneric access? (processor part mode)
(:documentation
"Return true if PROCESSOR needs MODE access to PART of events."))
;; Default behavior
(defmethod access? ((processor t) (part t) (mode t))
;; Since we do not know which PART and MODE values will be defined
;; in the future, we can only default to false.
;;
;; This default behavior is slightly dangerous because processor
;; code that is not aware of the access protocol will claim not
;; needing any parts.
nil)
(defmethod access? ((processor sequence) (part t) (mode t))
(some (rcurry #'access? part mode) processor))
(defmethod access? ((processor t) (part sequence) (mode t))
(some (lambda (part) (access? processor part mode)) part))
;;; Filterting processor protocol
(defgeneric processor-filters (processor)
(:documentation
"Return the list of filters applied by PROCESSOR."))
(defgeneric (setf processor-filters) (new-value processor)
(:documentation
"Set the list of filters applied by PROCESSOR to NEW-VALUE."))
;;; Notification protocol
(defgeneric notify (recipient subject action)
(:documentation
"When ACTION is either :filter-added or :filter-removed, methods
should return one of the symbols :not-implemented or :implemented
to indicate whether the combination of the filter SUBJECT and
ACTION could be implemented by RECIPIENT."))
;;; Default behavior
(defmethod notify ((recipient t) (subject t) (action t))
;; The default behavior is to do nothing.n
(values))
(defmethod notify ((recipient t)
(subject t)
(action (eql :filter-added)))
;; The default behavior for filter actions is to do nothing and
;; state the fact.
:not-implemented)
(defmethod notify ((recipient t)
(subject t)
(action (eql :filter-removed)))
;; The default behavior for filter actions is to do nothing and
;; state the fact.
:not-implemented)
;;; Error policy protocol
(defgeneric apply-error-policy (processor condition)
(:documentation
"Apply the error handling policy of PROCESSOR to CONDITION."))
;;; Configurator protocol
(defgeneric make-processor (configurator
&rest args
&key &allow-other-keys)
(:documentation
"Make and return a suitable processor instance for CONFIGURATOR.
Methods of this generic function will usually call
`collect-processor-mixins' and `ensure-processor-class' obtain the
desired class of the processor being made. ARGS are passed to
`make-instance' after the class has been determined."))
(defgeneric collect-processor-mixins (configurator)
(:method-combination append)
(:documentation
"Return a list of names of mixin classes which should be combined
to make the processor class for CONFIGURATOR."))
| 6,453 | Common Lisp | .lisp | 139 | 41.071942 | 85 | 0.660236 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 9f51089a1b198195923954bcfc5eb813c3b0239aa960bc2217b80bf10cfed7f1 | 25,273 | [
-1
] |
25,274 | types.lisp | open-rsx_rsb-cl/src/event-processing/types.lisp | ;;;; types.lisp --- Mixin classes for processor classes.
;;;;
;;;; Copyright (C) 2016, 2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.event-processing)
;;; Subscription-related types
(defstruct (subscription (:constructor nil) (:predicate nil) (:copier nil))
(scope nil :type scope :read-only t))
(declaim (inline subscribed))
(defstruct (subscribed
(:include subscription)
(:constructor subscribed (scope))
(:predicate nil) (:copier nil)))
(declaim (inline unsubscribed))
(defstruct (unsubscribed
(:include subscription)
(:constructor unsubscribed (scope))
(:predicate nil) (:copier nil)))
;;; Dispatching-related types
(declaim (inline scope-and-event))
(defstruct (scope-and-event
(:constructor scope-and-event (scope event))
(:copier nil))
(scope nil :type scope :read-only t)
(event nil :type t :read-only t))
| 995 | Common Lisp | .lisp | 26 | 32.769231 | 75 | 0.659044 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | af4ee9fc45b64dee42e4b47b403b99c2b5aa6ce29d4904a2beb237aa0180e462 | 25,274 | [
-1
] |
25,275 | client.lisp | open-rsx_rsb-cl/src/event-processing/client.lisp | ;;;; client.lisp --- A client that knows its configurator.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.event-processing)
(defclass client ()
((configurator :initarg :configurator
:type configurator
:reader client-configurator
:documentation
"Stores the configurator instance working for this
client."))
(:default-initargs
:configurator (missing-required-initarg 'client :configurator))
(:documentation
"A client of the event processing subsystem in the sense that they
have an associated `configurator'."))
(defmethod transport-specific-urls ((component client))
;; Return a list of transport URLs for connectors used by COMPONENT.
(remove-duplicates
(mapcar (lambda (connector)
(uiop:symbol-call '#:rsb.transport '#:connector-relative-url
connector component))
(configurator-connectors (client-configurator component)))
:test #'puri:uri=))
(defmethod detach ((participant client))
;; Let PARTICIPANT's configurator do the heavy lifting.
(detach (client-configurator participant)))
| 1,255 | Common Lisp | .lisp | 29 | 36.241379 | 73 | 0.675123 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 478deb31147532e327f2f606706d17d3812875a0094f97c7de8da7fe91eb79d0 | 25,275 | [
-1
] |
25,276 | in-route-configurator.lisp | open-rsx_rsb-cl/src/event-processing/in-route-configurator.lisp | ;;;; in-route-configurator.lisp --- Configurator for incoming event route.
;;;;
;;;; Copyright (C) 2011-2017 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.event-processing)
(defclass in-route-configurator (configurator)
((filters :type list
:accessor configurator-filters
:initform '()
:documentation
"Stores the list of filters installed by the client."))
(:documentation
"Configure in-direction connectors, filters and a processor for a client.
The client generally is an event receiving participant."))
(defmethod collect-processor-mixins append ((configurator in-route-configurator))
`(error-policy-handler-mixin
restart-handler-mixin
restart-dispatcher-mixin
filtering-processor-mixin
deliver-timestamp-mixin
,(ecase (configurator-direction configurator)
(:in-push 'broadcast-processor)
(:in-pull 'pull-processor))))
;;; Connectors
(defmethod notify ((configurator in-route-configurator)
(connector t)
(action (eql :connector-added)))
(let+ (((&structure-r/o configurator- filters processor) configurator))
(call-next-method)
;; Notify new connector regarding filters.
(iter (for filter in filters)
(log:trace "~@<~A is adding filter ~A to ~A~@:>"
configurator filter connector)
(unless (eq (notify connector filter :filter-added) :implemented)
(pushnew filter (processor-filters processor))))
;; Notify PROCESSOR regarding added CONNECTOR and add PROCESSOR to
;; CONNECTOR's handlers.
(notify processor connector action)
(log:trace "~@<~A is connecting ~A -> ~A~@:>"
configurator connector processor)
(push processor (handlers connector))))
(defmethod notify ((configurator in-route-configurator)
(connector t)
(action (eql :connector-removed)))
(let+ (((&structure-r/o configurator- filters processor) configurator))
;; Remove processor from CONNECTOR's handler list and notify
;; processor regarding removed CONNECTOR.
(log:trace "~@<~A is disconnecting ~A -> ~A~@:>"
configurator connector processor)
(removef (handlers connector) processor :count 1)
(notify processor connector action)
;; Notify CONNECTOR regarding removed filters.
(iter (for filter in filters)
(log:trace "~@<~A is removing filter ~A from ~A~@:>"
configurator filter connector)
(notify connector filter :filter-removed))
(call-next-method)))
;;; Filters
(defmethod notify ((configurator in-route-configurator)
(filter t)
(action (eql :filter-added)))
;; Add FILTER to CONFIGURATOR's filter list and notify its
;; connectors and processor.
(let+ (((&structure configurator- connectors processor filters)
configurator))
;; Add FILTER to the filter list of CONFIGURATOR.
(push filter filters)
;; Notify all connectors about the added filter. Unless all
;; connectors implemented the filter, add it to the processor.
(case (reduce #'merge-implementation-infos connectors
:key (rcurry #'notify filter action))
(:not-implemented
(push filter (processor-filters processor))))
;; We implemented the filter either way.
:implemented))
(defmethod notify ((configurator in-route-configurator)
(filter t)
(action (eql :filter-removed)))
;; Remove FILTER from CONFIGURATOR's filter list and notify its
;; connectors and processor.
(let+ (((&structure configurator- connectors processor filters)
configurator))
;; Remove FILTER from PROCESSOR's filter list.
(removef (processor-filters processor) filter)
;; Notify all connectors about the removed FILTER. Implementation
;; info do not matter in this case.
(map nil (rcurry #'notify filter action) connectors)
;; Remove FILTER from the filter list of CONFIGURATOR.
(removef filters filter :count 1)
:implemented))
;;; Handlers
(defmethod notify ((configurator in-route-configurator)
(handler t)
(action (eql :handler-added)))
(let ((processor (configurator-processor configurator)))
(log:trace "~@<~A is adding handler ~A to ~A~@:>"
configurator handler processor)
(push handler (handlers processor))))
(defmethod notify ((configurator in-route-configurator)
(handler t)
(action (eql :handler-removed)))
(let ((processor (configurator-processor configurator)))
(log:trace "~@<~A is removing handler ~A from ~A~@:>"
configurator handler processor)
(removef (handlers processor) handler)))
| 4,937 | Common Lisp | .lisp | 106 | 38.858491 | 81 | 0.657999 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 54d8008ec66bb43a962869cba1e1516a31f11777d7e1cea32f6bd4072ea78f44 | 25,276 | [
-1
] |
25,277 | scope-trie.lisp | open-rsx_rsb-cl/src/event-processing/scope-trie.lisp | ;;;; scope-trie.lisp --- [sink-]scope-trie data structures.
;;;;
;;;; Copyright (C) 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
;;;; A trie data structure in which paths consist of scope
;;;; components. Accesses are lock-free with atomic updates.
(cl:in-package #:rsb.event-processing)
(define-constant +no-value+ '%no-value)
;;; Scope trie data structure
;;;
;;; A trie using the components of scopes:
;;;
;;; / -> %NO-VALUE
;;; ├─foo -> %NO-VALUE
;;; │ ├─bar -> "/foo/bar"
;;; │ └─baz -> "/foo/baz"
;;; └─fez -> %NO-VALUE
;;; ├─whoop -> "/fez/whoop"
;;; └─moo -> "/fez/moo"
;;;
;;; The trie is represented as a tree of nodes of the form
;;;
;;; ┌──────────┐
;;; │ node │ ┌──────────┐
;;; ├──────────┤ │ state │
;;; │ state ●──┼────▶├──────────┤
;;; └──────────┘ │ value │ ┌──────────────────┐
;;; │ edges ●──┼────▶│ scope-node-edges │
;;; └──────────┘ └──────────────────┘
;;;
;;; The state is separate from the node to allow atomically
;;; compare-and-swapping the value and edges
;;; simultaneously.
;;;
;;; `scope-node-edges' is an abstract data structure mapping scope
;;; components to child nodes of the node. Dynamic switchover between
;;; multiple implementations can be used to implement different usage
;;; patterns efficiently w.r.t. computation time and memory use.
(deftype scope-node-edges ()
`list)
(declaim (ftype (function () (values scope-node-edges &optional))
make-empty-scope-node-edges)
(inline make-empty-scope-node-edges))
(defun make-empty-scope-node-edges ()
'())
(declaim (ftype (function (scope-node-edges) (values boolean &optional))
scope-node-edges-empty?)
(inline scope-node-edges-empty?))
(defun scope-node-edges-empty? (edges)
(null edges))
(declaim (ftype (function (string scope-node-edges) (values t &optional))
scope-node-edges-find-edge)
(inline scope-node-edges-find-edge))
(defun scope-node-edges-find-edge (component edges)
(cdr (assoc component edges :test #'string=)))
(declaim (ftype (function (string t scope-node-edges)
(values scope-node-edges &optional))
scope-node-edges-add-edge)
(inline scope-node-edges-add-edge))
(defun scope-node-edges-add-edge (component node edges)
(acons component node edges))
(declaim (ftype (function (string t scope-node-edges)
(values scope-node-edges &optional))
scope-node-edges-remove-edge)
(inline scope-node-edges-remove-edge))
(defun scope-node-edges-remove-edge (component node edges)
(declare (ignore component))
(remove node edges :test #'eq :key #'cdr :count 1))
(declaim (inline make-node-state make-empty-node-state))
(defstruct (node-state
(:constructor make-node-state (value edges))
(:constructor make-empty-node-state ())
(:predicate nil)
(:copier nil))
(value +no-value+ :read-only t)
(edges (make-empty-scope-node-edges) :type scope-node-edges :read-only t))
(declaim (inline make-node))
(defstruct (node
(:constructor make-scope-trie ())
(:constructor make-node (state))
(:predicate nil)
(:copier nil))
(state (make-empty-node-state) :type (or null node-state)))
(deftype scope-trie () 'node)
;; Call FUNCTION with TRIE and its children on the path described by
;; COMPONENTS.
;;
;; EXTEND? controls whether nodes on the path should be added to TRIE
;; if they do not already exist.
;;
;; LEAF-ONLY? controls whether FUNCTION is called for all nodes
;; corresponding to prefixes of COMPONENTS or only for the node
;; corresponding to the full path COMPONENTS.
(defun scope-trie-%map (function components trie extend? leaf-only?)
(declare (type function function)
(type list components)
(type node trie))
(tagbody
;; We restart here when encountering an in-progress deletion.
:global-start
(let+ ((deleting?)
((&labels visit (path path-tail component rest node)
(tagbody
;; We restart here in case CASing the node state
;; fails, redoing all computations to construct the
;; new node state.
:start
(let* ((old-state (or (node-state node)
;; Restart if NODE being
;; deleted.
(if deleting?
(return-from visit node)
(go :global-start))))
;; Call FUNCTION if inner nodes have been
;; requested or we have reached the end of
;; COMPONENTS.
(new-state (if (or (not component) (not leaf-only?))
(funcall function path old-state)
old-state))
(old-value (node-state-value (or new-state old-state)))
(old-edges (node-state-edges (or new-state old-state)))
(next nil))
(cond
;; End of COMPONENTS => stop traversal.
((not component))
;; A node corresponding to COMPONENT does
;; already exist => descend into that node.
((setf next (scope-node-edges-find-edge component old-edges)))
;; Such a node does not exist, but we are
;; supposed to extend the trie => create a new
;; node.
(extend?
(let ((new-child (make-node (make-empty-node-state))))
(setf new-state (make-node-state
old-value (scope-node-edges-add-edge
component new-child old-edges))
next new-child))))
;; if we have a next node to visit, do it
;; (including ancestors), then check whether it
;; should be deleted.
(when next
(let* ((component* (first rest))
(rest* (rest rest))
(cell (list component))
(path (if path
(progn
(setf (cdr path-tail) cell)
path)
cell))
(child (visit path cell component* rest* next)))
(declare (dynamic-extent cell))
(unless (node-state child)
(setf deleting? t)
(let ((new-edges (scope-node-edges-remove-edge
component child old-edges)))
(setf new-state
(unless (and (eq old-value +no-value+)
(scope-node-edges-empty? new-edges))
(make-node-state old-value new-edges)))))))
;; Cannot delete root.
(when (and (not new-state) (eq node trie))
(setf new-state (make-empty-node-state)))
;; Try to CAS NODE's state. Restart, if it doesn't
;; work.
(unless (or (eq new-state old-state)
(eq (sb-ext:compare-and-swap
(node-state node) old-state new-state)
old-state))
(go :start))
(return-from visit node))))))
(declare (dynamic-extent #'visit))
(visit '() nil (first components) (rest components) trie))))
(macrolet
((define-scope-trie-function (name parameters &body body)
(let+ (((&values body declarations documentation)
(parse-body body :documentation t)))
`(defun ,name (,@parameters scope trie)
,@(when documentation `(,documentation))
,@declarations
(macrolet
((visit ((scope-var state-var extend? leaf-only?) &body body)
(let+ (((&values scope-var ignore-scope-var)
(or scope-var (values (gensym) t)))
((&with-gensyms visit-name)))
`(flet ((,visit-name (,scope-var ,state-var)
,@(when ignore-scope-var
`((declare (ignore ,scope-var))))
,@body))
(declare (dynamic-extent #',visit-name))
(scope-trie-%map
#',visit-name (scope-components scope) trie
,extend? ,leaf-only?)))))
,@body)))))
(define-scope-trie-function scope-trie-get ()
"Return two values: 1) nil or the value associated with SCOPE in
TRIE 2) a Boolean indicating whether a value is associated with
SCOPE in TRIE."
(visit (nil state nil t)
(return-from scope-trie-get
(let ((value (node-state-value state)))
(values value (not (eq value +no-value+)))))))
(define-scope-trie-function (setf scope-trie-get) (new-value)
"Set the value associated with SCOPE in TRIE to NEW-VALUE, return
NEW-VALUE."
(visit (nil state t t)
(make-node-state new-value (node-state-edges state)))
new-value)
(define-scope-trie-function scope-trie-rem ()
"Remove the value associated with SCOPE in TRIE, if any."
(visit (nil state nil t)
(let ((old-edges (node-state-edges state)))
(unless (scope-node-edges-empty? old-edges)
(make-node-state +no-value+ old-edges)))))
(define-scope-trie-function scope-trie-map (function)
"Call FUNCTION for values associated to super-scopes of SCOPE in
TRIE.
FUNCTION is called with two arguments: 1) a dynamic-extent list
of components of a super-scope of SCOPE 2) the value associated
to that scope."
(let ((function (ensure-function function)))
(visit (scope state nil nil)
(let ((value (node-state-value state)))
(unless (eq value +no-value+)
(funcall function scope value))
state))))
(define-scope-trie-function scope-trie-update (function)
"Call FUNCTION with the value associated to SCOPE in TRIE and
replace that value with the return value of FUNCTION.
Return two values: 1) nil or the new value associated with SCOPE
in TRIE 2) a Boolean indicating whether SCOPE is associated with
a value in TRIE.
FUNCTION is called with two arguments: 1) nil or the current
value associated to SCOPE 2) a Boolean indicating whether a value
is associated to SCOPE in TRIE. FUNCTION should return two
values: 1) nil or the new value to associate with SCOPE in TRIE
2) a Boolean indicating whether SCOPE should be associated with a
value in TRIE.
FUNCTION is called at least once but may be called multiple times
in which case the return values of all but the most recent call
are discarded."
(let (new new?)
(visit (nil state t t)
(let* ((old-value (node-state-value state))
(old-edges (node-state-edges state)))
(setf (values new new?)
(if (eq old-value +no-value+)
(funcall function nil nil)
(funcall function old-value t)))
(cond
(new?
(make-node-state new old-edges))
(old-edges
(make-node-state +no-value+ old-edges)))))
(values new new?))))
;;; `sink-scope-trie' data structure
(defstruct (sink-scope-trie
(:include node)
(:constructor make-sink-scope-trie ())
(:predicate nil)
(:copier nil)))
(declaim (ftype (function (sink-scope-trie scope t) (values list t &optional))
sink-scope-trie-add sink-scope-trie-remove))
(defun sink-scope-trie-add (trie scope sink)
(scope-trie-update (lambda (value value?)
(declare (ignore value?))
(values (list* sink value) t))
scope trie))
(defun sink-scope-trie-remove (trie scope sink)
(scope-trie-update (lambda (value value?)
(declare (ignore value?))
(let ((new-value (remove sink value :count 1)))
(values new-value new-value)))
scope trie))
;;; Utilities
(defun print-trie (stream trie &optional colon? at?)
(declare (ignore colon? at?))
(print-unreadable-object (trie stream :type t :identity t)))
| 13,635 | Common Lisp | .lisp | 278 | 34.902878 | 84 | 0.530266 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 2c5d7eff7a8cb0bfb724dee4c7f356dd68fbba29fb59f9941ceb3537914f5282 | 25,277 | [
-1
] |
25,278 | broadcast-processor.lisp | open-rsx_rsb-cl/src/event-processing/broadcast-processor.lisp | ;;;; broadcast-processor.lisp --- Broadcast events to multiple handlers.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.event-processing)
;;; `broadcast-processor'
(defclass broadcast-processor ()
((handlers :initarg :handlers
:type list
:accessor handlers
:initform '()
:documentation
"Stores a list of handlers to which events are dispatched
via `handle'."))
(:documentation
"Instances maintain a list of handlers and dispatch events to these
handlers.
Methods on `handle' can be use to filter or transform
events. Methods on `dispatch' can be used to modify dispatching
behavior."))
(defmethod handle ((processor broadcast-processor)
(data t))
;; Dispatch DATA to handlers of PROCESSOR in a manner defined by
;; methods on `dispatch'.
(dispatch processor data))
(defmethod dispatch ((processor broadcast-processor)
(data t))
;; Dispatch DATA to handlers of PROCESSOR.
(handle (handlers processor) data))
| 1,168 | Common Lisp | .lisp | 30 | 32.666667 | 72 | 0.662544 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | cc2ccd84ca73118de17e08c8087c61760ec59a11cd073bcdf2a8b1d566820ed9 | 25,278 | [
-1
] |
25,279 | package.lisp | open-rsx_rsb-cl/src/transform/package.lisp | ;;;; package.lisp --- Package definition for transform module.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.transform
(:use
#:cl
#:alexandria
#:let-plus
#:iterate
#:more-conditions
#:rsb)
;; Conditions
(:export
#:transform-creation-error
#:transform-creation-error-spec
#:transform-error
#:transform-error-transform
#:transform-error-object)
;; Variables
(:export
#:+dropped-payload+)
;; Transformation protocol
(:export
#:transform!)
;; Transform creation protocol
(:export
#:make-transform)
(:documentation
"This package contains event transformation infrastructure and transforms.
The generic function `make-transform' can be used to instantiate
transforms.
Given an instantiated transform the generic function `transform!'
can be used to destructively transform events."))
| 978 | Common Lisp | .lisp | 35 | 24.314286 | 77 | 0.717811 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | bcb41287227e61e9f44d0117da717f8e8161d638212f68854dd8e2f8f1aac42c | 25,279 | [
-1
] |
25,280 | protocol.lisp | open-rsx_rsb-cl/src/transform/protocol.lisp | ;;;; protocol.lisp --- Protocol provided by the transform module.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transform)
;;; Transformation protocol
(defgeneric transform! (transform event)
(:documentation
"Destructively transform and return EVENT according to TRANSFORM.
Signal an error of type `transform-error' in case something goes
wrong. When the error is signaled, two restarts are established:
`continue'
Return the untransformed EVENT.
`use-value' VALUE
Return VALUE instead of transforming EVENT.
When TRANSFORM is a function of one argument, call it with EVENT
as the sole argument.
When TRANSFORM is a sequence, all elements have to be transforms
and the composition of these transforms is applied to EVENT. E.g.
(transform! (list #'1+ (curry #'* 2)) 1) ≡ (1+ (* 2 1))
."))
;; Default behavior
(defmethod transform! :around ((transform t) (event t))
;; Translate `error' s to `transform-error' s and establish
;; `continue' and `use-value' restarts.
(with-condition-translation
(((error transform-error)
:transform transform
:object event))
(restart-case
(call-next-method)
(continue (&optional condition)
:report (lambda (stream)
(format stream "~@<Continue without transforming ~
~A with ~A.~@:>"
event transform))
(declare (ignore condition))
event)
(use-value (value)
:report (lambda (stream)
(format stream "~@<Use a value instead of ~
transforming ~A with ~A.~@:>"
event transform))
value))))
(defmethod transform! ((transform t) (event t))
;; Signal an error since there is no suitable method on
;; `transform!'.
(error "~@<No ~S method for ~A and ~A.~@:>"
'transform! transform event))
(defmethod transform! ((transform function) (event t))
(funcall transform event))
(defmethod transform! ((transform sequence) (event t))
(reduce #'transform! transform :initial-value event :from-end t))
;;; Transform creation protocol.
(defgeneric make-transform (spec &key &allow-other-keys)
(:documentation
"Make and return a transform according to SPEC."))
(define-condition-translating-method make-transform ((spec symbol)
&rest args &key)
((error transform-creation-error)
:spec (list* spec args)))
(defmethod make-transform ((spec symbol) &rest args &key)
(apply #'service-provider:make-provider 'transform spec args))
(service-provider:define-service transform
(:documentation
"Providers of this service destructively transform events.
Providers implement methods on the `transform!' generic function
which accept an event, destructively modify one or more aspects of
the event and return the modified event."))
| 3,053 | Common Lisp | .lisp | 70 | 36.457143 | 70 | 0.660135 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | bc69ffed05295317649d9b77d68e3032de5c00df22c9ce9d3de8803c1177bced | 25,280 | [
-1
] |
25,281 | drop-payload.lisp | open-rsx_rsb-cl/src/transform/drop-payload.lisp | ;;;; drop-payload.lisp --- A transform that removes payloads from events.
;;;;
;;;; Copyright (C) 2014, 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transform)
(defconstant +dropped-payload+ '%dropped-payload
"This object is used to represent a removed payload.")
(deftype dropped-payload ()
"Instances of this type represent removed payloads."
'(eql %payload-dropped))
(defclass drop-payload (funcallable-transform-mixin)
()
(:metaclass closer-mop:funcallable-standard-class)
(:documentation
"Removes payloads from events.
This transform is intended for use in situations in which large
numbers of events have to be retained with only the meta-data
being of interest."))
(service-provider:register-provider/class
'transform :drop-payload :class 'drop-payload)
(defmethod rsb.ep:access? ((transform drop-payload)
(part (eql :data))
(mode (eql :write)))
t)
(defmethod transform! ((transform drop-payload) (event event))
(setf (event-data event) +dropped-payload+)
event)
| 1,143 | Common Lisp | .lisp | 28 | 36.392857 | 73 | 0.70551 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 660eccb43c16e655e5ad05666e5c552a609574f0b7e0d9e90f7b1fbf5d75519c | 25,281 | [
-1
] |
25,282 | adjust-timestamps.lisp | open-rsx_rsb-cl/src/transform/adjust-timestamps.lisp | ;;;; adjust-timestamps.lisp --- Transform that modifies event timestamps.
;;;;
;;;; Copyright (C) 2014, 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transform)
;;; Timestamp adjustment specifications
(deftype timestamp-adjustment-value/self ()
"Indicates that the current time (i.e. \"now\", time of processing
the event) should replace the stored timestamp."
'(eql :self))
(deftype timestamp-adjustment-value/now ()
"Indicates that the current time (i.e. \"now\", time of processing
the event) should replace the stored timestamp."
'(eql :now))
(deftype timestamp-adjustment-value/copy ()
"A value of the form
(:COPY TIMESTAMP-DESIGNATOR)
indicates that the timestamp designated by TIMESTAMP-DESIGNATOR
should be extracted from the event and used to replace the stored
timestamp."
'(cons (eql :copy) (cons timestamp-designator null)))
(deftype timestamp-adjustment-value/adjust ()
"A value of the form
(+ TIMESTAMP-ADJUSTMENT-VALUE AMOUNT)
indicates that the timestamp should be adjusted by AMOUNT seconds."
'(cons (eql +) (cons t (cons real null))))
(deftype timestamp-adjustment-value ()
"Specification of a replacement value for a particular timestamp."
'(or local-time:timestamp
timestamp-designator
timestamp-adjustment-value/self
timestamp-adjustment-value/now
timestamp-adjustment-value/copy
timestamp-adjustment-value/adjust))
(deftype timestamp-adjustment-spec ()
"Replacement rule of the form
(TIMESTAMP-DESIGNATOR TIMESTAMP-ADJUSTMENT-VALUE)
specifying that the timestamp designated by TIMESTAMP-DESIGNATOR
should be replaced with the timestamp value specified by
TIMESTAMP-ADJUSTMENT-VALUE"
'(cons timestamp-designator (cons timestamp-adjustment-value null)))
;;; Utility functions
(defun adjust-timestamps! (adjustments event)
(labels ((adjust (key spec)
(etypecase spec
(local-time:timestamp
(local-time::clone-timestamp spec))
(timestamp-adjustment-value/self
(adjust key key))
(timestamp-adjustment-value/now
(local-time:now))
(timestamp-designator
(local-time::clone-timestamp
(or (timestamp event spec)
(error "~@<Event ~A does not have a ~A ~
timestamp.~:@>"
event spec))))
(timestamp-adjustment-value/copy
(adjust key (second spec)))
(timestamp-adjustment-value/adjust
(let+ (((base adjustment) (rest spec))
((&values sec nsec) (floor adjustment)))
(local-time:adjust-timestamp (adjust key base)
(:offset :sec sec)
(:offset :nsec (floor (* 1000000000 nsec)))))))))
(declare (dynamic-extent #'adjust))
(iter (for (key spec) in adjustments)
(setf (timestamp event key) (adjust key spec))))
event)
;;; `adjust-timestamps' transform
(defclass adjust-timestamps (funcallable-transform-mixin
print-items:print-items-mixin)
((adjustments :type list
:accessor transform-adjustments
:initform '()
:documentation
"Stores a list of adjustments of the form
(TIMESTAMP NEW-VALUE)
where TIMESTAMP is a keyword designating a timestamp
and NEW-VALUE is a specification of type
`timestamp-adjustment-value' for the new value."))
(:metaclass closer-mop:funcallable-standard-class)
(:documentation
"Adjusts event timestamps according to given rules.
Rules can refer to existing timestamps and the current time and
include simple computations."))
(service-provider:register-provider/class
'transform :adjust-timestamps :class 'adjust-timestamps)
(defmethod shared-initialize :after ((instance adjust-timestamps)
(slot-names t)
&key
(adjustments '() adjustments-supplied?))
(when adjustments-supplied?
(setf (transform-adjustments instance) adjustments)))
(defmethod (setf transform-adjustments) :before ((new-value t)
(object adjust-timestamps))
(unless (and (listp new-value)
(every (of-type 'timestamp-adjustment-spec) new-value))
(error 'type-error
:datum new-value
:expected-type '(or null (cons timestamp-adjustment-spec)))))
(defmethod rsb.ep:access? ((transform adjust-timestamps)
(part (eql :timestamp))
(mode t))
t)
(defmethod transform! ((transform adjust-timestamps) (event event))
(adjust-timestamps! (transform-adjustments transform) event))
(defmethod print-items:print-items append ((object adjust-timestamps))
`((:adjustments ,(transform-adjustments object) "~{~{~A ‚Üê ~A~}~^, ~}")))
| 5,177 | Common Lisp | .lisp | 110 | 37.154545 | 79 | 0.635353 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 22cdbaced259834bd203b424546d77cf8a8c7b2c2142fd02be18456bb8055088 | 25,282 | [
-1
] |
25,283 | prefix-scope.lisp | open-rsx_rsb-cl/src/transform/prefix-scope.lisp | ;;;; prefix-scope.lisp --- Transform that add a prefix to scopes of transformed events.
;;;;
;;;; Copyright (C) 2012, 2013, 2014, 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transform)
(defclass prefix-scope (funcallable-transform-mixin
print-items:print-items-mixin)
((prefix :type scope
:reader transform-prefix
:writer (setf transform-%prefix)
:documentation
"Stores the prefix that should be added to the scopes of
transformed events."))
(:metaclass closer-mop:funcallable-standard-class)
(:default-initargs
:prefix (missing-required-initarg 'prefix-scope :prefix))
(:documentation
"Adds a prefix to scopes of transformed events."))
(service-provider:register-provider/class
'transform :prefix-scope :class 'prefix-scope)
(defmethod shared-initialize :after ((instance prefix-scope)
(slot-names t)
&key
(prefix '() prefix-supplied?))
(when prefix-supplied?
(setf (transform-prefix instance) prefix)))
(defgeneric (setf transform-prefix) (new-value object)
(:method ((new-value t) (object prefix-scope))
(setf (transform-%prefix object) (make-scope new-value))
new-value))
(defmethod rsb.ep:access? ((transform prefix-scope)
(part (eql :scope))
(mode t))
t)
(defmethod transform! ((transform prefix-scope) (event event))
(let+ (((&structure-r/o transform- prefix) transform))
(setf (event-scope event) (merge-scopes (event-scope event) prefix)))
event)
(defmethod print-items:print-items append ((object prefix-scope))
`((:prefix ,(scope-string (transform-prefix object)) "~A")))
| 1,867 | Common Lisp | .lisp | 41 | 37.317073 | 87 | 0.634763 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 80f19ce480bd4376300fed48105e3ad472f11ce66220e4cd82e036af1858b4b8 | 25,283 | [
-1
] |
25,284 | mixins.lisp | open-rsx_rsb-cl/src/transform/mixins.lisp | ;;;; mixins.lisp --- Mixin classes for transforms.
;;;;
;;;; Copyright (C) 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.transform)
;;; `funcallable-transform-mixin'
(defclass funcallable-transform-mixin (standard-object
function)
()
(:metaclass closer-mop:funcallable-standard-class)
(:documentation
"This class is intended to be mixed into transform classes instance
of which should be funcallable."))
(defmethod initialize-instance :after ((instance funcallable-transform-mixin)
&key)
(closer-mop:set-funcallable-instance-function
instance (curry #'transform! instance)))
| 735 | Common Lisp | .lisp | 18 | 34.277778 | 77 | 0.677419 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | d826de775d3db255aa2534ad6e673ce68e532c3855d52ca33a9c9192b6b3544f | 25,284 | [
-1
] |
25,285 | package.lisp | open-rsx_rsb-cl/src/patterns/package.lisp | ;;;; package.lisp --- Package definition for the patterns module.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.patterns
(:use
#:cl
#:alexandria
#:let-plus
#:more-conditions
#:rsb)
;; Conditions
(:export
#:child-condition
#:child-condition-container
#:child-condition-key
#:no-such-child-error
#:child-exists-error
#:child-exists-error-child
#:protocol-condition
#:protocol-condition-protocol
#:protocol-condition-role
#:protocol-condition-message
#:simple-protocol-condition
#:protocol-warning
#:protocol-error)
;; Participant children protocol
(:export
#:participant-children)
;; Child participant lookup protocol
(:export
#:participant-child) ; also `setf'
;; Participant child creation protocol
(:export
#:make-child-scope
#:make-child-initargs
#:make-child-participant)
;; `composite-participant-mixin' mixin class
(:export
#:composite-participant-mixin)
;; `child-container-mixin' mixin class
(:export
#:child-container-mixin)
;; `configuration-inheritance-mixin' mixin class
(:export
#:configuration-inheritance-mixin)
;; `lazy-child-making-mixin' mixin class
(:export
#:lazy-child-making-mixin)
(:documentation
"This package contains infrastructure for implementing
communication patterns on top of the event-driven architecture at
the core of RSB.
Currently the following infrastructure is provided:
* Participant children protocol
* Child participant lookup protocol
* Child participant creation protocol
Sub-packages contain concrete communication patterns implemented
on top of the RSB core, potentially utilizing the infrastructure
provided by this package.
Currently the following patterns are implemented in sub-packages:
request-reply (package rsb.patterns.request-reply)
In this communication pattern, a client submits requests to a
server which processes the requests and sends associated replies
to the client."))
| 2,146 | Common Lisp | .lisp | 66 | 28.378788 | 70 | 0.734307 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | d376541864a4577167332df5ace436fdafb24ac83c5cc544dac9987292182394 | 25,285 | [
-1
] |
25,286 | protocol.lisp | open-rsx_rsb-cl/src/patterns/protocol.lisp | ;;;; protocol.lisp --- Protocol provided by the patterns module.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns)
;;; Participant children protocol
;;;
;;; Allows retrieving the list of child participants of a given
;;; composite participant.
(defgeneric participant-children (participant)
(:documentation
"Return the list of child participants of PARTICIPANT."))
;;; Child participant lookup protocol
;;;
;;; Allows reading and writing child participants of a given
;;; participant according to their respective kind and unique name.
(defgeneric participant-child (participant which kind
&key
if-does-not-exist
if-exists
detach?)
(:documentation
"Return the child participant of PARTICIPANT uniquely identified by
WHICH and KIND.
KIND is a participant kind. The returned participant has to be of
kind KIND.
WHICH (in combination with KIND) uniquely identifies the requested
child participant within PARTICIPANT.
IF-DOES-NOT-EXIST controls the behavior in case the requested
child participant does not exist in PARTICIPANT. The default
behavior is returning nil. The following values are accepted:
error | (function error)
Signal a `no-such-child-error'. A `use-value' restart for
returning a given value instead of the missing child participant
is established when the error is signaled.
<any other object>
Return that object.
IF-EXISTS and DETACH? are accepted but ignored for parity with
`(setf participant-child)'"))
(defgeneric (setf participant-child) (new-value participant which kind
&key
if-does-not-exist
if-exists
detach?)
(:documentation
"Install NEW-VALUE as the child participant of PARTICIPANT uniquely
identified by WHICH and KIND.
KIND is a participant kind.
WHICH (in combination with KIND) uniquely identifies the new child
participant within PARTICIPANT.
NEW-VALUE has to be a participant of kind KIND.
IF-DOES-NOT-EXIST is accepted but ignored for parity with
`participant-child'.
IF-EXISTS controls the behavior in case a child identified by
WHICH and KIND already exists in PARTICIPANT. The default behavior
is replacing the existing child. The following values are accepted:
error | (function error)
Signal a `child-exists-error'. A `continue' restart for
replacing the existing child participant is established when the
error is signaled.
:supersede
Replace the existing child participant with NEW-VALUE.
DETACH? controls whether an existing child participant is detached
when replaced."))
;; Default behavior
(defmethod participant-child :around ((participant t)
(which t)
(kind t)
&key
if-does-not-exist
if-exists
detach?)
(declare (ignore if-exists detach?))
(or (call-next-method)
(error-behavior-restart-case
(if-does-not-exist (no-such-child-error
:container participant
:key (list kind which)))
(use-value (value)
:report (lambda (stream)
(format stream "~@<Supply a value to use in place ~
of the missing child participant ~
designated by ~S ~S of participant ~
~A~@:>"
which kind participant))
value))))
(defmethod (setf participant-child) :around ((new-value t)
(participant t)
(which t)
(kind t)
&key
if-does-not-exist
(if-exists :supersede)
(detach? t))
(declare (ignore if-does-not-exist))
(when-let ((existing (and new-value
(participant-child participant which kind
:if-does-not-exist nil))))
(ecase
(error-behavior-restart-case
(if-exists (child-exists-error
:container participant
:key (list kind which)
:child existing))
(continue (&optional condition)
:report (lambda (stream)
(format stream "~@<Replace the existing child ~
participant ~A designated by ~S ~
~S of participant ~A by ~A.~@:>"
existing which kind participant new-value))
(declare (ignore condition))
:supersede))
(:supersede
(unless (eq existing new-value)
(setf (participant-child participant which kind :detach? detach?)
nil)))))
(call-next-method))
;;; Child participant creation protocol
;;;
;;; Allows creating child participants of a given participant
;;; according to their respective kind and unique name.
;;;
;;; The entry point of the protocol is the `make-child-participant'
;;; generic function which by default calls `make-child-scope' and
;;; `make-child-initargs' to assemble the necessary information to
;;; actually construct child participants.
(defgeneric make-child-scope (participant which kind)
(:documentation
"Return a suitable `scope' or `puri:uri' for the child participant
of PARTICIPANT identified by KIND and WHICH.
The default behavior consists in deriving a `scope-component' from
WHICH and forming a sub-scope by merging the scope component with
the scope of PARTICIPANT."))
(defgeneric make-child-initargs (participant which kind
&rest args &key &allow-other-keys)
(:documentation
"Return a suitable list of initargs for the child participant of
PARTICIPANT identified by KIND and WHICH.
ARGS are the explicitly supplied initargs (e.g. supplied in the
`make-child-participant' call that called this function).
The default behavior consists in returning ARGS."))
(defgeneric make-child-participant (participant which kind
&rest args &key &allow-other-keys)
(:documentation
"Create and return the child participant of PARTICIPANT identified
by WHICH and KIND.
The default behavior consists in first calling `make-child-scope'
and `make-child-initargs' and then calling `make-participant' with
the collected information."))
;; Default behavior
(defmethod make-child-scope ((participant t)
(which (eql nil))
(kind t))
(participant-scope participant))
(defmethod make-child-scope ((participant t)
(which symbol)
(kind t))
(make-child-scope participant (string-downcase which) kind))
(defmethod make-child-scope ((participant t)
(which string)
(kind t))
(let ((scope (make-scope (list (derive-scope-component which)))))
(make-child-scope participant scope kind)))
(defmethod make-child-scope ((participant t)
(which scope)
(kind t))
(merge-scopes which (participant-scope participant)))
(defmethod make-child-scope ((participant t)
(which puri:uri)
(kind t))
;; Extract the path component of WHICH into a `scope', apply
;; `make-child-scope' processing, stick the resulting `scope' back
;; into a copy of WHICH, thus preserving all other components.
(let* ((scope (make-scope (puri:uri-path which)))
(scope (make-child-scope participant scope kind))
(result (puri:copy-uri which)))
(setf (puri:uri-path result) (scope-string scope))
result))
(defmethod make-child-initargs ((participant t)
(which t)
(kind t)
&rest args &key)
args)
(defmethod make-child-initargs ((participant rsb::error-hook-mixin)
(which t)
(kind t)
&key)
;; Connect the error-hook of the created child participant to the
;; error-hook of PARTICIPANT (the parent).
(let ((error-hook (participant-error-hook participant)))
(list* :error-policy (lambda (condition)
(hooks:run-hook error-hook condition))
(when (next-method-p)
(call-next-method)))))
(defmethod make-child-participant
((participant t)
(which t)
(kind t)
&rest args &key
(scope (make-child-scope participant which kind)))
(let ((initargs (apply #'make-child-initargs participant which kind
(remove-from-plist args :scope))))
(apply #'make-participant kind scope :parent participant initargs)))
| 9,784 | Common Lisp | .lisp | 204 | 34.901961 | 74 | 0.576133 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 99833549420a5c12ea526b75b8574d7b04f6069baa97e6b9a8ad3001f6a22b98 | 25,286 | [
-1
] |
25,287 | mixins.lisp | open-rsx_rsb-cl/src/patterns/mixins.lisp | ;;;; mixins.lisp --- Mixin classes for communication pattern implementations.
;;;;
;;;; Copyright (C) 2014, 2015, 2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns)
;;; `composite-participant-mixin'
(defclass composite-participant-mixin ()
()
(:documentation
"This class is intended to be mixed into participant classes that
contain child participants.
It provides appropriate disposal and printing functionality but no
storage for the child participants."))
(defmethod print-items:print-items append ((object composite-participant-mixin))
`((:num-children ,(length (participant-children object)) " (~D)")))
(defmethod detach ((participant composite-participant-mixin))
(mapc (lambda (child)
(with-restart-and-timeout (10)
(detach child)))
(participant-children participant))
(when (next-method-p)
(call-next-method)))
(defmethod transport-specific-urls ((component composite-participant-mixin))
(let ((uris (mapcar (curry #'puri:merge-uris (relative-url component))
(mappend #'transport-specific-urls
(participant-children component)))))
(remove-duplicates uris :test #'puri:uri=)))
;;; `child-container-mixin'
(defclass child-container-mixin ()
((children :type hash-table
:reader participant-%children
:initform (make-hash-table :test #'equal)
:documentation
"Stores a `hash-table' mapping \"child keys\" of the
form
(KIND . WHICH)
to child `participant' instances. KIND is a participant
kind and WHICH (with KIND) uniquely identifies the child
within the containing composite participant."))
(:documentation
"This class is intended to be mixed into participant classes that
store child participants which can be uniquely identified by a
kind and a name."))
(defmethod participant-children ((participant child-container-mixin))
(hash-table-values (participant-%children participant)))
(defmethod participant-child ((participant child-container-mixin)
(which t)
(kind t)
&key
if-does-not-exist
if-exists
detach?)
(declare (ignore if-does-not-exist if-exists detach?))
(let ((key (cons kind which)))
(values (gethash key (participant-%children participant)))))
(defmethod (setf participant-child) ((new-value t)
(participant child-container-mixin)
(which t)
(kind t)
&key
if-does-not-exist
if-exists
detach?)
(declare (ignore if-does-not-exist if-exists detach?))
(let ((key (cons kind which)))
(setf (gethash key (participant-%children participant)) new-value)))
(defmethod (setf participant-child) ((new-value (eql nil))
(participant child-container-mixin)
(which t)
(kind t)
&key
if-does-not-exist
if-exists
(detach? t))
(declare (ignore if-does-not-exist if-exists))
(let+ (((&structure-r/o participant- %children) participant)
(key (cons kind which))
(existing (gethash key %children)))
(when (and existing detach?)
(with-restart-and-timeout (10)
(detach existing)))
(remhash key %children))
new-value)
;;; `configuration-inheritance-mixin'
(defclass configuration-inheritance-mixin ()
((transport-options :initarg :transport-options
:type list
:reader participant-transport-options
:documentation
"Stores the transport options that should be
passed to child participants when they are
created.
The stored options have already been merged
with defaults and thus make created child
participants ignore any special binding of
`*configuration*'.")
(converter-options :initarg :converter-options
:reader participant-converter-options
:documentation
"Stores the converter options that should be
passed to child participants when they are
created.
TODO this is a temporary workaround until
participant-configuration is ready.")
(transform-option :initarg :transform-option
:reader participant-transform-option
:initform nil
:documentation
"Stores the transform which should be applied to
processed events.
TODO this is a temporary workaround until
participant-configuration is ready.")
(introspection?-option :initarg :introspection?-option
:type boolean
:reader participant-introspection?-option
:initform t
:documentation
"Stores a Boolean indicating whether
introspection has enabled for the
participant.
TODO this is a temporary workaround until
participant-configuration is ready."))
(:documentation
"This class is intended to be mixed into participant classes that
relay configuration options to their child participant."))
(defmethod shared-initialize :before
((instance configuration-inheritance-mixin)
(slot-names t)
&key
(transform nil transform-supplied?))
;; We store transform-options for passing them to methods but do not
;; accept transform for ourselves.
(when transform-supplied?
(incompatible-initargs 'configuration-inheritance-mixin
:transform transform)))
(defmethod make-participant-using-class
((class class)
(prototype configuration-inheritance-mixin)
(scope scope)
&rest args &key
(transports '())
(converters (default-converters))
transform
(introspection? (when (member (option-value '(:introspection :enabled)) '(t "1")
:test #'equal)
t)))
;; "Freeze" transport options by merging with defaults, thereby
;; disabling further inheritance from special bindings of
;; `*configuration*' during child participant creation (may even
;; happen in a different thread with different special bindings).
;;
;; Also check that TRANSPORTS will select at least one transport.
(let ((transport-options (rsb::merge-transport-options
transports (transport-options))))
(unless (rsb::effective-transport-options transport-options)
(error 'no-transports-error
:kind (participant-kind prototype)
:scope scope))
(apply #'call-next-method class prototype scope
:transport-options transport-options
:converter-options converters
:transform-option transform
:introspection?-option introspection?
(remove-from-plist args :converters :transports :transform))))
(defmethod make-child-initargs ((participant configuration-inheritance-mixin)
(which t)
(kind t)
&key
(transports nil transports-supplied?)
(converters nil converters-supplied?)
(transform nil transform-supplied?)
(introspection? nil introspection?-supplied?))
(declare (ignore transports converters transform introspection?))
(let+ (((&structure-r/o
participant-
transport-options converter-options transform-option
introspection?-option)
participant))
(append (unless transports-supplied?
(list :transports transport-options))
(unless converters-supplied?
(list :converters converter-options))
(unless transform-supplied?
(list :transform transform-option))
(unless introspection?-supplied?
(list :introspection? introspection?-option))
(when (next-method-p)
(call-next-method)))))
(defmethod make-child-participant :around ((participant configuration-inheritance-mixin)
(which t)
(kind t)
&key)
(let* ((old-configuration *configuration*)
(old-make-participant-hook *make-participant-hook*)
(*make-participant-hook*
(list (lambda (&rest args)
(let ((*configuration* old-configuration)
(*make-participant-hook* old-make-participant-hook))
(apply #'hooks:run-hook '*make-participant-hook* args)))))
(*configuration* '()))
(call-next-method)))
;;; `lazy-child-making-mixin'
(defclass lazy-child-making-mixin ()
()
(:documentation
"This mixin class adds the ability to create child participants
when they are first requested."))
(defmethod participant-child ((participant lazy-child-making-mixin)
(which t)
(kind t)
&key
(if-does-not-exist :create)
if-exists
detach?)
(declare (ignore if-exists detach?))
(case if-does-not-exist
(:create
(or (call-next-method participant which kind :if-does-not-exist nil)
;; If necessary, create the requested child. Make sure to
;; detach it if it cannot be installed.
(let ((child (make-child-participant participant which kind)))
(unwind-protect-case ()
(setf (participant-child participant which kind) child)
(:abort
(detach/ignore-errors child))))))
(t
(call-next-method))))
| 11,090 | Common Lisp | .lisp | 228 | 33.811404 | 88 | 0.553402 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 0e84be6e1853e2ca254adcfc288bb68f6bc6114fb415e116f8b2dd6621f94a07 | 25,287 | [
-1
] |
25,288 | package.lisp | open-rsx_rsb-cl/src/patterns/reader/package.lisp | ;;;; package.lisp --- Package definition for the patterns.reader module.
;;;;
;;;; Copyright (C) 2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.patterns.reader
(:use
#:cl
#:rsb
#:rsb.patterns)
;; Reader protocol and `reader' class
(:export
#:receive
#:reader)
(:documentation
"This package provides the `reader' participant for pull-based
event receiving."))
| 453 | Common Lisp | .lisp | 17 | 23.588235 | 72 | 0.691415 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 37dbdef6fe9f801224a8ec62c62f243d0ce0b509edfe20680fc4004948afb967 | 25,288 | [
-1
] |
25,289 | protocol.lisp | open-rsx_rsb-cl/src/patterns/reader/protocol.lisp | ;;;; protocol.lisp --- Protocol functions provided by the patterns.reader package..
;;;;
;;;; Copyright (C) 2011-2018 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.reader)
;;; Reader protocol
(defgeneric receive (reader
&key
block?)
(:documentation
"Receive data from the channel in which READER is participating.
When data is received, it is returned in form of an `event'
instance.
If BLOCK? is non-nil, wait for data to become available if there
is none. If BLOCK? is nil and no data is available, nil is
returned."))
| 657 | Common Lisp | .lisp | 17 | 33.411765 | 83 | 0.67874 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | b0747b2b4acfc6128ccabbd5b38a2fb3ca9562cdf16ed8ca4c88cfad300998ba | 25,289 | [
-1
] |
25,290 | reader.lisp | open-rsx_rsb-cl/src/patterns/reader/reader.lisp | ;;;; reader.lisp --- Pull-based receiving participant class.
;;;;
;;;; Copyright (C) 2011-2019 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.reader)
(defclass reader (participant
composite-participant-mixin
child-container-mixin
configuration-inheritance-mixin)
((direction :allocation :class
:initform :in-pull)
(queue :type lparallel.queue:queue
:reader queue
:initform (lparallel.queue:make-queue)
:documentation
"Stores events as they arrive via the message bus."))
(:documentation
"Called by client to receive events on a channel (pull style).
The client makes blocking or non-blocking calls to `receive' to
receive the next event."))
(rsb::register-participant-class 'reader)
(defmethod initialize-instance :after ((instance reader)
&key
(filters nil filters-supplied?))
(setf (participant-child instance nil :listener)
(apply #'make-child-participant
instance nil :listener
(when filters-supplied?
(list :filters filters)))))
(defmethod make-child-initargs ((participant reader)
(which (eql nil))
(kind (eql :listener))
&key)
(let ((queue (queue participant)))
(list* :handlers (list (lambda (event)
(lparallel.queue:push-queue event queue)))
(call-next-method))))
(defmethod rsb:receiver-filters ((receiver reader))
(rsb:receiver-filters (participant-child receiver nil :listener)))
(defmethod (setf rsb:receiver-filters) ((new-value list) (receiver reader))
(setf (rsb:receiver-filters (participant-child receiver nil :listener))
new-value))
(defmethod receive ((reader reader) &key (block? t))
(let ((queue (queue reader)))
(if block?
(lparallel.queue:pop-queue queue)
(lparallel.queue:try-pop-queue queue))))
| 2,169 | Common Lisp | .lisp | 48 | 34.5625 | 75 | 0.601326 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | bf798be3f2e5efe24276c13bb3f4510dd15a498aaaaa9c67d1f1aaa44ea61f81 | 25,290 | [
-1
] |
25,291 | package.lisp | open-rsx_rsb-cl/src/patterns/request-reply/package.lisp | ;;;; package.lisp --- Package definition for the patterns.request-reply module.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.patterns.request-reply
(:use
#:cl
#:alexandria
#:let-plus
#:iterate
#:more-conditions
#:rsb
#:rsb.patterns)
;; Types
(:export
#:method-name
#:argument-style)
;; Conditions
(:export
#:no-such-method
#:no-such-method-name
#:remote-call-error
#:remote-call-error-method
#:remote-call-error-request
#:remote-method-execution-error)
;; Future protocol
(:export
#:future-done?
#:future-result
#:future-error)
;; `future' class
(:export
#:future)
;; Method protocol
(:export
#:method-name)
;; Remote method protocol
(:export
#:call)
;; Server Protocol
(:export
#:server
#:server-methods
#:server-method) ; also setf
;; `local-server' class
(:export
#:local-server)
;; `remove-server' class
(:export
#:remote-server)
;; Convenience and utility macros
(:export
#:with-methods)
(:documentation
"This package contains the request-reply communication pattern.
In this communication pattern, a client submits requests to a
servers which processes the requests and sends associated replies
to the client."))
| 1,401 | Common Lisp | .lisp | 59 | 20.084746 | 79 | 0.674717 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 106418c78e014bd3d3800c262d432e14bdae242142d68fcba28a2ac4b869ede9 | 25,291 | [
-1
] |
25,292 | server.lisp | open-rsx_rsb-cl/src/patterns/request-reply/server.lisp | ;;;; server.lisp --- A superclass for local and remote server classes.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply)
;;; `method1' class
(defclass method1 (participant
composite-participant-mixin
lazy-child-making-mixin
child-container-mixin
configuration-inheritance-mixin)
((name :initarg :name
:type (or null method-name)
:reader method-name
:documentation
"Stores the name of the method."))
(:default-initargs
:name (missing-required-initarg 'method1 :name)
:server (missing-required-initarg 'method1 :server))
(:documentation
"This class serves as a superclass for local and remote method
classes."))
(defmethod shared-initialize :before
((instance method1)
(slot-names t)
&key
(name nil name-supplied?)
server
(transform-option nil transform-option-supplied?))
(declare (ignore server))
(when (and name-supplied? name)
(check-type name method-name "a legal method name"))
(when transform-option-supplied?
(check-type transform-option transform-specification)))
(defmethod print-items:print-items append ((object method1))
`((:num-children nil "")
(:name ,(method-name object) " ~S")))
;;; `server' class
(defclass server (participant
composite-participant-mixin
child-container-mixin
configuration-inheritance-mixin)
((method-kind :type keyword
:allocation :class
:reader server-method-kind
:initform :method)) ; useful for tests
(:documentation
"This class serves as a superclass for local and remote server
classes. It provides storage of transport options and methods and
generic support for retrieving, adding and removing methods."))
(defmethod shared-initialize :before
((instance server)
(slot-names t)
&key
(transform-option nil transform-option-supplied?))
(when transform-option-supplied?
(check-type transform-option transform-specification)))
(macrolet
((define-child-method (which)
`(defmethod ,(ecase which
(:get 'participant-child)
(:set '(setf participant-child))
(:make 'make-child-participant))
:before (,@(case which
(:set '((new-value method1))))
(participant server)
(which string)
(kind t)
&key &allow-other-keys)
(check-type which method-name "a legal method name"))))
(define-child-method :get)
(define-child-method :set)
(define-child-method :make))
(defmethod make-child-initargs ((participant server)
(which t)
(kind t)
&key)
(list* :name which
:server participant
(call-next-method)))
(defmethod server-methods ((server server))
(participant-children server))
(flet ((get-method (server name error?)
(participant-child
server name (server-method-kind server)
:if-does-not-exist
(when error?
(lambda (condition)
(error 'no-such-method
:container (child-condition-container condition)
:key (child-condition-key condition)))))))
(macrolet
((define-server-method-method (name-specializer)
`(defmethod server-method ((server server)
(name ,name-specializer)
&key
(error? t))
(get-method server name error?))))
(define-server-method-method string)
(define-server-method-method (eql nil))))
(macrolet
((define-setf-server-method-method (name-specializer new-value-specializer)
`(defmethod (setf server-method) ((new-value ,new-value-specializer)
(server server)
(name ,name-specializer)
&key
argument)
(declare (ignore argument))
(setf (participant-child server name (server-method-kind server))
new-value))))
(define-setf-server-method-method string method1)
(define-setf-server-method-method (eql nil) method1)
(define-setf-server-method-method string (eql nil))
(define-setf-server-method-method (eql nil) (eql nil)))
| 4,819 | Common Lisp | .lisp | 115 | 30.965217 | 79 | 0.576152 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 5087a56a24d29ca343edaa9dc167ae640f91ea6b2385448725bd037354303145 | 25,292 | [
-1
] |
25,293 | protocol.lisp | open-rsx_rsb-cl/src/patterns/request-reply/protocol.lisp | ;;;; protocol.lisp --- Protocols used in the pattern.request-reply module.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply)
;;; Future protocol
(defgeneric future-done? (future)
(:documentation
"Return one of :DONE and :FAILED if the operation the result of
which is represented by FUTURE did finish and nil otherwise."))
(defgeneric future-result (future
&key
timeout
error?)
(:documentation
"Obtain and return the result represented by FUTURE. If the
operation producing the result is not done, block until it
finishes or the specified waiting time is exceeded. Return two
values: the result of the operation and one of :DONE, :FAILED
and :TIMEOUT indicating how the associated operation finished. The
values :FAILED and :TIMEOUT can only be returned if ERROR? is
nil (see below).
TIMEOUT specifies the maximum amount of time in seconds to wait
for the operation to finish. If timeout is nil, wait indefinitely.
If ERROR? is non-nil (the default), signal an error or a condition
of type `bordeaux-threads:timeout' if the operation producing the
result fails or a timeout occurs respectively."))
(defgeneric (setf future-result) (new-value future)
(:documentation
"Set NEW-VALUE as the result of the operation associated to
FUTURE. The NEW-VALUE can be retrieved from FUTURE using
`future-result' afterward. Threads waiting for the result in
`future-result' will be woken up."))
(defgeneric (setf future-error) (new-value future)
(:documentation
"Indicate that the operation associated to FUTURE failed and set
NEW-VALUE as the error condition. Afterward, calling
`future-result' may signal the error NEW-VALUE. NEW-VALUE can be a
condition object, a string or a list of the
form (CONDITION-CLASS-NAME KW1 VALUE1 ...). All three forms have
to be usable as arguments to `error'."))
;;; Method protocol
(defgeneric method-name (method)
(:documentation
"Return the name of METHOD."))
;;; Local and remote method invocation protocol
(defgeneric call (server method request
&key
block?
timeout
return)
(:argument-precedence-order request method server)
(:documentation
"Call METHOD of SERVER with argument REQUEST and return the result
of the method call. If a remote call fails for some reason, an
error of type `remote-call-error' is signaled.
If BLOCK? is non-nil, the call blocks until a result is available
or an error occurs. Otherwise, an object implementing the future
protocol is returned.
If BLOCK? is non-nil, the value of TIMEOUT, when non-nil, controls
the amount of time to wait for a reply before the blocking call
signals a timeout error. If TIMEOUT is not supplied or nil,
blocking calls wait indefinitely.
RETURN controls which kind of result is (ultimately,
i.e. potentially after forcing the returned future) returned by
the method call. Valid values are :event, which causes the whole
reply event to be returned, and :payload, which causes the payload
of the reply event to be returned."))
;;; Server protocol
(defgeneric server-methods (server)
(:documentation
"Return a list of methods provided by SERVER."))
(defgeneric server-method (server name &key error?)
(:documentation
"Return the method named NAME of SERVER.
Signal a `type-error' if NAME is not a valid method name for
SERVER.
If no such method exists and ERROR? is non-nil signal a
`no-such-method' error. Otherwise return nil."))
(defgeneric (setf server-method) (new-value server name
&key argument)
(:argument-precedence-order server name new-value)
(:documentation
"Store NEW-VALUE as the method named NAME of SERVER. NEW-VALUE can
be a method instance a thing like a function based on which a
method can be made.
If NEW-VALUE is nil, the method stored for NAME is removed from
SERVER.
When supplied, ARGUMENT has to be either :event or :payload
causing the associated callback function of NEW-VALUE to receive
the request event or just its payload respectively.
Signal a `type-error' if NAME is not a valid method name for
SERVER."))
| 4,477 | Common Lisp | .lisp | 94 | 41.861702 | 74 | 0.718513 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 9a3f23dcd3b79b7e386677c30234ca7589622233e66bc46a27284b9deb8471f2 | 25,293 | [
-1
] |
25,294 | future.lisp | open-rsx_rsb-cl/src/patterns/request-reply/future.lisp | ;;;; future.lisp --- A simple implementation of the future pattern.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply)
;;; Representation of failures
(defstruct (future-failure
(:constructor make-future-failure (tag condition))
(:copier nil))
(tag nil :type keyword :read-only t)
(condition nil :type list :read-only t))
;;; `future' class
(defclass future ()
((result :initarg :result
:writer (setf future-%result)
:documentation
"Stores the result of the operation associated to the
future. Remains unbound until the operation completes
successfully or fails.")
(lock :reader future-%lock
:initform (bt:make-lock "Future lock")
:documentation
"Stores the lock that protects access to the result
slot.")
(condition :reader future-%condition
:initform (bt:make-condition-variable
:name "Future condition")
:documentation
"Stores the condition variable which can be used to wait
for the result slot to be set."))
(:documentation
"Instances of this class represent results of operations that are
still in progress when the respective instances are
made. Instances can therefore be considered placeholders for the
actual results which may or may not (when the producing operation
fails) become available later.
Interaction with `future' instances is done using methods on the
following protocol functions:
+ `future-done?' :: Check whether the associated operation
finished or failed.
+ `future-result' :: Obtained the result, potentially waiting for
it to become available.
+ `(setf future-result)' :: Supply a result for the `future'
instance.
+ `(setf future-error)' :: Indicate that the operation associated
to the `future' instance failed.
It is possible to supply values for the result, lock and condition
slots of new `future' instance using initargs. The former may be
useful when a result is immediately available but the future
protocol has to be obeyed. The latter two may be useful when the
lock and condition objects have to be available to some code
outside the future or for performance reasons."))
(defmethod future-done? ((future future))
(bt:with-lock-held ((future-%lock future))
(when (slot-boundp future 'result)
(let ((value (slot-value future 'result)))
;; When there is some result, check whether it indicates an
;; error.
(if (future-failure-p value)
(future-failure-tag value)
:done)))))
(defmethod future-result ((future future)
&key
timeout
(error? t)
&allow-other-keys)
(check-type timeout (or null timeout))
(let+ (((&structure-r/o future- (lock %lock) (condition %condition))
future)
((&flet timeout ()
(if error?
#+sbcl (error 'sb-ext:timeout :seconds timeout)
; #-sbcl #-sbcl #.(error "not implemented")
(return-from future-result (values nil :timeout)))))
(value (progn
(bt:with-lock-held (lock)
(iter (until (slot-boundp future 'result))
(unless (bt:condition-wait
condition lock :timeout timeout)
(timeout))))
(slot-value future 'result))))
#+later (declare (dynamic-extent #'timeout))
;; Return the result stored in VALUE or signal an error, depending
;; on ERROR?
(cond
((not (future-failure-p value))
(values value :done))
;; When the stored value indicates an error, signal the error or
;; return the tag, depending on ERROR?.
(error?
(apply #'error (future-failure-condition value)))
(t
(values nil (future-failure-tag value))))))
(defmethod (setf future-result) ((new-value t) (future future))
(bt:with-lock-held ((future-%lock future))
(prog1
(setf (future-%result future) new-value)
(bt:condition-notify (future-%condition future)))))
(defmethod (setf future-error) ((new-value t) (future future))
;; Store a result value that indicates an error. NEW-VALUE can be
;; used to (construct and) signal the error.
(setf (future-result future)
(make-future-failure :failed (ensure-list new-value))))
(defmethod print-object ((object future) stream)
(print-unreadable-object (object stream :type t :identity t)
(format stream "~A" (or (future-done? object) :running))))
| 4,908 | Common Lisp | .lisp | 107 | 36.766355 | 70 | 0.625889 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 2e13c2170c623edfa6a47c37e09bb01486cd258fff25ae510cf2939d916bbf6f | 25,294 | [
-1
] |
25,295 | types.lisp | open-rsx_rsb-cl/src/patterns/request-reply/types.lisp | ;;;; types.lisp --- Type definitions used the patterns.request-reply module.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply)
(deftype method-name ()
"Instances of this type are strings which are legal as method
names."
'scope-component)
(deftype argument-style ()
`(member :payload :event))
(deftype return-style ()
"Instances of this type describe styles in which a result can be
returned from a method call."
'(member :payload :event))
(deftype transform-specification ()
"Instances of this type describe the transforms that should be
applied to the argument and return value of a method."
`(or null
(cons (cons (eql :argument) t) null)
(cons (cons (eql :argument) t)
(cons (cons (eql :return) t) null))
(cons (cons (eql :return) t) null)
(cons (cons (eql :return) t)
(cons (cons (eql :argument) t) null))))
| 1,013 | Common Lisp | .lisp | 26 | 35.153846 | 76 | 0.681263 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | f725d4c60ac349721306640a1d98070631a5ecf3ea79eab3758a6ba6ec3a844d | 25,295 | [
-1
] |
25,296 | remote-server.lisp | open-rsx_rsb-cl/src/patterns/request-reply/remote-server.lisp | ;;;; remote-server.lisp --- The remote-server class is used to access a service.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply)
;;; `remote-method' class
(defclass remote-method (method1
closer-mop:funcallable-standard-object)
((lock :reader method-%lock
:initform (bt:make-lock "Remote Method Lock")
:documentation
"Stores a lock which protects the table of in-progress calls
from concurrent modification.")
(calls :type hash-table
:reader method-%calls
:initform (make-hash-table :test #'equal)
:documentation
"Stores a mapping of request ids (as strings) to the
associated call information which is represented as a cons
cell
(CONDITION . RESULT).
RESULT is initially nil and gets set when a call
completes. CONDITION is a condition variable that is used
to wait for RESULT."))
(:metaclass closer-mop:funcallable-standard-class)
(:documentation
"Makes a method of a remote server callable by client code."))
(rsb::register-participant-class 'remote-method)
(defmethod initialize-instance :after ((instance remote-method)
&key
server)
(closer-mop:set-funcallable-instance-function
instance (lambda (&optional (data-or-event rsb.converter:+no-value+)
&rest args)
(apply #'call server instance data-or-event args))))
(defmethod make-child-initargs ((participant remote-method)
(which (eql nil))
(kind t)
&key)
(let* ((initargs (call-next-method))
(transform (getf initargs :transform)))
(list* :transform (cdr (assoc (ecase kind
(:listener :return)
(:informer :argument))
transform))
(remove-from-plist initargs :transform))))
(defmethod make-child-initargs ((participant remote-method)
(which (eql nil))
(kind (eql :listener))
&key)
(let+ ((initargs (call-next-method))
((&plist-r/o (filters :filters) (handlers :handlers)) initargs)
((&structure-r/o method- (lock %lock) (calls %calls)) participant)
((&flet handle-reply (event)
(let+ (((&flet update-call (call)
(%call-result->future
participant (cadr call) event (cddr call) (car call)))))
(cond
((when-let ((local-call *local-call*))
(cond
((not (consp local-call))
nil)
;; Can happen when more than one local-method
;; processes a blocking local call.
((eq (car local-call) t)
t)
(t
(update-call local-call)
(setf (car local-call) t)))))
(t
;; Extract the call id, look up the call, store the
;; result and notify the caller.
(when-let* ((event-id (first (event-causes event)))
(key (%event-id->key event-id))
;; Find and maybe remove the call. Then
;; store the received reply in the result
;; future.
(call (bt:with-lock-held (lock)
(when-let ((call (gethash key calls)))
(remhash key calls)
call))))
(update-call call))))))))
;; Filter: ignore events which do have a suitable method to be
;; considered replies.
;;
;; Handler: `handle-reply' processes replies to method calls.
(list* :filters (list* *reply-filter* filters)
:handlers (list* #'handle-reply handlers)
(remove-from-plist initargs :filters :handlers))))
(defmethod call ((server t)
(method remote-method)
(request event)
&key
(return :payload)
(block? t)
&allow-other-keys)
;; Call the remote method of METHOD transmitting REQUEST as request
;; data.
(check-type return return-style "either :payload or :event")
(participant-child method nil :listener) ; force creation
(let+ ((informer (participant-child method nil :informer))
((&structure-r/o method- (lock %lock) (calls %calls)) method)
(future (make-instance 'future))
(call (cons future (cons request return)))
(*local-call* (if block? call t)))
(handler-case
;; Send the request to the remote server(s) and register the
;; method call. We hold the lock the entire time to prevent
;; the reply from arriving before we registered the call.
(bt:with-lock-held (lock)
(setf (event-method request) :|request|
request (send informer request))
(unless (and block? (eq (car call) t))
(let ((key (%event-id->key (event-id/opaque request))))
(setf (gethash key calls) call)))
future)
(error (condition)
(error 'remote-call-error
:method method
:request request
:cause condition)))))
(defmethod call :around ((server t)
(method remote-method)
(request event)
&key
(block? t)
timeout
&allow-other-keys)
;; Establish restarts and take care retrieving future results if
;; BLOCK? is non-nil.
(check-type timeout (or null timeout))
(iter (restart-case
(return-from call
(if block?
(let ((result (future-result (call-next-method)
:timeout timeout)))
(if (eq result rsb.converter:+no-value+)
(values)
result))
(call-next-method)))
(retry ()
:report (lambda (stream)
(format stream "~@<Retry calling method ~A of ~
server ~A with request ~A.~@:>"
method server request))))))
;;; `remote-server' class
(defclass remote-server (server)
((method-kind :allocation :class
:initform :remote-method))
(:documentation
"Allows client code to call methods provided by remote servers.
The methods are presented as functions and can be called as if
they were local."))
(rsb::register-participant-class 'remote-server)
(flet ((ensure-method (server name error? next-method)
(or (funcall next-method server name :error? error?)
(setf (participant-child server name :remote-method)
(make-child-participant server name :remote-method)))))
(macrolet ((define-server-method-method (name-specializer)
`(defmethod server-method ((server remote-server)
(name ,name-specializer)
&key
error?)
(ensure-method server name error? #'call-next-method))))
(define-server-method-method string)
(define-server-method-method (eql nil))))
(defmethod call ((server remote-server)
(method t)
(request t)
&rest args
&key &allow-other-keys)
;; Create the method named METHOD if it does not already
;; exist, then call it.
(apply #'call server (server-method server method) request args))
(defmethod call ((server t)
(method remote-method)
(request t)
&rest args
&key &allow-other-keys)
(let* ((informer (participant-child method nil :informer))
(event (make-instance 'event
:scope (participant-scope informer)
:data request)))
(apply #'call server method event args)))
;;; Utility functions
(declaim (ftype (function (event-id) (cons sequence-number string)) %event-id->key))
(defun %event-id->key (event-id)
;; Return an `equal'-comparable object representing EVENT-ID.
(cons (cdr event-id) (princ-to-string (car event-id))))
(defun %call-result->future (method request event return future)
;; Store data from METHOD, REQUEST and EVENT in FUTURE taking into
;; account whether EVENT represents an error. Return the modified
;; FUTURE.
(if (meta-data event :|rsb:error?|)
(setf (future-error future)
(list 'remote-method-execution-error
:method method
:request request
:cause (make-condition
'simple-error
:format-control "~@<~A~@:>"
:format-arguments (list (event-data event)))))
(setf (future-result future) (ecase return
(:payload (event-data event))
(:event event))))
future)
| 9,777 | Common Lisp | .lisp | 207 | 32.42029 | 84 | 0.522263 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 89b0dd695109c49787f579dbbc26449c19478cfd22254f75e1fd52d0e47040e3 | 25,296 | [
-1
] |
25,297 | local-server.lisp | open-rsx_rsb-cl/src/patterns/request-reply/local-server.lisp | ;;;; local-server.lisp --- The local-server class is used to provide a service.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply)
;;; `local-method' class
(defclass local-method (method1)
((server :initarg :server
:type local-server
:reader method-%server
:documentation
"Stores the `local-server' instance to which the method
belongs.")
(callback :initarg :callback
:type function
:reader method-callback
:documentation
"Stores the function that is called to perform the actual
processing of the method.")
(argument :initarg :argument
:type argument-style
:reader method-argument
:initform :payload
:documentation
"Stores the kind of argument (event vs. payload) that
should be passed to the callback function."))
(:default-initargs
:callback (missing-required-initarg 'local-method :callback))
(:documentation
"Method within a local server. Runs client code when called.
The actual behavior of methods is implemented by invoking
arbitrary user-supplied functions."))
(rsb::register-participant-class 'local-method)
(defmethod initialize-instance :after ((instance local-method) &key)
(participant-child instance nil :listener)) ; force creation
(defmethod make-child-initargs ((participant local-method)
(which (eql nil))
(kind t)
&key)
(let* ((initargs (call-next-method))
(transform (getf initargs :transform)))
(list* :transform (cdr (assoc (ecase kind
(:listener :argument)
(:informer :return))
transform))
(remove-from-plist initargs :transform))))
(defmethod make-child-initargs ((participant local-method)
(which (eql nil))
(kind (eql :listener))
&key)
(let+ ((initargs (call-next-method))
((&plist-r/o (filters :filters) (handlers :handlers)) initargs))
;; Filter: ignore events which do have a suitable method to be
;; considered requests.
;;
;; Handler: call the callback and sends the reply using the
;; informer.
(list* :filters (list* *request-filter* filters)
:handlers (list* (curry #'call (method-%server participant) participant)
handlers)
(remove-from-plist initargs :filters :handlers))))
(defmethod call :around ((server t)
(method local-method)
(request event)
&key &allow-other-keys)
(if (eq *local-call* t)
(bt:make-thread (lambda ()
(let ((*local-call* nil))
(call-next-method))))
(call-next-method)))
(defmethod call ((server t)
(method local-method)
(request event)
&key &allow-other-keys)
;; Invoke the call back function of METHOD with the payload of
;; REQUEST. Send the result or an error notification back to the
;; caller.
(let+ ((informer (participant-child method nil :informer))
((&structure-r/o method- callback argument) method)
(causes (list (event-id/opaque request)))
((&flet make-reply (payload)
(make-event (event-scope request) payload))))
(handler-case
(let* ((maybe-result (multiple-value-list
(cond
((eq argument :event)
(funcall callback request))
((eq (event-data request) rsb.converter:+no-value+)
(funcall callback))
(t
(funcall callback (event-data request))))))
(result (cond
((not maybe-result)
rsb.converter:+no-value+)
((typep maybe-result '(cons event null))
(first maybe-result))
(t
(make-reply (first maybe-result))))))
(send informer result :method :|reply| :causes causes))
(error (condition)
(send informer (make-reply (princ-to-string condition))
:method :|reply|
:causes causes
:|rsb:error?| "1")))))
;;; `local-server' class
(defclass local-server (server)
((method-kind :allocation :class
:initform :local-method))
(:documentation
"Makes a set of named functions available for remote invocation.
Instances of this class associate a collection of `local-method'
instances which are implemented by callback functions with a scope
under which these methods are exposed for remote clients."))
(rsb::register-participant-class 'local-server)
(flet ((set-method (server name argument callback)
(check-type argument argument-style)
(setf (participant-child server name :local-method)
(make-child-participant server name :local-method
:callback callback
:argument argument))))
(macrolet
((define-setf-server-method-method (name-type)
`(defmethod (setf server-method) ((new-value function)
(server local-server)
(name ,name-type)
&key
(argument :payload))
(set-method server name argument new-value))))
(define-setf-server-method-method string)
(define-setf-server-method-method (eql nil))))
| 6,207 | Common Lisp | .lisp | 131 | 32.908397 | 83 | 0.537141 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | b4201adfa8b402c5bbff4b6db2096f5b6b79e34b1ac1637eacc3ed8a42402bda | 25,297 | [
-1
] |
25,298 | conditions.lisp | open-rsx_rsb-cl/src/patterns/request-reply/conditions.lisp | ;;;; conditions.lisp --- Conditions used in the patterns.request-reply module.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply)
(define-condition no-such-method (no-such-child-error)
()
(:default-initargs
:name (missing-required-initarg 'no-such-method :name))
(:report
(lambda (condition stream)
(format stream "~@<The specified method ~S does not exist.~@:>"
(second (child-condition-key condition)))))
(:documentation
"This error is signaled when a specified method does not exist."))
(defun no-such-method-name (condition)
(second (child-condition-key condition)))
(define-condition remote-call-error (rsb-error
chainable-condition)
((method :initarg :method
:type method
:reader remote-call-error-method
:documentation
"Stores the method of the failed call.")
(request :initarg :request
:reader remote-call-error-request
:documentation
"Stores the request object that was passed to the method
in the failed call."))
(:default-initargs
:method (missing-required-initarg 'remote-call-error :method)
:request (missing-required-initarg 'remote-call-error :request))
(:report
(lambda (condition stream)
(format stream "~@<Failed to call method ~A with request ~
~A~/more-conditions:maybe-print-cause/~:@>"
(remote-call-error-method condition)
(remote-call-error-request condition)
condition)))
(:documentation
"This error is signaled when a remote method call fails for some
reason."))
(define-condition remote-method-execution-error (remote-call-error)
()
(:report
(lambda (condition stream)
(format stream "~@<Remote method ~A failed to execute for ~
request ~
~A~/more-conditions:maybe-print-cause/~:@>"
(remote-call-error-method condition)
(remote-call-error-request condition)
condition)))
(:documentation
"This error is signaled when a call to a remote method succeeds in
calling the method on the remote side but fails in the actual
remote method."))
| 2,356 | Common Lisp | .lisp | 57 | 33.77193 | 78 | 0.64952 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 00b29d461cb75ac9fa3d93e5a84dc2096ccf3783b8e21cd44120fb55307ade53 | 25,298 | [
-1
] |
25,299 | variables.lisp | open-rsx_rsb-cl/src/patterns/request-reply/variables.lisp | ;;;; variables.lisp --- Variables used in the patterns.request-reply module.
;;;;
;;;; Copyright (C) 2011, 2012, 2013, 2014 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply)
;;; Direct call mechanism
(defvar *local-call* nil
"The value of this special variable can be used to determine whether
a reply is received via direct function calls within a single
thread. If so, this variable is bound to a value of one of the
following forms
t
Indicates that a non-blocking local call is in progress.
(FUTURE . (REQUEST . RETURN))
Indicates that a blocking local call initiated by REQUEST is in
progress. RETURN indicates the desired return value processing
and FUTURE is the `future' instance for the call.
which allow to decide whether to proceed normally, spawn a thread
or store the result directly.")
;;; Request and reply filters
(defvar *request-filter*
(rsb.filter:make-filter :method :method :|request|)
"A filter which only accepts events which can be considered
requests.")
(defvar *reply-filter*
(rsb.filter:make-filter :method :method :|reply|)
"A filter which only accepts events which can be considered
replies.")
| 1,277 | Common Lisp | .lisp | 29 | 40.275862 | 76 | 0.738076 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 5c6046833f5dd145ef7109f287bca0284f7082b4b4aed7edb78e69fb9b7a5197 | 25,299 | [
-1
] |
25,300 | macros.lisp | open-rsx_rsb-cl/src/patterns/request-reply/macros.lisp | ;;;; macros.lisp --- Convenience macros provided by the patterns.request-reply module.
;;;;
;;;; Copyright (C) 2011-2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.patterns.request-reply)
(defun call-with-methods (server methods thunk)
(declare (type function thunk))
(let+ (((&flet+ add-one-method ((name request-type lambda))
(case request-type
(:event (setf (server-method server name :argument :event)
lambda))
(t (setf (server-method server name)
lambda)))))
((&flet+ remove-one-method ((name &ign &ign))
(when-let ((method (server-method server name :error? nil)))
(handler-bind
(((or error bt:timeout)
(lambda (condition)
(warn "~@<Error removing method ~S: ~A~@:>"
method condition)
(continue))))
(with-restart-and-timeout (10)
(setf (server-method server (method-name method)) nil)))))))
(unwind-protect
(progn
(mapc #'add-one-method methods)
(funcall thunk))
(mapc #'remove-one-method methods))))
(defmacro with-methods ((server) methods &body body)
"Execute body with the methods defined by METHODS added to
SERVER. METHODS is a list of items of the form
\(NAME ([ARG REQUEST-TYPE]) BODY)
where NAME is the name of the method, ARG is a symbol which will be
bound to the request data during the execution of the method body
BODY.
REQUEST-TYPE specifies the type of acceptable requests. If
REQUEST-TYPE is the keyword :event, BODY is called with ARG bound
to the request event (instead of just the payload).
If ARG and REQUEST-TYPE are omitted, the method does not accept
arguments and consequently BODY cannot access any argument binding
variable."
(let+ (((&flet+ process-one ((name (&optional arg (request-type t))
&rest body))
(let+ ((name/thunk (symbolicate name '#:-method-body))
(name/string (when name (string name)))
((&with-gensyms arg-var))
((&values body declarations) (parse-body body)))
(when name/string
(check-type name/string method-name "a valid method name"))
(check-type arg symbol "a symbol")
(check-type request-type (or symbol cons) ":EVENT or a type specifier")
`(list ,name/string ',request-type
(named-lambda ,name/thunk (,@(when arg `(,arg-var)))
,@(when (and arg (not (member request-type '(:event t))))
`((check-type ,arg-var ,request-type)))
(let (,@(when arg `((,arg ,arg-var))))
,@declarations
,@body)))))))
`(flet ((with-methods-thunk () ,@body))
(declare (dynamic-extent #'with-methods-thunk))
(call-with-methods ,server (list ,@(mapcar #'process-one methods))
#'with-methods-thunk))))
| 3,244 | Common Lisp | .lisp | 63 | 38.873016 | 86 | 0.560668 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | e6b7d4bbe76f89a83a457ac6c3113daa62a0aa83ed213371ef6c084fccfa67d3 | 25,300 | [
-1
] |
25,301 | model.lisp | open-rsx_rsb-cl/src/introspection/model.lisp | ;;;; model.lisp --- Model classes used by the introspection module.
;;;;
;;;; Copyright (C) 2014, 2015, 2016 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection)
;;; Functions related to `process-info'
(defun current-process-info ()
"Make and return a `process-info' instance describing the current
process."
(with-platform-information-fallback-values
(let+ (((program-name &rest arguments)
(current-program-name-and-commandline-arguments))
((&structure-r/o pathname- name type)
(uiop:parse-native-namestring program-name)))
(make-instance
'process-info
:process-id (current-process-id)
:program-name (format nil "~A~@[.~A~]" name type)
:commandline-arguments arguments
:start-time (current-process-start-time)
:executing-user (current-user)
:rsb-version (rsb-system:version/string :commit? t)
:display-name (option-value '(:introspection :displayname))))))
;;; Functions related to `host-info'
(defun current-host-info ()
"Return a `host-info' instance describing the local host."
(with-platform-information-fallback-values
(make-instance 'host-info
:id (current-host-id)
:hostname (current-hostname)
:machine-type (current-machine-type)
:machine-version (current-machine-version)
:software-type (current-software-type)
:software-version (current-software-version))))
;;; `hello' message
(defclass hello ()
((participant :initarg :participant
:type participant-info
:reader hello-participant
:documentation
"Stores information about the created participant.")
(process :initarg :process
:type process-info
:reader hello-process
:documentation
"Stores information about the local process.")
(host :initarg :host
:type host-info
:reader hello-host
:documentation
"Stores information about the local host."))
(:default-initargs
:participant (missing-required-initarg 'hello :participant)
:process (missing-required-initarg 'hello :process)
:host (missing-required-initarg 'hello :host))
(:documentation
"Instances of this message are published when participants are
created in the local process and may be received when participants
are created in remote processes."))
(defmethod print-object ((object hello) stream)
(print-unreadable-object (object stream :type t)
(format stream "~/print-items:format-print-items/"
(mapcar
(lambda+ ((&whole entry key value &optional &ign &ign))
(case key
(:id
(list key value " ~/rsb::print-id/" '((:after :transports))))
(t
entry)))
(print-items:print-items (hello-participant object))))))
;;; `bye' message
(defclass bye (uuid-mixin)
((rsb::id :initarg :id
:reader bye-id
:documentation
"Stores the unique id of the detached participant."))
(:default-initargs
:id (missing-required-initarg 'bye :id))
(:documentation
"Instances of this message are published when participants are
detached in the local process and may be received when
participants are destroyed in remote processes."))
(defmethod print-object ((object bye) stream)
(print-unreadable-id-object (object stream)))
| 3,762 | Common Lisp | .lisp | 85 | 35.588235 | 79 | 0.616476 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 83796b78c710e89cc876413217b8f2a196711482bc06821a5ca33b6eeaa9acaf | 25,301 | [
-1
] |
25,302 | conversion.lisp | open-rsx_rsb-cl/src/introspection/conversion.lisp | ;;;; conversion.lisp --- Converter for introspection messages.
;;;;
;;;; Copyright (C) 2014 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection)
(macrolet
((define-introspection-converter
((model-class notification-class wire-schema)
&key wire->domain domain->wire)
`(progn
(defmethod rsb.converter:wire->domain?
((converter (eql :introspection))
(wire-data simple-array)
(wire-schema (eql ,wire-schema)))
(values :introspection ',model-class))
(defmethod rsb.converter:domain->wire?
((converter (eql :introspection))
(domain-object ,model-class))
(values :introspection 'nibbles:octet-vector ,wire-schema))
(defmethod rsb.converter:wire->domain
((converter (eql :introspection))
(wire-data simple-array)
(wire-schema (eql ,wire-schema)))
(let ((notification (pb:unpack wire-data ',notification-class)))
,wire->domain))
(defmethod rsb.converter:domain->wire
((converter (eql :introspection))
(domain-object ,model-class))
(values (pb:pack* ,domain->wire) ,wire-schema)))))
(define-introspection-converter
(hello
rsb.protocol.introspection:hello
:|.rsb.protocol.introspection.Hello|)
:wire->domain
(let+ (((&accessors-r/o
(participant-id rsb.protocol.introspection:hello-id)
(kind rsb.protocol.introspection:hello-kind)
(type rsb.protocol.introspection:hello-type)
(transports rsb.protocol.introspection:hello-transport)
(scope rsb.protocol.introspection:hello-scope)
(process rsb.protocol.introspection:hello-process)
(host rsb.protocol.introspection:hello-host))
notification)
((&accessors-r/o
(process-id rsb.protocol.operatingsystem:process-id)
(program-name rsb.protocol.operatingsystem:process-program-name)
(commandline-arguments rsb.protocol.operatingsystem:process-commandline-arguments)
(start-time rsb.protocol.operatingsystem:process-start-time)
(executing-user rsb.protocol.operatingsystem:process-executing-user)
(rsb-version rsb.protocol.operatingsystem:process-rsb-version)
(display-name rsb.protocol.operatingsystem:process-display-name))
process)
((&accessors-r/o
(host-id rsb.protocol.operatingsystem:host-id)
(hostname rsb.protocol.operatingsystem:host-hostname)
(machine-type rsb.protocol.operatingsystem:host-machine-type)
(machine-version rsb.protocol.operatingsystem:host-machine-version)
(software-type rsb.protocol.operatingsystem:host-software-type)
(software-version rsb.protocol.operatingsystem:host-software-version))
host))
(make-instance
'hello
:participant (make-instance
'remote-participant-info
:kind (make-keyword (string-upcase kind))
:id (uuid:byte-array-to-uuid
participant-id)
:parent-id (when (and (rsb.protocol.introspection:hello-parent?
notification)
(not (emptyp (rsb.protocol.introspection:hello-parent
notification))))
(uuid:byte-array-to-uuid
(rsb.protocol.introspection:hello-parent
notification)))
:scope (make-scope scope)
:type (if (emptyp type) ; TODO
t
type
#+no (let ((*package* (find-package :keyword)))
(read-from-string type)))
:transports (map 'list #'puri:uri transports))
:process (make-instance
'process-info
:process-id (parse-integer process-id)
:program-name program-name
:commandline-arguments (coerce commandline-arguments 'list)
:start-time (unix-microseconds->timestamp
start-time)
:executing-user (unless (emptyp executing-user)
executing-user)
:rsb-version (unless (emptyp rsb-version)
rsb-version)
:display-name (unless (emptyp display-name)
display-name))
:host (make-instance
'host-info
:id host-id
:hostname hostname
:machine-type (unless (emptyp machine-type)
machine-type)
:machine-version (unless (emptyp machine-version)
machine-version)
:software-type (unless (emptyp software-type)
software-type)
:software-version (unless (emptyp software-version)
software-version))))
:domain->wire
(let+ (((&structure-r/o hello- participant process host) domain-object)
((&structure-r/o
participant-info- kind id scope type transports parent-id)
participant)
((&structure-r/o
process-info-
process-id program-name commandline-arguments
start-time executing-user rsb-version
display-name)
process)
((&structure-r/o
host-info- (host-id id) hostname
machine-type machine-version software-type software-version)
host))
(apply #'make-instance 'rsb.protocol.introspection:hello
:kind (string-downcase kind)
:id (uuid:uuid-to-byte-array id)
:scope (scope-string scope)
:type (prin1-to-string type)
:transport (map 'vector #'princ-to-string transports)
:process (apply
#'make-instance
'rsb.protocol.operatingsystem:process
:id (prin1-to-string process-id)
:program-name program-name
:commandline-arguments (coerce commandline-arguments
'(vector string))
:start-time (timestamp->unix-microseconds
start-time)
:executing-user executing-user
:rsb-version rsb-version
(when display-name
(list :display-name display-name)))
:host (make-instance
'rsb.protocol.operatingsystem:host
:id host-id
:hostname hostname
:machine-type machine-type
:machine-version machine-version
:software-type software-type
:software-version software-version)
(when parent-id
(list :parent (uuid:uuid-to-byte-array parent-id))))))
(define-introspection-converter
(bye
rsb.protocol.introspection:bye
:|.rsb.protocol.introspection.Bye|)
:wire->domain
(make-instance 'bye
:id (uuid:byte-array-to-uuid
(rsb.protocol.introspection:bye-id notification)))
:domain->wire
(make-instance
'rsb.protocol.introspection:bye
:id (uuid:uuid-to-byte-array (bye-id domain-object)))))
;;; Utility functions
;;; TODO these will be part of generic serialization/protocol helper functions
(defun timestamp->unix-microseconds (timestamp)
"Convert the `local-time:timestamp' instance TIMESTAMP into an
integer which counts the number of microseconds since UNIX epoch."
(+ (* 1000000 (local-time:timestamp-to-unix timestamp))
(* 1 (local-time:timestamp-microsecond timestamp))))
(defun unix-microseconds->timestamp (unix-microseconds)
"Convert UNIX-MICROSECONDS to an instance of
`local-time:timestamp'."
(let+ (((&values unix-seconds microseconds)
(floor unix-microseconds 1000000)))
(local-time:unix-to-timestamp
unix-seconds :nsec (* 1000 microseconds))))
| 9,299 | Common Lisp | .lisp | 177 | 35.259887 | 97 | 0.517238 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 105b1c23158776ea3a7a75599b224a43f7643e45f0dc3b631e72c9ed23e3b694 | 25,302 | [
-1
] |
25,303 | package.lisp | open-rsx_rsb-cl/src/introspection/package.lisp | ;;;; package.lisp --- Package definition for the introspection module.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.introspection
(:use
#:cl
#:alexandria
#:let-plus
#:more-conditions
#:rsb
#:rsb.model
#:rsb.patterns)
(:shadowing-import-from #:rsb.patterns
#:child-container-mixin)
(:import-from #:rsb.patterns.request-reply
#:remote-call-error
#:future-done?
#:future-result
#:server-method
#:call)
;; Conditions
(:export
#:introspection-protocol-error
#:no-such-participant-error
#:no-such-participant-error-container
#:no-such-participant-error-id)
;; Variables
(:export
#:+introspection-scope+
#:introspection-participants-scope #:+introspection-participants-scope+
#:participant-id->scope
#:scope->participant-id-or-nil
#:scope->participant-id
#:introspection-hosts-scope #:+introspection-hosts-scope+
#:introspection-process-scope)
;; Model protocol and classes
(:export
#:info-most-recent-activity
#:info-clock-offset
#:info-latency
#:participant-info #:remote-participant-info
#:participant-info-kind
#:participant-info-id
#:participant-info-parent-id
#:participant-info-scope
#:participant-info-type
#:participant-info-transports
#:process-info #:remote-process-info
#:process-info-process-id #:process-info-state
#:process-info-program-name #:process-info-transports
#:process-info-commandline-arguments
#:process-info-start-time
#:process-info-executing-user
#:process-info-rsb-version
#:process-info-display-name
#:current-process-info
#:host-info #:remote-host-info
#:host-info-id #:host-info-state
#:host-info-hostname
#:host-info-machine-type
#:host-info-machine-version
#:host-info-software-type
#:host-info-software-version
#:current-host-info)
;; Introspection message protocol
(:export
#:hello
#:hello-participant
#:hello-process
#:hello-host
#:bye
#:bye-id)
;; Participant table protocol
(:export
#:introspection-participants
#:introspection-participants/roots
#:find-participant) ; also `setf'
;; Process table protocol
(:export
#:introspection-processes
#:find-process ; also `setf'
#:ensure-process)
;; Host table protocol
(:export
#:introspection-hosts
#:find-host ; also `setf'
#:ensure-host)
;; Database locking protocol
(:export
#:call-with-database-lock
#:with-database-lock)
;; Change hook protocol
(:export
#:database-change-hook)
;; Introspection receiver protocol
(:export
#:introspection-survey
#:introspection-ping)
;; Remote database entries and protocol
(:export
#:entry-info
#:participant-entry
#:entry-parent
#:entry-children
#:process-entry
#:host-entry)
;; Reloading support
(:export
#:reinitialize-introspection)
(:documentation
"This package contains the introspection functionality.
There are two aspects:
1) Broadcasting pieces of introspection information describing the
local host, the current process and participants in it.
2) Receiving this information and aggregating the individual
pieces into a global view of the system.
1) should happen in almost all RSB applications while 2) is mostly
relevant for tools which inspect and describe system.
Both aspects share a model protocol and model classes to
handle (pieces of) introspection information. This model consists
of the classes:
* `participant-info' and `remote-participant-info' which describe
participants in general and participants in remote processes
respectively.
* `process-info' and `remote-process-info' which describe
processes in general and processes on remote hosts respectively.
* `host-info' and `remote-host-info' which describe hosts in
general and in remote hosts respectively."))
| 4,209 | Common Lisp | .lisp | 130 | 27.923077 | 74 | 0.687129 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 3aea70dcd8708ead3274d1d382ac44b90ff21a0f5b731f1a5219b1ae875ac3bd | 25,303 | [
-1
] |
25,304 | protocol.lisp | open-rsx_rsb-cl/src/introspection/protocol.lisp | ;;;; protocol.lisp --- Protocol provided by the introspection module.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection)
;;; Hello and bye messages
;;;
;;; Hello messages are sent when participants are created and when an
;;; introspection survey is performed. These messages contain
;;; information about the respective participants but also the
;;; containing processes and hosts.
;;;
;;; Bye messages only contain unique ids as their purpose is removing
;;; previously announced participants from introspection databases.
(defgeneric hello-participant (message)
(:documentation
"Return a `participant-info' instance representing the participant
to which MESSAGE refers."))
(defgeneric hello-process (message)
(:documentation
"Return a `process-info' instance representing the process
containing the participant to which MESSAGE refers."))
(defgeneric hello-host (message)
(:documentation
"Return a `host-info' instance representing the host on which the
process containing the participant to which MESSAGE refers is
executed."))
(defgeneric bye-id (message)
(:documentation
"Return the unique id of the participant to which MESSAGE
refers."))
;;; Participant table protocol
;;;
;;; Retrieval and manipulation of `participant-info' instances indexed
;;; by id.
(defgeneric introspection-participants (container)
(:documentation
"Return the list of all `participant-info' instances stored in
CONTAINER."))
(defgeneric (setf introspection-participants) (new-value container)
(:documentation
"Store NEW-VALUE as the list of `participant-info' instances in
CONTAINER."))
(defgeneric introspection-participants/roots (container)
(:documentation
"Return the list of root (i.e. without parent) `participant-info'
instances stored in CONTAINER."))
(defgeneric find-participant (id container
&key
parent-id
if-does-not-exist)
(:documentation
"Return the `participant-info' instance designated by ID in
CONTAINER.
PARENT-ID is accepted for parity with (setf find-participant).
IF-DOES-NOT-EXIST controls the behavior in case ID does not
designate a participant entry in CONTAINER."))
(defgeneric (setf find-participant) (new-value id container
&key
parent-id
if-does-not-exist)
(:documentation
"Store NEW-VALUE as the `participant-info' instance designated by
ID in CONTAINER.
If NEW-VALUE is nil, remove the corresponding entry.
IF-DOES-NOT-EXIST is accepted for parity with
`find-participant'."))
(defgeneric ensure-participant (id container default)
(:documentation
"If the participant designated by ID exists in CONTAINER,
return it. Otherwise create it according to DEFAULT, store and
return it.
DEFAULT is of the form
(CLASS . INITARGS)
and maybe be passed to `make-instance' or `change-class' depending
on the existing entry for ID."))
;; Default behavior
(defmethod introspection-participants/roots ((container t))
(remove container (introspection-participants container)
:test-not #'eq :key #'node-parent))
;;; Process table protocol
(defgeneric introspection-processes (container)
(:documentation
"Return the list of `process-info' instances stored in
CONTAINER."))
(defgeneric find-process (id container)
(:documentation
"Return the process designated by ID in CONTAINER."))
(defgeneric (setf find-process) (new-value id container)
(:documentation
"Store NEW-VALUE as the process designated by ID in CONTAINER."))
(defgeneric ensure-process (id container process &key receiver)
(:documentation
"If the process designated by ID exists in CONTAINER, update it
with information from PROCESS and return it. Otherwise create and
return a new entry based on PROCESS.
RECEIVER is the introspection receiver through which PROCESS was
received. This relation is recorded in the updated or created
entry."))
;;; Host table protocol
(defgeneric introspection-hosts (container)
(:documentation
"Return the list of `host-info' instances stored in CONTAINER."))
(defgeneric find-host (id container)
(:documentation
"Return the host designated by ID in CONTAINER."))
(defgeneric (setf find-host) (new-value id container)
(:documentation
"Store NEW-VALUE as the host designated by ID in CONTAINER."))
(defgeneric ensure-host (id container host)
(:documentation
"If the host designated by ID exists in CONTAINER, return
it. Otherwise create and return a new entry based on HOST."))
;;; Database locking protocol
(defgeneric call-with-database-lock (database thunk)
(:documentation
"Call THUNK with locked DATABASE."))
;;; Timing tracker protocol
(defgeneric timing-tracker-clock-offset (tracker)
(:documentation
"Return the clock offset estimated by TRACKER or nil if not
available."))
(defgeneric timing-tracker-latency (tracker)
(:documentation
"Return the communication latency estimated by TRACKER or nil if
not available."))
(defgeneric timing-tracker-to-local-clock (tracker time &key allow-future?)
(:documentation
"Return a timestamp corresponding to TIME but expressed with
respect to the local clock.
If possible, the clock offset estimate computed by TRACKER is used
to perform the conversion.
ALLOW-FUTURE? controls whether returned timestamps are restricted
to the current time of the local clock or earlier."))
;;; Database change hook protocol
(defgeneric database-change-hook (database)
(:documentation
"Return a hook that is run when DATABASE changes."))
;;; Introspection receiver protocol
(defgeneric introspection-survey (introspection)
(:documentation
"Perform an introspection survey collecting the results in
INTROSPECTION."))
(defgeneric introspection-ping (introspection host process
&key
block?)
(:documentation
"Send a \"ping\" message to PROCESS running on HOST and return the
reply event.
BLOCK? controls whether the call should block until the reply
arrives. If false, a `rsb.patterns.request-reply:future' is
returned."))
| 6,454 | Common Lisp | .lisp | 153 | 37.163399 | 75 | 0.733451 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 049788e515bda58284353851ee022ea2777667a47b185f5534c42277fb7e9ccb | 25,304 | [
-1
] |
25,305 | reloading.lisp | open-rsx_rsb-cl/src/introspection/reloading.lisp | ;;;; reloading.lisp --- Support for releading images with RSB introspection.
;;;;
;;;; Copyright (C) 2014 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection)
(defun reinitialize-introspection ()
;; Note that the body is only executed when there already is a local
;; database object. Otherwise, nothing happens.
(with-local-database (database)
(let+ (((&structure introspection- process host) database))
(setf host (current-host-info)
process (current-process-info))
(log:info "~@<Reinitialized ~A with ~A and ~A~@:>"
database host process))))
#+sbcl (pushnew 'reinitialize-introspection sb-ext:*init-hooks*)
#-sbcl (pushnew 'reinitialize-introspection uiop:*image-restore-hook*)
| 800 | Common Lisp | .lisp | 17 | 42.941176 | 76 | 0.702564 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 66bf61bdcf1beb4a6f14ddb1dde5ab60ddcb7ed71e150c3d52ff2362b63c2273 | 25,305 | [
-1
] |
25,306 | builder.lisp | open-rsx_rsb-cl/src/introspection/builder.lisp | ;;;; builder.lisp --- (un)builder support for introspection nodes.
;;;;
;;;; Copyright (C) 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:defpackage #:rsb.introspection.builder
(:use
#:cl
#:let-plus
#:architecture.builder-protocol
#:rsb.introspection)
(:import-from #:rsb.introspection
#:tracked-quantity
#:tracked-quantity-name
#:tracked-quantity-value
#:tracked-quantity-history
#:timing-tracker-%clock-offset
#:timing-tracker-%latency
#:entry-%tracker
#:remote-introspection-database)
(:import-from #:rsb.model.builder
#:define-node-methods))
(cl:in-package #:rsb.introspection.builder)
;;; database
(defmethod node-kind ((builder t) (node remote-introspection-database))
:database)
(defmethod node-relations ((builder t) (node remote-introspection-database))
'((:children . *)))
(defmethod node-relation ((builder t)
(relation (eql :children))
(node remote-introspection-database))
(introspection-hosts node))
;;; `host-entry'
(defmethod node-relations ((builder t) (node host-entry))
(list* '(:clock-offset . 1) '(:latency . 1) (call-next-method)))
(defmethod node-relation ((builder t)
(relation (eql :clock-offset))
(node host-entry))
(timing-tracker-%clock-offset (entry-%tracker node)))
(defmethod node-relation ((builder t)
(relation (eql :latency))
(node host-entry))
(timing-tracker-%latency (entry-%tracker node)))
;;; `process-entry'
(defmethod node-relations ((builder t) (node process-entry))
(list* '(:latency . 1) (call-next-method)))
(defmethod node-relation ((builder t)
(relation (eql :latency))
(node process-entry))
(timing-tracker-%latency (entry-%tracker node)))
;;; `tracked-quantity'
(define-node-methods (tracked-quantity :kind :tracked-quantity)
(name :builders t)
(value :builders t))
(defmethod node-relations ((builder t) (node tracked-quantity))
'((:history . *)))
(defmethod node-relation ((builder t)
(relation (eql :history))
(node tracked-quantity))
(tracked-quantity-history node))
| 2,341 | Common Lisp | .lisp | 60 | 32.133333 | 76 | 0.631812 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 01da3a5ee2cc34f4fbace8e841c0f4508bd4f08a1ff25454be0a2d278bda5ac8 | 25,306 | [
-1
] |
25,307 | platform-sbcl-win32.lisp | open-rsx_rsb-cl/src/introspection/platform-sbcl-win32.lisp | ;;;; platform-sbcl-win32.lisp --- Platform-specific functions for SBCL on Win32.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection)
;;; Process information
(defun current-process-id ()
(sb-posix:getpid)) ; cannot fail
(defun current-program-name-and-commandline-arguments ()
sb-ext:*posix-argv*)
;; Process start time
;; kernel32.dll; Cannot fail according to MSDN.
(sb-alien:define-alien-routine ("GetCurrentProcess" get-current-process)
(* t))
(sb-alien:define-alien-type nil
(sb-alien:struct filetime
(low-date-time sb-win32::dword)
(high-date-time sb-win32::dword)))
(declaim (ftype (function ((sb-alien:alien (sb-alien:struct filetime))) integer)
filetime/struct->filetime/integer))
(defun filetime/struct->filetime/integer (filetime)
(let ((high (sb-alien:slot filetime 'high-date-time))
(low (sb-alien:slot filetime 'low-date-time)))
(dpb high (byte 32 32) low)))
(define-constant +filetime-base-time+
(local-time:parse-rfc3339-timestring "1601-01-01T00:00:00Z")
:test #'local-time:timestamp=)
(defun filetime/integer->local-time (nanoseconds/100)
(let ((local-time:*default-timezone* local-time:+utc-zone+))
(local-time:adjust-timestamp +filetime-base-time+
(:offset :nsec (* 100 nanoseconds/100)))))
;; kernel32.dll
(sb-alien:define-alien-routine ("GetProcessTimes" get-process-time)
sb-alien:long
(process (* t))
(create (* (sb-alien:struct filetime)))
(exit (* (sb-alien:struct filetime)))
(kernel (* (sb-alien:struct filetime)))
(user (* (sb-alien:struct filetime))))
(defun %current-process-start-time ()
(with-platform-information-error-translation
("determine start time of the current process")
(sb-alien:with-alien ((create (sb-alien:struct filetime))
(exit (sb-alien:struct filetime))
(kernel (sb-alien:struct filetime))
(user (sb-alien:struct filetime)))
(if (zerop (get-process-time (get-current-process)
(sb-alien:addr create) (sb-alien:addr exit)
(sb-alien:addr kernel) (sb-alien:addr user)))
(sb-win32::win32-error "GetProcessTimes")
(filetime/integer->local-time
(filetime/struct->filetime/integer create))))))
;; User
(sb-alien:load-shared-object "advapi32")
(sb-alien:define-alien-routine ("GetUserNameW" get-user-name/w)
sb-alien:long
(buffer (array sb-alien:char))
(length (* sb-alien:long)))
(defun %current-user ()
(with-platform-information-error-translation
("determine username via GetUserNameW")
(sb-alien:with-alien ((buffer (array sb-alien:char 1024))
(length sb-alien:long :local 1024))
(if (zerop (get-user-name/w (sb-alien:cast buffer (array sb-alien:char))
(sb-alien:addr length)))
(sb-win32::win32-error "GetUserNameW")
;; The C-string in BUFFER is guaranteed to be
;; NULL-terminated, doing this conversion without explicitly
;; stopping after LENGTH characters is safe.
(sb-alien::c-string-to-string
(sb-alien:alien-sap buffer) :utf-16le 'character)))))
;;; Host information
(sb-alien:load-shared-object "secur32")
(sb-alien:define-alien-routine ("GetComputerObjectNameW" get-computer-object-name/w)
sb-alien:int
(format sb-alien:int)
(buffer (array sb-alien:char 1024))
(length (* sb-alien:long)))
(defun %current-host-id ()
(with-platform-information-error-translation
("determine unique id of the computer")
(sb-alien:with-alien ((buffer (sb-alien:array sb-alien:char 1024))
(length sb-alien:long :local 1024))
(if (zerop (get-computer-object-name/w 6 buffer (sb-alien:addr length)))
(sb-win32::win32-error "GetComputerObjectNameW")
;; Hopefully, the C-string in BUFFER is guaranteed to be
;; NULL-terminated, doing this conversion without explicitly
;; stopping after LENGTH characters is safe.
(sb-alien::c-string-to-string
(sb-alien:alien-sap buffer) :utf-16le 'character)))))
| 4,332 | Common Lisp | .lisp | 91 | 40.483516 | 84 | 0.652689 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 6105ee6555ecd182866dd9c5d5476758dc6a82dfb911ad0d15cd9114b1858747 | 25,307 | [
-1
] |
25,308 | platform-sbcl-darwin.lisp | open-rsx_rsb-cl/src/introspection/platform-sbcl-darwin.lisp | ;;;; platform-sbcl-darwin.lisp --- Platform-specific functions for SBCL on Darwin.
;;;;
;;;; Copyright (C) 2014 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection)
;;; Process information
(defun current-process-id ()
(sb-posix:getpid)) ; cannot fail according to getpid(2)
(defun current-program-name-and-commandline-arguments ()
sb-ext:*posix-argv*)
;; This is not the actual definition of the kproc structure, but we
;; are only interested in the start time.
(sb-alien:define-alien-type nil
(sb-alien:struct kproc
(start-time (sb-alien:struct sb-unix:timeval))
(padding (array sb-alien:char 632))))
(defun %current-process-start-time ()
(with-platform-information-error-translation
("determine start time of the current process")
(sb-alien:with-alien ((mib (array sb-alien:int 16))
(mib-size sb-alien:size-t 16))
;; Translate the string name into a sequence of numeric ids.
(sb-unix::syscall* ("sysctlnametomib" sb-alien:c-string (* sb-alien:int) (* sb-alien:size-t))
(values)
"kern.proc.pid"
(sb-alien:cast mib (* sb-alien:int)) (sb-alien:addr mib-size))
;; Add the process id as the fourth element of the mib. Increase
;; the size correspondingly.
(setf (sb-alien:deref mib mib-size) (sb-posix:getpid))
(incf mib-size)
;; Return information block and extract start time.
(sb-alien:with-alien
((kproc (sb-alien:struct kproc))
(kproc-size sb-alien:size-t (sb-alien:alien-size
(sb-alien:struct kproc))))
(sb-unix::syscall* ("sysctl" (* sb-alien:int) sb-alien:size-t
(* t) (* sb-alien:size-t)
(* t) sb-alien:size-t)
(let* ((start-time (sb-alien:slot kproc 'start-time))
(seconds (sb-alien:slot start-time 'sb-unix::tv-sec))
(micro-seconds (sb-alien:slot start-time 'sb-unix::tv-usec)))
(local-time:unix-to-timestamp seconds :nsec (* 1000 micro-seconds)))
(sb-alien:cast mib (* sb-alien:int)) mib-size
(sb-alien:addr kproc) (sb-alien:addr kproc-size)
(sb-sys:int-sap 0) 0)))))
;;; Host information
(defun %current-host-id ()
(with-platform-information-error-translation
("determine unique id of the computer")
(sb-alien:with-alien ((timeout (sb-alien:struct sb-unix::timespec))
(uuid (sb-alien:array sb-alien:unsigned-char 16)))
(setf (sb-alien:slot timeout 'sb-unix::tv-sec) 1
(sb-alien:slot timeout 'sb-unix::tv-nsec) 0)
(sb-unix::syscall* ("gethostuuid" (* (array sb-alien:unsigned-char 16))
(* (sb-alien:struct sb-unix::timespec)))
(with-output-to-string (stream)
(dotimes (i 16)
(format stream "~(~2,'0X~)" (sb-alien:deref uuid i))))
(sb-alien:addr uuid) (sb-alien:addr timeout)))))
| 3,112 | Common Lisp | .lisp | 60 | 42.216667 | 99 | 0.598226 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 7ca6ecf3c034b4d8c110a6f3e9085019cdccd516c1fbe86bc1002b83a0fe7b7a | 25,308 | [
-1
] |
25,309 | conditions.lisp | open-rsx_rsb-cl/src/introspection/conditions.lisp | ;;;; conditions.lisp --- Conditions used by the introspection module.
;;;;
;;;; Copyright (C) 2014 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection)
;;; Protocol-related conditions
(define-condition introspection-protocol-condition (rsb.patterns:protocol-condition)
()
(:default-initargs
:protocol :introspection)
(:documentation
"Instances of subclasses of this condition class are signaled to
indicate occurrences of conditions related to the introspection
protocol."))
(define-condition introspection-protocol-error (introspection-protocol-condition
rsb.patterns:protocol-error)
()
(:documentation
"This error is signaled to indicate a violation of the
introspection protocol."))
(define-condition simple-introspection-protocol-error (introspection-protocol-error
rsb.patterns:simple-protocol-condition)
()
(:documentation
"This error condition class simplifies signaling of simple
`introspection-protocol-error' s."))
(defun introspection-error (role message cause
&optional format-control
&rest format-arguments)
(error 'simple-introspection-protocol-error
:role role
:message message
:cause cause
:format-control format-control
:format-arguments format-arguments))
;;; Database-related conditions
(define-condition no-such-participant-error (rsb-error)
((container :initarg :container
:reader no-such-participant-error-container
:documentation
"Stores the container in which the participant could not
be found.")
(id :initarg :id
:reader no-such-participant-error-id
:documentation
"Stores the id for which no participant could be found
in the container."))
(:default-initargs
:container (missing-required-initarg 'no-such-participant-error :container)
:id (missing-required-initarg 'no-such-participant-error :id))
(:report
(lambda (condition stream)
(format stream "~@<No participant ~A in container ~A.~@:>"
(no-such-participant-error-id condition)
(no-such-participant-error-container condition))))
(:documentation
"This error is signaled when an attempt to retrieve a participant
by ids id fails."))
| 2,565 | Common Lisp | .lisp | 59 | 35.237288 | 94 | 0.657326 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 21756780a95ca2c42cdace10b2929802d649026862030eb494ca8f80fa779317 | 25,309 | [
-1
] |
25,310 | variables.lisp | open-rsx_rsb-cl/src/introspection/variables.lisp | ;;;; variables.lisp --- Variables used by the introspection module.
;;;;
;;;; Copyright (C) 2014 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection)
;;; Reserved scopes used by the introspection protocol
;;;
;;; Currently, there are sub-scopes for participants, hosts and
;;; processes.
(defparameter +introspection-scope+
(make-scope (merge-scopes "/introspection" *reserved-scope*) :intern? t)
"Scope for all introspection communication.")
;; Participants scope
(defun introspection-participants-scope (&optional
(base +introspection-scope+))
(make-scope (merge-scopes '("participants") base) :intern? t))
(defparameter +introspection-participants-scope+
(introspection-participants-scope +introspection-scope+)
"Default sub-scope for participant introspection.")
(defun participant-id->scope (id &optional (base +introspection-scope+))
(merge-scopes (list (princ-to-string id))
(introspection-participants-scope base)))
(defun scope->participant-id-or-nil (scope &optional (base +introspection-scope+))
(when-let* ((participants-scope (introspection-participants-scope base))
(length (length (scope-components participants-scope)))
(component (nth length (scope-components scope))))
(uuid:make-uuid-from-string component)))
(defun scope->participant-id (scope &optional (base +introspection-scope+))
(or (scope->participant-id-or-nil scope base)
(error "~@<No participant-id scope component in scope ~A~@:>"
(scope-string scope))))
;; Hosts and processes scope
(defun introspection-hosts-scope (&optional
(base +introspection-scope+))
(make-scope (merge-scopes '("hosts") base) :intern? t))
(defparameter +introspection-hosts-scope+
(introspection-hosts-scope +introspection-scope+)
"Default sub-scope for host and process introspection.")
(defun introspection-process-scope (process-id host-id
&optional
(base +introspection-scope+))
(merge-scopes (list (derive-scope-component host-id)
(derive-scope-component
(write-to-string process-id :base 10 :escape nil)))
(introspection-hosts-scope base)))
;;; Filters used in the introspection protocol
(defvar *survey-filter*
(rsb.filter:filter '(:or (:method :method :|request|)
(:method :method :|survey|))))
(defvar *broadcast-filter*
(rsb.filter:make-filter :method :method nil))
;;; Converters used for introspection payloads
(defvar *introspection-host-converters*
'(:fundamental-void :fundamental-utf-8-string))
(defvar *introspection-all-converters*
`(,@*introspection-host-converters* :introspection))
;;; Local introspection database
(defvar *local-database* nil
"Stores the introspection database for local participants.
This singleton database object is created lazily by
`call-with-local-database'. However, once it has been created, it
is retained indefinitely, even across image restarts.")
(defvar *local-database-lock* (bt:make-recursive-lock "Local database lock")
"A lock that protects accesses to `*local-database*'.")
(defun call-with-local-database (thunk &key if-does-not-exist)
"Call THUNK with one argument, the database. Return what THUNK returns.
During the call of THUNK the passed database object is locked.
Depending on IF-DOES-NOT-EXIST, create the database if necessary:
:create
Create the database, if it does not already exist, then, in any
case, call THUNK with the database object. Return whatever THUNK
returns.
nil
If the database already exists, call THUNK with the existing
object and return whatever THUNK returns. Otherwise do not call
THUNK and return nil."
(bt:with-recursive-lock-held (*local-database-lock*)
(let+ (((&flet success (database)
(return-from call-with-local-database
(funcall thunk database))))
((&flet call (database thunk)
(call-with-database-lock ; `with-database-lock' not yet defined
database (lambda () (funcall thunk database))))))
(when-let ((database *local-database*))
(call database (lambda (database)
(when (introspection-participants database)
(funcall #'success database)))))
(when (eq if-does-not-exist :create)
(log:info "~@<Creating local introspection.~@:>")
(let ((database (make-participant
:local-introspection +introspection-scope+)))
(hooks:add-to-hook (participant-error-hook database)
(lambda (condition)
(log:warn "Condition~2&~2@T~A~2&~2@T~A"
condition (find-restart 'continue))
(continue))) ; TODO hack
(setf *local-database* database)
(call database #'success))))))
(defmacro with-local-database ((database-var &key if-does-not-exist)
&body body)
"Execute BODY with DATABASE-VAR bound to the local introspection
database.
For a description of IF-DOES-NOT-EXIST, see
`call-with-local-database'."
`(call-with-local-database
(named-lambda with-local-database-thunk (,database-var) ,@body)
:if-does-not-exist ,if-does-not-exist))
;;; [Un]registering participants
;;;
;;; Called to add and remote entries to/from the local introspection
;;; database as participants are created and destroyed in the local
;;; process.
(defun register-participant (participant &optional parent)
(let ((id (participant-id participant))
(parent-id (when parent (participant-id parent))))
(log:info "~@<Adding participant ~A to introspection~@:>" participant)
(restart-case
(with-local-database (database :if-does-not-exist :create)
(setf (find-participant id database :parent-id parent-id)
participant))
(continue (&optional condition)
:report (lambda (stream)
(format stream "~@<Continue without introspection ~
for ~A~@:>"
participant))
(declare (ignore condition))))))
(defun unregister-participant (participant)
(log:info "~@<Removing participant ~A from introspection~@:>" participant)
(restart-case
(with-local-database (database)
(setf (find-participant (participant-id participant) database
:if-does-not-exist nil)
nil))
(continue (&optional condition)
:report (lambda (stream)
(format stream "~@<Continue without removing ~A from ~
introspection~@:>"
participant))
(declare (ignore condition)))))
;;; Participant state change handlers
(defun exclude-from-introspection? (participant)
(or (member (participant-kind participant)
'(:local-introspection
:remote-introspection :introspection-receiver)
:test #'eq)
(sub-scope? (participant-scope participant) +introspection-scope+)))
(defun handle-make-participant (participant args)
;; Register PARTICIPANT for introspection but only if it does not
;; look like being part of the introspection machinery itself.
(let+ (((&plist-r/o (introspection? :introspection?) (parent :parent)) args))
(when (and introspection? (not (exclude-from-introspection? participant)))
(register-participant participant parent)))
;; Do not return a non-nil value: the hook interprets such a value
;; as a replacement for PARTICIPANT.
nil)
(defgeneric handle-participant-state-change (participant new-state)
(:method ((participant t) (new-state t))
nil)
(:method ((participant t) (new-state (eql :detached)))
(unless (exclude-from-introspection? participant)
(unregister-participant participant)))
(:documentation
"Handle the event of PARTICIPANT changing into state NEW-STATE.
Most importantly, call `unregister-participant' when NEW-STATE
is :detached.
This generic function is not part of a public protocol. It exists
only for local convenient and flexible dispatch."))
;;; Event handling
;; Avoid adding handler multiple times after redefinition of
;; handle-{make-participant,participant-state-change}.
(defvar *make-participant-handler*
(lambda (&rest args) (apply 'handle-make-participant args)))
(hooks:add-to-hook '*make-participant-hook* *make-participant-handler*)
(defvar *participant-state-change-handler*
(lambda (&rest args) (apply 'handle-participant-state-change args)))
(hooks:add-to-hook '*participant-state-change-hook*
*participant-state-change-handler*)
| 8,990 | Common Lisp | .lisp | 178 | 42.314607 | 82 | 0.667579 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 46b089633f1606e13a436d311b5d8b95e90029d40f6f1aa2afe361afd7b9c9f7 | 25,310 | [
-1
] |
25,311 | platform-common.lisp | open-rsx_rsb-cl/src/introspection/platform-common.lisp | ;;;; platform-common.lisp --- Utilities for platform-specific functions.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection)
;;; Platform information errors
(define-condition platform-information-error (simple-error
chainable-condition)
()
(:report
(lambda (condition stream)
(format stream "~?~/more-conditions:maybe-print-cause/"
(simple-condition-format-control condition)
(simple-condition-format-arguments condition)
condition))))
(defun platform-information-error (cause
&optional format-control
&rest format-arguments)
(error 'platform-information-error
:format-control format-control
:format-arguments format-arguments
:cause cause))
(defun call-with-platform-information-error-translation (description thunk)
(with-condition-translation (((error platform-information-error)
:format-control "~@<Could not ~A.~@:>"
:format-arguments (list description)))
(funcall thunk)))
(defmacro with-platform-information-error-translation ((description) &body body)
`(call-with-platform-information-error-translation
,description (lambda () ,@body)))
;;; Fallback values
(defun call-with-platform-information-fallback-values (thunk)
(handler-bind ((platform-information-error
(lambda (condition)
(log:warn "~@<~A.~@:_Using fallback value.~@:>"
condition)
(continue))))
(funcall thunk)))
(defmacro with-platform-information-fallback-values (&body body)
`(call-with-platform-information-fallback-values (lambda () ,@body)))
;;;
(defun current-process-start-time ()
(let ((fallback))
(restart-case
(%current-process-start-time)
(continue (&optional condition)
:report (lambda (stream)
(format stream "~@<Use a fallback start time value.~@:>"))
(declare (ignore condition))
(or fallback (setf fallback (local-time:now)))))))
#-win32
(defun %current-user ()
(with-platform-information-error-translation
("determine username from passwd database entry")
(if-let ((entry (sb-posix:getpwuid (sb-posix:getuid))))
(sb-posix:passwd-name entry)
(error "~@<No passwd database entry for current user.~@:>"))))
(defun current-user ()
(restart-case
(%current-user)
(continue (&optional condition)
:report (lambda (stream)
(format stream "~@<Guess username from home directory.~@:>"))
(declare (ignore condition))
(when-let* ((pathname (user-homedir-pathname))
(directory (pathname-directory pathname)))
(when (>= (length directory) 2)
(lastcar directory))))))
(defun current-host-id (&key (compatible? t))
;; For compatibility with languages who have no easy way of calling
;; C API functions, use hostname instead calling host id C function
;; provided by respective operating system.
(when (and compatible?
(member (current-software-type) '("win32" "darwin")
:test #'string=))
(return-from current-host-id (current-hostname)))
(restart-case
(%current-host-id)
(continue (&optional condition)
:report (lambda (stream)
(format stream "~@<Use a fallback host id value.~@:>"))
(declare (ignore condition))
(current-hostname))))
(defun current-hostname ()
(first (split-sequence:split-sequence #\. (machine-instance))))
(defun current-machine-type ()
(substitute #\_ #\- (string-downcase (machine-type))))
(defun current-machine-version ()
(machine-version))
(defun current-software-type ()
(string-downcase (software-type)))
(defun current-software-version ()
(software-version))
| 4,031 | Common Lisp | .lisp | 94 | 34.882979 | 80 | 0.634669 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | aecbc08999e57cded3f69902d608dccb80d89b31a7f6207ae82fe133049b5ad7 | 25,311 | [
-1
] |
25,312 | platform-generic.lisp | open-rsx_rsb-cl/src/introspection/platform-generic.lisp | ;;;; platform-generic.lisp --- Generic platform.
;;;;
;;;; Copyright (C) 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
(cl:in-package #:rsb.introspection)
;;; Process information
(defun current-process-id ()
0)
(defun current-program-name-and-commandline-arguments ()
(list* (uiop:argv0) (uiop:command-line-arguments)))
(defun %current-process-start-time ()
(with-platform-information-error-translation
("determine start time of the current process")
(error "~@<Not available.~@:>")))
;;; Host information
(defun %current-host-id ()
(with-platform-information-error-translation
("determine unique id of the computer")
(error "~@<Not available.~@:>")))
| 732 | Common Lisp | .lisp | 20 | 33.85 | 61 | 0.707801 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 298ed466d2de8a95aca58049d32b58225357ba8d43cabcac73b422dc56324f04 | 25,312 | [
-1
] |
25,313 | timing-tracking.lisp | open-rsx_rsb-cl/src/introspection/timing-tracking.lisp | ;;;; timing-tracking.lisp --- Track timing properties of remote processes, hosts.
;;;;
;;;; Copyright (C) 2013, 2014, 2015 Jan Moringen
;;;;
;;;; Author: Jan Moringen <[email protected]>
;;;; This file contains the following classes:
;;;;
;;;; `tracked-quantity'
;;;;
;;;; Stores a series of measurements for a single quantity and
;;;; provides simple statistical analysis: median, mean, variance.
;;;;
;;;; `timing-tracker' (aka Ghetto NTP)
;;;;
;;;; An instance of this class consumes events sent by a particular
;;;; remote process to the local process in response to previous
;;;; events sent in the opposite direction. The remote process
;;;; annotates reply events with send and receive timestamps of the
;;;; corresponding request events.
;;;;
;;;; Applying the basic offset estimation algorithm of the Network
;;;; Time Protocol allows estimating the difference between the
;;;; local clock and the remote clock as well as the mean event
;;;; transport latency based on a set of such events.
;;;;
;;;; See
;;;; http://en.wikipedia.org/wiki/Network_Time_Protocol#Clock_synchronization_algorithm
;;;;
;;;; Uses two `tracked-quantity' instances to track clock offsets
;;;; and latencies.
(cl:in-package #:rsb.introspection)
;;; `tracked-quantity'
(defstruct (tracked-quantity
(:constructor make-tracked-quantity
(&key name (capacity 100) (history '())))
(:copier nil))
"Instances of this track measured values of a quantity over time."
(name nil :type (or null string))
;; Stores the maximum number of offset samples to keep for median,
;; mean, etc. calculation.
(capacity 100 :type positive-integer)
;; Stores offset samples for mean offset calculation.
(history '() :type list #| of real |#))
(defun tracked-quantity-value (quantity)
(let+ (((&structure-r/o tracked-quantity- history) quantity))
(when (> (length history) 3)
(values (median history) (mean history) (variance history)))))
(defun tracked-quantity-add (quantity value)
(let+ (((&structure tracked-quantity- capacity history) quantity))
(push value history)
(when (> (length history) capacity)
(setf (cdr (nthcdr (1- capacity) history)) '())))
quantity)
(defun tracked-quantity-reset (quantity)
(setf (tracked-quantity-history quantity) '()))
(defmethod print-items:print-items append ((object tracked-quantity))
`((:name ,(tracked-quantity-name object), "~S")
(:value ,(tracked-quantity-value object) " ~:[n/a~:;~:*~A~]" ((:after :name)))
(:num-entries ,(length (tracked-quantity-history object)) " (~D)" ((:after :value)))))
(defmethod print-object ((object tracked-quantity) stream)
(print-unreadable-object (object stream :type t :identity t)
(format stream "~/print-items:format-print-items/"
(print-items:print-items object))))
;;; `timing-tracker'
(defclass timing-tracker ()
((clock-offset :type tracked-quantity
:reader timing-tracker-%clock-offset
:initform (make-tracked-quantity :name "clock-offset")
:documentation
"Stores the clock offset estimation as a
`tracked-quantity' instance.")
(latency :type tracked-quantity
:reader timing-tracker-%latency
:initform (make-tracked-quantity :name "latency")
:documentation
"Stores the latency estimation as a
`tracked-quantity' instance."))
(:documentation
"Instances of this class consume events with timestamp annotations
and estimate the clock offset and latency between the local host
and remote hosts based on a bounded log of events."))
(defmethod timing-tracker-clock-offset ((tracker timing-tracker))
(tracked-quantity-value (timing-tracker-%clock-offset tracker)))
(defmethod timing-tracker-latency ((tracker timing-tracker))
(tracked-quantity-value (timing-tracker-%latency tracker)))
(defmethod timing-tracker-to-local-clock ((tracker timing-tracker)
(time local-time:timestamp)
&key
allow-future?)
(let+ (((&flet maybe-transform (time)
(if-let ((offset (timing-tracker-clock-offset tracker)))
(let+ (((&values seconds remainder) (floor (- offset))))
(local-time:adjust-timestamp time
(:offset :sec seconds)
(:offset :nsec (floor remainder 1/1000000000))))
time)))
((&flet ensure-not-future (time)
(extremum (list (local-time:now) time)
#'local-time:timestamp<)))
(localized (maybe-transform time)))
(if allow-future?
localized
(ensure-not-future localized))))
(defmethod rsb.ep:handle ((sink timing-tracker) (data event))
;; This is the actual clock offset and latency estimation. See
;; description above for explanation and reference.
(let+ (((&structure-r/o timing-tracker- %clock-offset %latency) sink))
(when-let* ((t0 (timestamp data :request.send))
(t1 (timestamp data :request.receive))
(t2 (timestamp data :send))
(t3 (timestamp data :receive))
(diff1 (local-time:timestamp-difference t1 t0))
(diff2 (local-time:timestamp-difference t3 t2))
(offset (/ (- diff1 diff2) 2))
(latency (/ (+ diff1 diff2) 2)))
(tracked-quantity-add %clock-offset offset)
(tracked-quantity-add %latency latency))))
(defmethod rsb.ep:handle ((sink timing-tracker) (data (eql :reset)))
(tracked-quantity-reset (timing-tracker-%clock-offset sink))
(tracked-quantity-reset (timing-tracker-%latency sink)))
| 5,941 | Common Lisp | .lisp | 120 | 42.133333 | 102 | 0.637209 | open-rsx/rsb-cl | 1 | 0 | 5 | LGPL-3.0 | 9/19/2024, 11:28:28 AM (Europe/Amsterdam) | 00feaa5a23a15094fb207c4839d60980eccc76d63cc1eb6f29c40b2d5aa7a794 | 25,313 | [
-1
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.