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
11 : handle-node-client ( -- )
13 [ first2 get-process send ] [ stop-this-server ] if* ;
15 : <node-server> ( addrspec -- threaded-server )
19 "concurrency.distributed" >>name
20 [ handle-node-client ] >>handler ;
22 : (start-node) ( addrspec addrspec -- )
23 local-node set-global <node-server> start-server* ;
25 : start-node ( port -- )
26 host-name over <inet> (start-node) ;
28 TUPLE: remote-process id node ;
30 C: <remote-process> remote-process
32 : send-remote-message ( message node -- )
33 binary [ serialize ] with-client ;
35 M: remote-process send ( message thread -- )
36 [ id>> 2array ] [ node>> ] bi
39 M: thread (serialize) ( obj -- )
40 id>> local-node get-global <remote-process>
43 : stop-node ( node -- )
44 f swap send-remote-message ;