52 lines
2.1 KiB
Racket
52 lines
2.1 KiB
Racket
#lang syndicate/actor
|
|
|
|
(require racket/cmdline)
|
|
(require racket/port)
|
|
(require racket/set)
|
|
|
|
(require "private/util.rkt")
|
|
(require "protocol.rkt")
|
|
|
|
(require/activate syndicate/drivers/timestate)
|
|
(require/activate "config.rkt")
|
|
(require/activate "hub/static-content.rkt")
|
|
(require/activate "hub/topic-demand.rkt")
|
|
(require/activate "hub/local-topic.rkt")
|
|
(require/activate "hub/subscription.rkt")
|
|
|
|
(command-line #:program "racketmq"
|
|
|
|
#:once-each
|
|
["--canonical-host" host port "Specify the canonical host and port for this hub"
|
|
(actor #:name (list 'command-line-canonical-host host port)
|
|
(assert (config (list 'canonical-host host (string->number port)))))]
|
|
|
|
#:multi
|
|
[("-o" "--option") key vals "Specify a single configuration option"
|
|
(actor #:name (list 'config-option key vals)
|
|
(assert (config (cons (string->symbol key)
|
|
(port->list read (open-input-string vals))))))]
|
|
[("-f" "--config-file") filename "Specify a configuration file to load"
|
|
(spawn-configuration filename)])
|
|
|
|
(actor #:name 'main
|
|
|
|
(during (config (list 'canonical-host $h $p))
|
|
(assert (canonical-local-host h p))
|
|
(assert (local-host h p)))
|
|
|
|
(define/query-set canonical-local-hosts ($ c (canonical-local-host _ _)) c)
|
|
(stop-when (rising-edge (> (set-count (canonical-local-hosts)) 1))
|
|
(log-error "Too many canonical-host records in configuration."))
|
|
(on-start (sleep 0.1)
|
|
(when (set-empty? (canonical-local-hosts))
|
|
(log-error "No canonical-host records specified; try the --canonical-host command line argument")))
|
|
;; TODO: Make the too-many-canonical-host-records situation recoverable.
|
|
;; TODO: And/or, make the whole application quit when it gets into a bad state.
|
|
|
|
(during (config (list 'accepted-host $h $p))
|
|
(assert (local-host h p)))
|
|
|
|
(during (local-host $host-name $port)
|
|
(assert (vh host-name port))))
|