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