Moving config:scripts back inside the adt barrier

svn: r12348
This commit is contained in:
Jay McCarthy 2008-11-07 23:22:11 +00:00
parent c1a10edaff
commit 8a91afa69d
8 changed files with 68 additions and 80 deletions

View File

@ -17,7 +17,6 @@
(define (mkd p) (define (mkd p)
(define-values (! u->s) (define-values (! u->s)
(servlets:make-cached-url->servlet (servlets:make-cached-url->servlet
(box (make-cache-table))
(lambda _ (values p url0s)) (lambda _ (values p url0s))
(servlets:make-default-path->servlet))) (servlets:make-default-path->servlet)))
(define d (define d

View File

@ -107,19 +107,18 @@
(provide/contract (provide/contract
[url->servlet/c contract?] [url->servlet/c contract?]
[make-cached-url->servlet [make-cached-url->servlet
(-> (box/c cache-table?) (-> url->path/c
url->path/c
path->servlet/c path->servlet/c
(values (-> void) (values (-> void)
url->servlet/c))]) url->servlet/c))])
(define (make-cached-url->servlet (define (make-cached-url->servlet
config:scripts
url->path url->path
path->servlet) path->servlet)
(define config:scripts (make-cache-table))
(values (lambda () (values (lambda ()
;; This is broken - only out of date or specifically mentioned scripts should be flushed. This destroys persistent state! ;; This is broken - only out of date or specifically mentioned scripts should be flushed. This destroys persistent state!
(cache-table-clear! (unbox config:scripts))) (cache-table-clear! config:scripts))
(lambda (uri) (lambda (uri)
(define-values (servlet-path _) (define-values (servlet-path _)
(with-handlers (with-handlers
@ -128,7 +127,7 @@
(exn-message e) (exn-message e)
(exn-continuation-marks e))))]) (exn-continuation-marks e))))])
(url->path uri))) (url->path uri)))
(cache-table-lookup! (unbox config:scripts) (cache-table-lookup! config:scripts
(string->symbol (path->string servlet-path)) (string->symbol (path->string servlet-path))
(lambda () (path->servlet servlet-path)))))) (lambda () (path->servlet servlet-path))))))

View File

@ -372,14 +372,13 @@ Equivalent to @scheme[(path? . -> . servlet?)].
@defthing[url->servlet/c contract?]{Equivalent to @scheme[(url? . -> . servlet?)]} @defthing[url->servlet/c contract?]{Equivalent to @scheme[(url? . -> . servlet?)]}
@defproc[(make-cached-url->servlet @defproc[(make-cached-url->servlet
[config:scripts (box/c cache-table?)]
[url->path url->path/c] [url->path url->path/c]
[path->serlvet path->servlet/c]) [path->serlvet path->servlet/c])
(values (-> void) (values (-> void)
url->servlet/c)]{ url->servlet/c)]{
The first return value flushes the cache. The first return value flushes the cache.
The second is a procedure that uses @scheme[url->path] to resolve the URL to a path, then uses @scheme[path->servlet] to resolve The second is a procedure that uses @scheme[url->path] to resolve the URL to a path, then uses @scheme[path->servlet] to resolve
that path to a servlet, caching the results in @scheme[config:scripts]. that path to a servlet, caching the results in an internal table.
} }
@defproc[(make [url->servlet url->servlet/c] @defproc[(make [url->servlet url->servlet/c]

View File

@ -25,10 +25,6 @@ Provides contains the following identifiers.
Contains the configuration of individual virtual hosts. Contains the configuration of individual virtual hosts.
} }
@defthing[scripts (box/c (cache-table? path? servlet?))]{
Contains initially loaded servlets.
}
@defthing[initial-connection-timeout integer?]{ @defthing[initial-connection-timeout integer?]{
Specifies the initial timeout given to a connection. Specifies the initial timeout given to a connection.
} }

View File

@ -94,21 +94,20 @@
[file-not-found-path (build-path server-root-path "conf" "not-found.html")] [file-not-found-path (build-path server-root-path "conf" "not-found.html")]
#:mime-types-path #:mime-types-path
[mime-types-path (build-path server-root-path "mime.types")]) [mime-types-path (build-path server-root-path "mime.types")])
(let*-values (define standalone-url
([(standalone-url) (format "http://localhost:~a~a" the-port servlet-path))
(format "http://localhost:~a~a" the-port servlet-path)] (define make-servlet-namespace
[(make-servlet-namespace) (make-make-servlet-namespace (make-make-servlet-namespace
#:to-be-copied-module-specs servlet-namespace)] #:to-be-copied-module-specs servlet-namespace))
[(the-scripts) (make-cache-table)] (define sema (make-semaphore 0))
[(sema) (make-semaphore 0)] (define servlet
[(servlet)
(parameterize ([current-custodian (make-custodian)] (parameterize ([current-custodian (make-custodian)]
[current-namespace [current-namespace
(make-servlet-namespace (make-servlet-namespace
#:additional-specs #:additional-specs
servlets:default-module-specs)]) servlets:default-module-specs)])
(servlets:make-v2.servlet servlet-current-directory manager start))] (servlets:make-v2.servlet servlet-current-directory manager start)))
[(dispatcher) (define dispatcher
(sequencer:make (sequencer:make
(if quit? (if quit?
(filter:make (filter:make
@ -120,7 +119,6 @@
(servlets:make (lambda (url) servlet))) (servlets:make (lambda (url) servlet)))
(let-values ([(clear-cache! url->servlet) (let-values ([(clear-cache! url->servlet)
(servlets:make-cached-url->servlet (servlets:make-cached-url->servlet
(box the-scripts)
(fsmap:filter-url->path (fsmap:filter-url->path
#rx"\\.(ss|scm)$" #rx"\\.(ss|scm)$"
(fsmap:make-url->valid-path (fsmap:make-url->valid-path
@ -141,11 +139,11 @@
(build-path server-root-path "htdocs")) (build-path server-root-path "htdocs"))
#:path->mime-type (make-path->mime-type (build-path server-root-path "mime.types")) #:path->mime-type (make-path->mime-type (build-path server-root-path "mime.types"))
#:indices (list "index.html" "index.htm")) #:indices (list "index.html" "index.htm"))
(lift:make (gen-file-not-found-responder file-not-found-path)))] (lift:make (gen-file-not-found-responder file-not-found-path))))
[(shutdown-server) (define shutdown-server
(serve #:dispatch dispatcher (serve #:dispatch dispatcher
#:listen-ip listen-ip #:listen-ip listen-ip
#:port the-port)]) #:port the-port))
(when launch-browser? (when launch-browser?
((send-url) standalone-url #t)) ((send-url) standalone-url #t))
(printf "Your Web application is running at ~a.~n" standalone-url) (printf "Your Web application is running at ~a.~n" standalone-url)
@ -157,4 +155,4 @@
(shutdown-server))]) (shutdown-server))])
(semaphore-wait/enable-break sema)) (semaphore-wait/enable-break sema))
; We shouldn't get here, because nothing posts to the semaphore. But just in case... ; We shouldn't get here, because nothing posts to the semaphore. But just in case...
(shutdown-server))) (shutdown-server))

View File

@ -2,7 +2,6 @@
max-waiting max-waiting
virtual-hosts virtual-hosts
scripts
initial-connection-timeout initial-connection-timeout
port port
listen-ip listen-ip

View File

@ -88,7 +88,6 @@
(define listen-ip the-listen-ip) (define listen-ip the-listen-ip)
(define initial-connection-timeout (configuration-table-initial-connection-timeout table)) (define initial-connection-timeout (configuration-table-initial-connection-timeout table))
(define virtual-hosts the-virtual-hosts) (define virtual-hosts the-virtual-hosts)
(define scripts (box (make-cache-table)))
(define make-servlet-namespace the-make-servlet-namespace))) (define make-servlet-namespace the-make-servlet-namespace)))
; apply-default-functions-to-host-table : str host-table -> host ; apply-default-functions-to-host-table : str host-table -> host

View File

@ -77,7 +77,6 @@
((responders-collect-garbage (host-responders host-info))))) ((responders-collect-garbage (host-responders host-info)))))
(let-values ([(clear-cache! url->servlet) (let-values ([(clear-cache! url->servlet)
(servlets:make-cached-url->servlet (servlets:make-cached-url->servlet
config:scripts
(fsmap:filter-url->path (fsmap:filter-url->path
#rx"\\.(ss|scm)$" #rx"\\.(ss|scm)$"
(fsmap:make-url->valid-path (fsmap:make-url->valid-path