]> gitweb.factorcode.org Git - factor.git/commitdiff
Fix serializing of remote threads in concurrency.distributed
authorChris Double <chris.double@double.co.nz>
Thu, 10 Nov 2016 09:23:41 +0000 (22:23 +1300)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 11 Nov 2016 01:38:59 +0000 (17:38 -0800)
The commit f20ee7a53b264fda515d2a55c8fbea26261de016 broke
serialization of remote threads and removed the local node
aspect of distributed messaging. This corrects that.

basis/concurrency/distributed/distributed-docs.factor
basis/concurrency/distributed/distributed.factor

index 19cfef88723975ea504b2f6605efea283f60f847..b329d6b1f92e345f07b5c44f805a12ce04c2ed4b 100644 (file)
@@ -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 "
+"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" } ;
index 153f0c9ad63a6dd997bd5c0058dcfe65e3f8d77a..92330bc64404ec126820eff40ea85e6ed27cbe56 100644 (file)
@@ -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 -- )
+    <node-server> start-server local-node set-global ;
+
 TUPLE: remote-thread node id ;
 
 C: <remote-thread> remote-thread
@@ -44,10 +49,10 @@ M: remote-thread send ( message 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