]> gitweb.factorcode.org Git - factor.git/blob - basis/concurrency/distributed/distributed.factor
Merge branch 'master' into global_optimization
[factor.git] / basis / 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.messaging threads io
4 io.servers.connection io.encodings.binary
5 arrays namespaces kernel accessors ;
6 FROM: io.sockets => host-name <inet> with-client ;
7 IN: concurrency.distributed
8
9 SYMBOL: local-node
10
11 : handle-node-client ( -- )
12     deserialize
13     [ first2 get-process send ] [ stop-this-server ] if* ;
14
15 : <node-server> ( addrspec -- threaded-server )
16     binary <threaded-server>
17         swap >>insecure
18         "concurrency.distributed" >>name
19         [ handle-node-client ] >>handler ;
20
21 : (start-node) ( addrspec addrspec -- )
22     local-node set-global <node-server> start-server* ;
23
24 : start-node ( port -- )
25     host-name over <inet> (start-node) ;
26
27 TUPLE: remote-process id node ;
28
29 C: <remote-process> remote-process
30
31 : send-remote-message ( message node -- )
32     binary [ serialize ] with-client ;
33
34 M: remote-process send ( message thread -- )
35     [ id>> 2array ] [ node>> ] bi
36     send-remote-message ;
37
38 M: thread (serialize) ( obj -- )
39     id>> local-node get-global <remote-process>
40     (serialize) ;
41
42 : stop-node ( node -- )
43     f swap send-remote-message ;