-USING: help.markup help.syntax concurrency.messaging threads ;
+USING: help.markup help.syntax concurrency.messaging io.servers threads ;
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"
"In this example the Factor instance associated with port 9000 will run "
"a thread that receives and prints messages "
"[ 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 } "."
$nl
"The second Factor instance, the one associated with port 9001, can send "
ARTICLE: "concurrency.distributed" "Distributed message passing"
"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 }
"The " { $vocab-link "serialize" } " vocabulary is used to convert Factor objects to byte arrays for transfer over a socket."
{ $subsections "concurrency.distributed.example" } ;
: get-remote-thread ( name -- thread )
dup registered-remote-threads at [ ] [ threads at ] ?if ;
+SYMBOL: local-node
+
: handle-node-client ( -- )
deserialize
[ first2 get-remote-thread send ] [ stop-this-server ] if* ;
"concurrency.distributed" >>name
[ handle-node-client ] >>handler ;
+: start-node ( addrspec -- )
+ <node-server> start-server local-node set-global ;
+
TUPLE: remote-thread node id ;
C: <remote-thread> remote-thread
send-remote-message ;
M: thread (serialize) ( obj -- )
- id>> [ insecure-addr ] dip <remote-thread> (serialize) ;
+ id>> [ local-node get insecure>> ] dip <remote-thread> (serialize) ;
-: stop-node ( node -- )
- f swap send-remote-message ;
+: stop-node ( -- )
+ local-node get insecure>> f swap send-remote-message ;
[
H{ } clone \ registered-remote-threads set-global