Fix serializing of remote threads in concurrency.distributed
The commit f20ee7a53b
broke
serialization of remote threads and removed the local node
aspect of distributed messaging. This corrects that.
char-rename
parent
c1cdc2318f
commit
4c3714ac56
|
@ -1,6 +1,13 @@
|
||||||
USING: help.markup help.syntax concurrency.messaging threads ;
|
USING: help.markup help.syntax concurrency.messaging io.servers threads ;
|
||||||
IN: concurrency.distributed
|
IN: concurrency.distributed
|
||||||
|
|
||||||
|
HELP: local-node
|
||||||
|
{ $var-description "A variable containing the " { $link threaded-server } " the current node is running on." } ;
|
||||||
|
|
||||||
|
HELP: start-node
|
||||||
|
{ $values { "addrspec" "an addrspec to listen on" } }
|
||||||
|
{ $description "Starts a " { $link threaded-server } " for receiving messages from remote Factor instances." } ;
|
||||||
|
|
||||||
ARTICLE: "concurrency.distributed.example" "Distributed Concurrency Example"
|
ARTICLE: "concurrency.distributed.example" "Distributed Concurrency Example"
|
||||||
"In this example the Factor instance associated with port 9000 will run "
|
"In this example the Factor instance associated with port 9000 will run "
|
||||||
"a thread that receives and prints messages "
|
"a thread that receives and prints messages "
|
||||||
|
@ -11,7 +18,7 @@ ARTICLE: "concurrency.distributed.example" "Distributed Concurrency Example"
|
||||||
"[ log-message ] \"logger\" spawn dup name>> register-remote-thread"
|
"[ 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 "
|
||||||
"able to be accessed remotely using " { $link register-remote-thread } "."
|
"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 "
|
||||||
|
@ -38,7 +45,8 @@ $nl
|
||||||
|
|
||||||
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." $nl
|
"The " { $vocab-link "concurrency.distributed" } " implements transparent distributed message passing, inspired by Erlang and Termite." $nl
|
||||||
"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 local-node start-node }
|
||||||
|
"Instances of " { $link thread } " can be sent to remote nodes, at which point they are converted to objects holding the thread ID and the current node's addrspec:"
|
||||||
{ $subsections remote-thread }
|
{ $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" } ;
|
||||||
|
|
|
@ -22,6 +22,8 @@ PRIVATE>
|
||||||
: get-remote-thread ( name -- thread )
|
: get-remote-thread ( name -- thread )
|
||||||
dup registered-remote-threads at [ ] [ threads at ] ?if ;
|
dup registered-remote-threads at [ ] [ threads at ] ?if ;
|
||||||
|
|
||||||
|
SYMBOL: local-node
|
||||||
|
|
||||||
: handle-node-client ( -- )
|
: handle-node-client ( -- )
|
||||||
deserialize
|
deserialize
|
||||||
[ first2 get-remote-thread send ] [ stop-this-server ] if* ;
|
[ first2 get-remote-thread send ] [ stop-this-server ] if* ;
|
||||||
|
@ -32,6 +34,9 @@ PRIVATE>
|
||||||
"concurrency.distributed" >>name
|
"concurrency.distributed" >>name
|
||||||
[ handle-node-client ] >>handler ;
|
[ handle-node-client ] >>handler ;
|
||||||
|
|
||||||
|
: start-node ( addrspec -- )
|
||||||
|
<node-server> start-server local-node set-global ;
|
||||||
|
|
||||||
TUPLE: remote-thread node id ;
|
TUPLE: remote-thread node id ;
|
||||||
|
|
||||||
C: <remote-thread> remote-thread
|
C: <remote-thread> remote-thread
|
||||||
|
@ -44,10 +49,10 @@ M: remote-thread send ( message thread -- )
|
||||||
send-remote-message ;
|
send-remote-message ;
|
||||||
|
|
||||||
M: thread (serialize) ( obj -- )
|
M: thread (serialize) ( obj -- )
|
||||||
id>> [ insecure-addr ] dip <remote-thread> (serialize) ;
|
id>> [ local-node get insecure>> ] dip <remote-thread> (serialize) ;
|
||||||
|
|
||||||
: stop-node ( node -- )
|
: stop-node ( -- )
|
||||||
f swap send-remote-message ;
|
local-node get insecure>> f swap send-remote-message ;
|
||||||
|
|
||||||
[
|
[
|
||||||
H{ } clone \ registered-remote-threads set-global
|
H{ } clone \ registered-remote-threads set-global
|
||||||
|
|
Loading…
Reference in New Issue