[Distributed Places] cleanup docs
This commit is contained in:
parent
033cdc1413
commit
823c091e8b
|
@ -11,9 +11,17 @@
|
|||
(provide main)
|
||||
|
||||
(define (main)
|
||||
(define remote-node (spawn-remote-racket-node "localhost" #:listen-port 6344))
|
||||
(define tuple-place (supervise-named-dynamic-place-at remote-node 'tuple-server tuple-path 'make-tuple-server))
|
||||
(define bank-place (supervise-dynamic-place-at remote-node bank-path 'make-bank))
|
||||
(define remote-node (spawn-remote-racket-node
|
||||
"localhost"
|
||||
#:listen-port 6344))
|
||||
(define tuple-place (supervise-named-dynamic-place-at
|
||||
remote-node
|
||||
'tuple-server
|
||||
tuple-path
|
||||
'make-tuple-server))
|
||||
(define bank-place (supervise-dynamic-place-at
|
||||
remote-node bank-path
|
||||
'make-bank))
|
||||
|
||||
(message-router
|
||||
remote-node
|
||||
|
@ -23,8 +31,10 @@
|
|||
(displayln (bank-removeM bank-place 'user0 5)))
|
||||
|
||||
(after-seconds 2
|
||||
(define c (connect-to-named-place remote-node 'tuple-server))
|
||||
(define d (connect-to-named-place remote-node 'tuple-server))
|
||||
(define c (connect-to-named-place remote-node
|
||||
'tuple-server))
|
||||
(define d (connect-to-named-place remote-node
|
||||
'tuple-server))
|
||||
(tuple-server-hello c)
|
||||
(tuple-server-hello d)
|
||||
(displayln (tuple-server-set c "user0" 100))
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
(call-with-input-file
|
||||
filename
|
||||
(lambda (i)
|
||||
(codeblock (port->string i)))))
|
||||
(codeblock0 (port->string i)))))
|
||||
|
||||
@(define-runtime-path master-path "../../racket/place/distributed/examples/named/master.rkt")
|
||||
@(define-runtime-path tuple-path "../../racket/place/distributed/examples/named/tuple.rkt")
|
||||
|
@ -30,7 +30,8 @@ The example code can also be found in
|
|||
@filepath{racket/distributed/examples/named/master.rkt}.
|
||||
|
||||
@figure["named-example-master" "examples/named/master.rkt"]{
|
||||
@codeblockfromfile[(path->string master-path)]}
|
||||
@codeblockfromfile[(path->string master-path)]
|
||||
}
|
||||
|
||||
The @racket[spawn-remote-racket-vm] primitive connects to
|
||||
@tt{"localhost"} and starts a racloud node there that listens on port
|
||||
|
@ -53,7 +54,8 @@ suitiable for invocation by @racket[supervise-named-place-thunk-at].
|
|||
|
||||
|
||||
@figure["named-example" "examples/named/tuple.rkt"]{
|
||||
@codeblockfromfile[(path->string tuple-path)]}
|
||||
@codeblockfromfile[(path->string tuple-path)]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -93,7 +95,7 @@ The @racket[define-rpc] form is similar to the @racket[define-rpc] form
|
|||
except there is no reply message from the server to client
|
||||
|
||||
@figure["define-named-remote-server-expansion" "Expansion of define-named-remote-server"]{
|
||||
@codeblock{
|
||||
@codeblock0{
|
||||
'(begin
|
||||
(require racket/place racket/match)
|
||||
(define/provide
|
||||
|
@ -118,7 +120,8 @@ except there is no reply message from the server to client
|
|||
(define (log-to-parent-real msg #:severity (severity 'info))
|
||||
(place-channel-put ch (log-message severity msg)))
|
||||
(syntax-parameterize
|
||||
((log-to-parent (make-rename-transformer #'log-to-parent-real)))
|
||||
((log-to-parent (make-rename-transformer
|
||||
#'log-to-parent-real)))
|
||||
(match
|
||||
msg
|
||||
((list (list 'set k v) src)
|
||||
|
@ -131,7 +134,9 @@ except there is no reply message from the server to client
|
|||
(loop))
|
||||
((list (list 'hello) src)
|
||||
(define result
|
||||
(let () (printf "Hello from define-cast\n") (flush-output)))
|
||||
(let ()
|
||||
(printf "Hello from define-cast\n")
|
||||
(flush-output)))
|
||||
(loop))))
|
||||
loop))))
|
||||
(void))
|
||||
|
|
|
@ -623,48 +623,52 @@ documented below.
|
|||
}
|
||||
|
||||
@examples[ #:eval evaler
|
||||
(define-named-remote-server
|
||||
tuple-server
|
||||
(module example1 racket
|
||||
(require racket/place/define-remote-server)
|
||||
(define-named-remote-server
|
||||
tuple-server
|
||||
|
||||
(define-state h (make-hash))
|
||||
(define-rpc (set k v)
|
||||
(hash-set! h k v)
|
||||
v)
|
||||
(define-rpc (get k)
|
||||
(hash-ref h k #f)))]
|
||||
(define-state h (make-hash))
|
||||
(define-rpc (set k v)
|
||||
(hash-set! h k v)
|
||||
v)
|
||||
(define-rpc (get k)
|
||||
(hash-ref h k #f))))]
|
||||
|
||||
@examples[ #:eval evaler
|
||||
(define-remote-server
|
||||
bank
|
||||
(module example2 racket
|
||||
(require racket/place/define-remote-server)
|
||||
(define-remote-server
|
||||
bank
|
||||
|
||||
(define-state accounts (make-hash))
|
||||
(define-rpc (new-account who)
|
||||
(match (hash-has-key? accounts who)
|
||||
[#t '(already-exists)]
|
||||
[else
|
||||
(hash-set! accounts who 0)
|
||||
(list 'created who)]))
|
||||
(define-rpc (removeM who amount)
|
||||
(cond
|
||||
[(hash-ref accounts who (lambda () #f)) =>
|
||||
(lambda (balance)
|
||||
(cond [(<= amount balance)
|
||||
(define new-balance (- balance amount))
|
||||
(hash-set! accounts who new-balance)
|
||||
(list 'ok new-balance)]
|
||||
[else
|
||||
(list 'insufficient-funds balance)]))]
|
||||
[else
|
||||
(list 'invalid-account who)]))
|
||||
(define-rpc (add who amount)
|
||||
(cond
|
||||
[(hash-ref accounts who (lambda () #f)) =>
|
||||
(lambda (balance)
|
||||
(define new-balance (+ balance amount))
|
||||
(hash-set! accounts who new-balance)
|
||||
(list 'ok new-balance))]
|
||||
[else
|
||||
(list 'invalid-account who)])))]
|
||||
(define-state accounts (make-hash))
|
||||
(define-rpc (new-account who)
|
||||
(match (hash-has-key? accounts who)
|
||||
[#t '(already-exists)]
|
||||
[else
|
||||
(hash-set! accounts who 0)
|
||||
(list 'created who)]))
|
||||
(define-rpc (removeM who amount)
|
||||
(cond
|
||||
[(hash-ref accounts who (lambda () #f)) =>
|
||||
(lambda (balance)
|
||||
(cond [(<= amount balance)
|
||||
(define new-balance (- balance amount))
|
||||
(hash-set! accounts who new-balance)
|
||||
(list 'ok new-balance)]
|
||||
[else
|
||||
(list 'insufficient-funds balance)]))]
|
||||
[else
|
||||
(list 'invalid-account who)]))
|
||||
(define-rpc (add who amount)
|
||||
(cond
|
||||
[(hash-ref accounts who (lambda () #f)) =>
|
||||
(lambda (balance)
|
||||
(define new-balance (+ balance amount))
|
||||
(hash-set! accounts who new-balance)
|
||||
(list 'ok new-balance))]
|
||||
[else
|
||||
(list 'invalid-account who)]))))]
|
||||
|
||||
@defthing[distributed-launch-path path?]{
|
||||
Contains the path to the distributed places launcher.
|
||||
|
@ -685,19 +689,7 @@ Returns the path to the currently executing racket binary on the local system.
|
|||
(racket-path)
|
||||
]}
|
||||
|
||||
@defform[(get-current-module-path)]{
|
||||
Returns the path to the current module.
|
||||
}
|
||||
@examples[ #:eval evaler
|
||||
(begin
|
||||
(module my-module racket/base
|
||||
(require racket/place/distributed)
|
||||
(get-current-module-path))
|
||||
(require 'my-module))
|
||||
]
|
||||
|
||||
@;{
|
||||
|
||||
@defproc[(->string) string?]{
|
||||
Coerces strings, numbers, symbols, and paths to a string.
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user