not using message passing threads for modules

db4
Sam Anklesaria 2009-08-03 22:29:02 -05:00
parent 1145f49a47
commit a7ff4c7884
4 changed files with 28 additions and 30 deletions

View File

@ -2,4 +2,4 @@ USING: help.syntax help.markup modules.rpc-server modules.using ;
IN: modules.rpc-server
HELP: 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*: } ;

View File

@ -1,35 +1,31 @@
! Copyright (C) 2009 Sam Anklesaria.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs concurrency.distributed
concurrency.messaging continuations effects init kernel
namespaces sequences sets threads vocabs vocabs.parser ;
USING: accessors assocs combinators continuations effects
io.encodings.binary io.servers.connection kernel namespaces
sequences serialize sets threads vocabs vocabs.parser init ;
IN: modules.rpc-server
<PRIVATE
TUPLE: rpc-request args vocabspec wordname ;
SYMBOL: serving-vocabs serving-vocabs [ V{ } clone ] initialize
: register-gets-thread ( -- )
[ receive [ data>> dup serving-vocabs get-global index
: getter ( -- ) deserialize dup serving-vocabs get-global index
[ vocab-words [ stack-effect ] { } assoc-map-as ]
[ \ no-vocab boa ] if
] keep reply-synchronous
t ] "get-words" spawn-server "gets-thread" swap register-process ;
[ \ no-vocab boa ] if serialize ;
: register-does-thread ( -- )
[ receive [ data>> dup vocabspec>> serving-vocabs get-global index
: doer ( -- ) deserialize dup vocabspec>> serving-vocabs get-global index
[ [ args>> ] [ wordname>> ] [ vocabspec>> vocab-words ] tri at [ execute ] curry with-datastack ]
[ vocabspec>> \ no-vocab boa ] if
] 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 ;
[ vocabspec>> \ no-vocab boa ] if serialize ;
PRIVATE>
SYNTAX: service current-vocab name>> serving-vocabs get-global adjoin ;
[ 9012 start-node
register-gets-thread
register-does-thread
register-loads-thread
[ [ binary <threaded-server>
"rpcs" >>name 9012 >>insecure
[ break deserialize {
{ [ "getter" ] [ getter ] }
{ [ "doer" ] [ doer ] }
{ [ "loader" ] [ deserialize vocab serialize ] }
} case ] >>handler
start-server ] in-thread drop
] "modules.rpc-server" add-init-hook

View File

@ -1,24 +1,27 @@
! Copyright (C) 2009 Sam Anklesaria.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs concurrency.distributed
concurrency.messaging fry generalizations io.sockets kernel
locals namespaces parser sequences vocabs vocabs.parser words ;
USING: accessors assocs fry generalizations io.encodings.binary
io.sockets kernel locals namespaces parser sequences serialize
vocabs vocabs.parser words tools.continuations io ;
IN: modules.rpc
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 -- )
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 ;
:: remote-vocab ( addrspec vocabspec -- 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
] unless ;
: 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 ;

View File

@ -8,5 +8,4 @@ ABOUT: { "modules.using" "use" }
HELP: USING*:
{ $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." }
"To use the 'USING*:' without explicitly importing modules.using first, add '\"modules.using\" require' to your .factor-boot-rc" ;
{ $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." } ;