Rename distributed process registry stuff to remote-thread

db4
Chris Double 2009-10-29 18:39:25 +13:00
parent 72ae46e72b
commit 536a4a3932
4 changed files with 30 additions and 31 deletions

View File

@ -28,7 +28,7 @@ MATCH-VARS: ?from ?tag ?id ?value ;
SYMBOL: no-channel SYMBOL: no-channel
: channel-process ( -- ) : channel-thread ( -- )
[ [
{ {
{ { to ?id ?value } { { to ?id ?value }
@ -41,10 +41,9 @@ SYMBOL: no-channel
PRIVATE> PRIVATE>
: start-channel-node ( -- ) : start-channel-node ( -- )
"remote-channels" get-process [ "remote-channels" get-remote-thread [
"remote-channels" [ channel-thread t ] "Remote channels" spawn-server
[ channel-process t ] "Remote channels" spawn-server "remote-channels" register-remote-thread
register-process
] unless ; ] unless ;
TUPLE: remote-channel node id ; TUPLE: remote-channel node id ;
@ -53,12 +52,12 @@ C: <remote-channel> remote-channel
M: remote-channel to ( value remote-channel -- ) M: remote-channel to ( value remote-channel -- )
[ [ \ to , id>> , , ] { } make ] keep [ [ \ to , id>> , , ] { } make ] keep
node>> "remote-channels" swap <remote-process> node>> "remote-channels" <remote-thread>
send-synchronous no-channel = [ no-channel throw ] when ; send-synchronous no-channel = [ no-channel throw ] when ;
M: remote-channel from ( remote-channel -- value ) M: remote-channel from ( remote-channel -- value )
[ [ \ from , id>> , ] { } make ] keep [ [ \ from , id>> , ] { } make ] keep
node>> "remote-channels" swap <remote-process> node>> "remote-channels" <remote-thread>
send-synchronous dup no-channel = [ no-channel throw ] when* ; send-synchronous dup no-channel = [ no-channel throw ] when* ;
[ [

View File

@ -21,23 +21,23 @@ $nl
{ $examples { $examples
{ $unchecked-example { $unchecked-example
": log-message ( -- ) receive . flush log-message ;" ": log-message ( -- ) receive . flush log-message ;"
"[ log-message ] \"logger\" spawn [ name>> ] keep register-process" "[ log-message ] \"logger\" spawn dup name>> register-remote-thread"
} }
} }
"This spawns a thread waits for the messages. It registers that thread as a " "This spawns a thread waits for the messages. It registers that thread as a "
"able to be accessed remotely using " { $link register-process } "." "able to be accessed remotely using " { $link register-remote-thread } "."
$nl $nl
"The second Factor instance, the one associated with port 9001, can send " "The second Factor instance, the one associated with port 9001, can send "
"messages to the 'logger' process by name:" "messages to the 'logger' thread by name:"
{ $examples { $examples
{ $unchecked-example { $unchecked-example
"USING: io.sockets concurrency.messaging concurrency.distributed ;" "USING: io.sockets concurrency.messaging concurrency.distributed ;"
"\"hello\" \"logger\" \"127.0.0.1\" 9000 <inet4> <remote-process> send" "\"hello\" \"127.0.0.1\" 9000 <inet4> \"logger\" <remote-thread> send"
} }
} }
"The " { $link send } " word is used to send messages to other threads. If an " "The " { $link send } " word is used to send messages to other threads. If an "
"instance of " { $link remote-process } " is provided instead of a thread then " "instance of " { $link remote-thread } " is provided instead of a thread then "
"the message is marshalled to the named process on the given machine using the " "the message is marshalled to the named thread on the given machine using the "
{ $vocab-link "serialize" } " vocabulary." { $vocab-link "serialize" } " vocabulary."
$nl $nl
"Running this code should show the message \"hello\" in the first Factor " "Running this code should show the message \"hello\" in the first Factor "
@ -45,15 +45,15 @@ $nl
$nl $nl
"It is also possible to use " { $link send-synchronous } " to receive a " "It is also possible to use " { $link send-synchronous } " to receive a "
"response to a distributed message. When an instance of " { $link thread } " " "response to a distributed message. When an instance of " { $link thread } " "
"is marshalled it is converted into an instance of " { $link remote-process } "is marshalled it is converted into an instance of " { $link remote-thread }
". The receiver of this can use it as the target of a " { $link send } ". The receiver of this can use it as the target of a " { $link send }
" or " { $link reply } " call." ; " or " { $link reply } " call." ;
ARTICLE: "concurrency.distributed" "Distributed message passing" ARTICLE: "concurrency.distributed" "Distributed message passing"
"The " { $vocab-link "concurrency.distributed" } " implements transparent distributed message passing, inspired by Erlang and Termite." "The " { $vocab-link "concurrency.distributed" } " implements transparent distributed message passing, inspired by Erlang and Termite."
{ $subsections start-node } { $subsections start-node }
"Instances of " { $link thread } " can be sent to remote processes, at which point they are converted to objects holding the thread ID and the current node's host name:" "Instances of " { $link thread } " can be sent to remote threads, at which point they are converted to objects holding the thread ID and the current node's host name:"
{ $subsections remote-process } { $subsections remote-thread }
"The " { $vocab-link "serialize" } " vocabulary is used to convert Factor objects to byte arrays for transfer over a socket." "The " { $vocab-link "serialize" } " vocabulary is used to convert Factor objects to byte arrays for transfer over a socket."
{ $subsections "concurrency.distributed.example" } ; { $subsections "concurrency.distributed.example" } ;

View File

@ -25,7 +25,7 @@ IN: concurrency.distributed.tests
[ 8 ] [ [ 8 ] [
5 self 2array 5 self 2array
"thread-a" test-node <remote-process> send test-node "thread-a" <remote-thread> send
receive receive
] unit-test ] unit-test

View File

@ -8,25 +8,25 @@ IN: concurrency.distributed
<PRIVATE <PRIVATE
: registered-processes ( -- hash ) : registered-remote-threads ( -- hash )
\ registered-processes get-global ; \ registered-remote-threads get-global ;
PRIVATE> PRIVATE>
: register-process ( name process -- ) : register-remote-thread ( thread name -- )
swap registered-processes set-at ; registered-remote-threads set-at ;
: unregister-process ( name -- ) : unregister-remote-thread ( name -- )
registered-processes delete-at ; registered-remote-threads delete-at ;
: get-process ( name -- process ) : get-remote-thread ( name -- thread )
dup registered-processes at [ ] [ thread ] ?if ; dup registered-remote-threads at [ ] [ thread ] ?if ;
SYMBOL: local-node SYMBOL: local-node
: handle-node-client ( -- ) : handle-node-client ( -- )
deserialize deserialize
[ first2 get-process send ] [ stop-this-server ] if* ; [ first2 get-remote-thread send ] [ stop-this-server ] if* ;
: <node-server> ( addrspec -- threaded-server ) : <node-server> ( addrspec -- threaded-server )
binary <threaded-server> binary <threaded-server>
@ -40,26 +40,26 @@ SYMBOL: local-node
: start-node ( port -- ) : start-node ( port -- )
host-name over <inet> (start-node) ; host-name over <inet> (start-node) ;
TUPLE: remote-process id node ; TUPLE: remote-thread node id ;
C: <remote-process> remote-process C: <remote-thread> remote-thread
: send-remote-message ( message node -- ) : send-remote-message ( message node -- )
binary [ serialize ] with-client ; binary [ serialize ] with-client ;
M: remote-process send ( message thread -- ) M: remote-thread send ( message thread -- )
[ id>> 2array ] [ node>> ] bi [ id>> 2array ] [ node>> ] bi
send-remote-message ; send-remote-message ;
M: thread (serialize) ( obj -- ) M: thread (serialize) ( obj -- )
id>> local-node get-global <remote-process> id>> [ local-node get-global ] dip <remote-thread>
(serialize) ; (serialize) ;
: stop-node ( node -- ) : stop-node ( node -- )
f swap send-remote-message ; f swap send-remote-message ;
[ [
H{ } clone \ registered-processes set-global H{ } clone \ registered-remote-threads set-global
] "remote-thread-registry" add-init-hook ] "remote-thread-registry" add-init-hook