]> gitweb.factorcode.org Git - factor.git/blob - basis/concurrency/distributed/distributed.factor
Fix permission bits
[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 qualified 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     <threaded-server>
17         swap >>insecure
18         binary >>encoding
19         "concurrency.distributed" >>name
20         [ handle-node-client ] >>handler ;
21
22 : (start-node) ( addrspec addrspec -- )
23     local-node set-global <node-server> start-server* ;
24
25 : start-node ( port -- )
26     host-name over <inet> (start-node) ;
27
28 TUPLE: remote-process id node ;
29
30 C: <remote-process> remote-process
31
32 : send-remote-message ( message node -- )
33     binary [ serialize ] with-client ;
34
35 M: remote-process send ( message thread -- )
36     [ id>> 2array ] [ node>> ] bi
37     send-remote-message ;
38
39 M: thread (serialize) ( obj -- )
40     id>> local-node get-global <remote-process>
41     (serialize) ;
42
43 : stop-node ( node -- )
44     f swap send-remote-message ;