not using message passing threads for modules
parent
1145f49a47
commit
a7ff4c7884
|
@ -2,4 +2,4 @@ USING: help.syntax help.markup modules.rpc-server modules.using ;
|
||||||
IN: modules.rpc-server
|
IN: modules.rpc-server
|
||||||
HELP: service
|
HELP: service
|
||||||
{ $syntax "IN: my-vocab service" }
|
{ $syntax "IN: my-vocab service" }
|
||||||
{ $description "Allows words defined in the vocabulary to be used as remote procedure calls by " { $link POSTPONE: USING*: } } ;
|
{ $description "Allows words defined in the vocabulary to be used as remote procedure calls by " { $link POSTPONE: USING*: } ;
|
|
@ -1,35 +1,31 @@
|
||||||
! Copyright (C) 2009 Sam Anklesaria.
|
! Copyright (C) 2009 Sam Anklesaria.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors assocs concurrency.distributed
|
USING: accessors assocs combinators continuations effects
|
||||||
concurrency.messaging continuations effects init kernel
|
io.encodings.binary io.servers.connection kernel namespaces
|
||||||
namespaces sequences sets threads vocabs vocabs.parser ;
|
sequences serialize sets threads vocabs vocabs.parser init ;
|
||||||
IN: modules.rpc-server
|
IN: modules.rpc-server
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
TUPLE: rpc-request args vocabspec wordname ;
|
TUPLE: rpc-request args vocabspec wordname ;
|
||||||
SYMBOL: serving-vocabs serving-vocabs [ V{ } clone ] initialize
|
SYMBOL: serving-vocabs serving-vocabs [ V{ } clone ] initialize
|
||||||
|
|
||||||
: register-gets-thread ( -- )
|
: getter ( -- ) deserialize dup serving-vocabs get-global index
|
||||||
[ receive [ data>> dup serving-vocabs get-global index
|
|
||||||
[ vocab-words [ stack-effect ] { } assoc-map-as ]
|
[ vocab-words [ stack-effect ] { } assoc-map-as ]
|
||||||
[ \ no-vocab boa ] if
|
[ \ no-vocab boa ] if serialize ;
|
||||||
] keep reply-synchronous
|
|
||||||
t ] "get-words" spawn-server "gets-thread" swap register-process ;
|
|
||||||
|
|
||||||
: register-does-thread ( -- )
|
: doer ( -- ) deserialize dup vocabspec>> serving-vocabs get-global index
|
||||||
[ receive [ data>> dup vocabspec>> serving-vocabs get-global index
|
|
||||||
[ [ args>> ] [ wordname>> ] [ vocabspec>> vocab-words ] tri at [ execute ] curry with-datastack ]
|
[ [ args>> ] [ wordname>> ] [ vocabspec>> vocab-words ] tri at [ execute ] curry with-datastack ]
|
||||||
[ vocabspec>> \ no-vocab boa ] if
|
[ vocabspec>> \ no-vocab boa ] if serialize ;
|
||||||
] keep reply-synchronous
|
|
||||||
t ] "do-word" spawn-server "does-thread" swap register-process ;
|
|
||||||
|
|
||||||
: register-loads-thread ( -- )
|
|
||||||
[ [ receive vocab ] keep reply-synchronous t ] "load-words" spawn-server "loads-thread" swap register-process ;
|
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
SYNTAX: service current-vocab name>> serving-vocabs get-global adjoin ;
|
SYNTAX: service current-vocab name>> serving-vocabs get-global adjoin ;
|
||||||
|
|
||||||
[ 9012 start-node
|
[ [ binary <threaded-server>
|
||||||
register-gets-thread
|
"rpcs" >>name 9012 >>insecure
|
||||||
register-does-thread
|
[ break deserialize {
|
||||||
register-loads-thread
|
{ [ "getter" ] [ getter ] }
|
||||||
|
{ [ "doer" ] [ doer ] }
|
||||||
|
{ [ "loader" ] [ deserialize vocab serialize ] }
|
||||||
|
} case ] >>handler
|
||||||
|
start-server ] in-thread drop
|
||||||
] "modules.rpc-server" add-init-hook
|
] "modules.rpc-server" add-init-hook
|
|
@ -1,24 +1,27 @@
|
||||||
! Copyright (C) 2009 Sam Anklesaria.
|
! Copyright (C) 2009 Sam Anklesaria.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors assocs concurrency.distributed
|
USING: accessors assocs fry generalizations io.encodings.binary
|
||||||
concurrency.messaging fry generalizations io.sockets kernel
|
io.sockets kernel locals namespaces parser sequences serialize
|
||||||
locals namespaces parser sequences vocabs vocabs.parser words ;
|
vocabs vocabs.parser words tools.continuations io ;
|
||||||
IN: modules.rpc
|
IN: modules.rpc
|
||||||
|
|
||||||
TUPLE: rpc-request args vocabspec wordname ;
|
TUPLE: rpc-request args vocabspec wordname ;
|
||||||
|
|
||||||
: send-with-check ( message thread -- reply/* ) send-synchronous dup no-vocab? [ throw ] when ;
|
: send-with-check ( message -- reply/* )
|
||||||
|
serialize flush deserialize dup no-vocab? [ throw ] when ;
|
||||||
|
|
||||||
:: define-remote ( str effect addrspec vocabspec -- )
|
:: define-remote ( str effect addrspec vocabspec -- )
|
||||||
str create-in effect [ in>> length ] [ out>> length ] bi
|
str create-in effect [ in>> length ] [ out>> length ] bi
|
||||||
'[ _ narray vocabspec str rpc-request boa "does-thread" addrspec 9012 <inet> <remote-process> send-with-check _ firstn ]
|
'[ _ narray vocabspec str rpc-request boa addrspec 9012 <inet> binary
|
||||||
|
[ "doer" serialize serialize send-with-check ] with-client _ firstn ]
|
||||||
effect define-declared ;
|
effect define-declared ;
|
||||||
|
|
||||||
:: remote-vocab ( addrspec vocabspec -- vocab )
|
:: remote-vocab ( addrspec vocabspec -- vocab )
|
||||||
vocabspec "-remote" append dup vocab [ dup set-current-vocab
|
vocabspec "-remote" append dup vocab [ dup set-current-vocab
|
||||||
vocabspec "gets-thread" addrspec 9012 <inet> <remote-process> send-with-check
|
vocabspec addrspec 9012 <inet> binary [ "getter" serialize send-with-check ] with-client
|
||||||
[ first2 addrspec vocabspec define-remote ] each
|
[ first2 addrspec vocabspec define-remote ] each
|
||||||
] unless ;
|
] unless ;
|
||||||
|
|
||||||
: remote-load ( addr vocabspec -- voabspec ) [ swap
|
: remote-load ( addr vocabspec -- voabspec ) [ swap
|
||||||
"loads-thread" swap 9012 <inet> <remote-process> send-synchronous ] keep [ dictionary get-global set-at ] keep ;
|
9012 <inet> binary [ "loader" serialize serialize flush deserialize ] with-client ] keep
|
||||||
|
[ dictionary get-global set-at ] keep ;
|
|
@ -8,5 +8,4 @@ ABOUT: { "modules.using" "use" }
|
||||||
|
|
||||||
HELP: USING*:
|
HELP: USING*:
|
||||||
{ $syntax "USING: rpc-server::module fetch-sever:module { module qualified-name } { module => word ... } { qualified-module } { module EXCEPT word ... } { module word => importname } ;" }
|
{ $syntax "USING: rpc-server::module fetch-sever:module { module qualified-name } { module => word ... } { qualified-module } { module EXCEPT word ... } { module word => importname } ;" }
|
||||||
{ $description "Adds vocabularies to the search path. Vocabularies can be loaded off a server or called as an rpc if preceded by a valid hostname. Bracketed pairs facilitate all types of qualified imports on both remote and local modules." }
|
{ $description "Adds vocabularies to the search path. Vocabularies can be loaded off a server or called as an rpc if preceded by a valid hostname. Bracketed pairs facilitate all types of qualified imports on both remote and local modules." } ;
|
||||||
"To use the 'USING*:' without explicitly importing modules.using first, add '\"modules.using\" require' to your .factor-boot-rc" ;
|
|
Loading…
Reference in New Issue