diff --git a/basis/concurrency/distributed/distributed-docs.factor b/basis/concurrency/distributed/distributed-docs.factor index 19cfef8872..b329d6b1f9 100644 --- a/basis/concurrency/distributed/distributed-docs.factor +++ b/basis/concurrency/distributed/distributed-docs.factor @@ -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 +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 " @@ -11,7 +18,7 @@ ARTICLE: "concurrency.distributed.example" "Distributed Concurrency Example" "[ 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 " @@ -38,7 +45,8 @@ $nl 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" } ; diff --git a/basis/concurrency/distributed/distributed.factor b/basis/concurrency/distributed/distributed.factor index 153f0c9ad6..92330bc644 100644 --- a/basis/concurrency/distributed/distributed.factor +++ b/basis/concurrency/distributed/distributed.factor @@ -22,6 +22,8 @@ PRIVATE> : 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* ; @@ -32,6 +34,9 @@ PRIVATE> "concurrency.distributed" >>name [ handle-node-client ] >>handler ; +: start-node ( addrspec -- ) + start-server local-node set-global ; + TUPLE: remote-thread node id ; C: remote-thread @@ -44,10 +49,10 @@ M: remote-thread send ( message thread -- ) send-remote-message ; M: thread (serialize) ( obj -- ) - id>> [ insecure-addr ] dip (serialize) ; + id>> [ local-node get insecure>> ] dip (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