racketmq-2017/racketmq/hub/topic-demand.rkt

34 lines
1003 B
Racket

#lang syndicate/actor
(require racket/exn)
(require racket/set)
(require racket/string)
(require net/url)
(require/activate syndicate/drivers/web)
(require "../private/util.rkt")
(require "../protocol.rkt")
(actor #:name 'topic-demand-analyzer
(during/actor (topic-demand $full-topic _)
#:name (list 'topic-demand full-topic)
(define/query-value topic-baseurl #f (canonical-baseurl $b)
(canonical-url b `("topic" ("" ()))))
(define/dataflow state
(cond
[(not (topic-baseurl)) 'unknown]
[(string-prefix? full-topic (topic-baseurl)) 'local]
[else 'remote]))
(begin/dataflow
(log-info "Topic-demand for ~s is in state ~s." full-topic (state)))
(assert #:when (eq? (state) 'local)
(local-topic-demand (substring full-topic (string-length (topic-baseurl)))))
(assert #:when (eq? (state) 'remote)
(remote-topic-demand full-topic))))