1 USING: help.markup help.syntax concurrency.messaging threads ;
2 IN: concurrency.distributed
4 ARTICLE: "concurrency.distributed.example" "Distributed Concurrency Example"
5 "In this example the Factor instance associated with port 9000 will run "
6 "a thread that receives and prints messages "
7 "in the listener. The code to start the thread is: "
10 ": log-message ( -- ) receive . flush log-message ;"
11 "[ log-message ] \"logger\" spawn dup name>> register-remote-thread"
14 "This spawns a thread waits for the messages. It registers that thread as a "
15 "able to be accessed remotely using " { $link register-remote-thread } "."
17 "The second Factor instance, the one associated with port 9001, can send "
18 "messages to the 'logger' thread by name:"
21 "USING: io.sockets concurrency.messaging concurrency.distributed ;"
22 "\"hello\" \"127.0.0.1\" 9000 <inet4> \"logger\" <remote-thread> send"
25 "The " { $link send } " word is used to send messages to other threads. If an "
26 "instance of " { $link remote-thread } " is provided instead of a thread then "
27 "the message is marshalled to the named thread on the given machine using the "
28 { $vocab-link "serialize" } " vocabulary."
30 "Running this code should show the message \"hello\" in the first Factor "
33 "It is also possible to use " { $link send-synchronous } " to receive a "
34 "response to a distributed message. When an instance of " { $link thread } " "
35 "is marshalled it is converted into an instance of " { $link remote-thread }
36 ". The receiver of this can use it as the target of a " { $link send }
37 " or " { $link reply } " call." ;
39 ARTICLE: "concurrency.distributed" "Distributed message passing"
40 "The " { $vocab-link "concurrency.distributed" } " implements transparent distributed message passing, inspired by Erlang and Termite." $nl
41 "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:"
42 { $subsections remote-thread }
43 "The " { $vocab-link "serialize" } " vocabulary is used to convert Factor objects to byte arrays for transfer over a socket."
44 { $subsections "concurrency.distributed.example" } ;
46 ABOUT: "concurrency.distributed"