]> gitweb.factorcode.org Git - factor.git/blob - extra/concurrency/distributed/distributed.factor
Initial import
[factor.git] / extra / concurrency / distributed / distributed.factor
1 ! Copyright (C) 2005 Chris Double. All Rights Reserved.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: serialize sequences concurrency io io.server qualified
4 threads arrays namespaces kernel ;
5 QUALIFIED: io.sockets
6 IN: concurrency.distributed
7
8 TUPLE: node hostname port ;
9
10 C: <node> node
11
12 : handle-node-client ( -- )
13     deserialize first2 get-process send ;
14
15 : node-server ( port -- )
16     internet-server
17     "concurrency"
18     [ handle-node-client ] with-server ;
19
20 : send-to-node ( msg pid  host port -- )
21     io.sockets:<inet> io.sockets:<client> [
22         2array serialize
23     ] with-stream ;
24
25 : localnode ( -- node )
26     \ localnode get ;
27
28 : start-node ( hostname port -- )
29     [ node-server ] in-thread
30     <node> \ localnode set-global ;
31
32 TUPLE: remote-process node pid ;
33
34 C: <remote-process> remote-process
35
36 M: remote-process send ( message process -- )
37     #! Send the message via the inter-node protocol
38     { remote-process-pid remote-process-node } get-slots
39     { node-hostname node-port } get-slots
40     send-to-node ;
41
42 M: process (serialize) ( obj -- )
43     localnode swap process-pid <remote-process> (serialize) ;