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
11 : handle-node-client ( -- )
13 [ first2 get-process send ] [ stop-this-server ] if* ;
15 : <node-server> ( addrspec -- threaded-server )
16 binary <threaded-server>
18 "concurrency.distributed" >>name
19 [ handle-node-client ] >>handler ;
21 : (start-node) ( addrspec addrspec -- )
22 local-node set-global <node-server> start-server* ;
24 : start-node ( port -- )
25 host-name over <inet> (start-node) ;
27 TUPLE: remote-process id node ;
29 C: <remote-process> remote-process
31 : send-remote-message ( message node -- )
32 binary [ serialize ] with-client ;
34 M: remote-process send ( message thread -- )
35 [ id>> 2array ] [ node>> ] bi
38 M: thread (serialize) ( obj -- )
39 id>> local-node get-global <remote-process>
42 : stop-node ( node -- )
43 f swap send-remote-message ;