factor/extra/concurrency/distributed/distributed.factor

37 lines
1.0 KiB
Factor
Raw Normal View History

2007-09-20 18:09:08 -04:00
! Copyright (C) 2005 Chris Double. All Rights Reserved.
! See http://factorcode.org/license.txt for BSD license.
2008-02-18 06:07:40 -05:00
USING: serialize sequences concurrency.messaging
2008-02-18 08:30:16 -05:00
threads io io.server qualified arrays
namespaces kernel io.encodings.binary ;
2007-09-20 18:09:08 -04:00
QUALIFIED: io.sockets
IN: concurrency.distributed
2008-03-11 22:01:39 -04:00
SYMBOL: local-node
2008-02-18 10:08:59 -05:00
2007-09-20 18:09:08 -04:00
: handle-node-client ( -- )
2008-02-18 10:08:59 -05:00
deserialize first2 get-process send ;
2007-09-20 18:09:08 -04:00
2008-02-18 06:07:40 -05:00
: (start-node) ( addrspecs addrspec -- )
[
local-node set-global
"concurrency.distributed"
binary [ handle-node-client ] with-server
2008-02-18 06:07:40 -05:00
] 2curry f spawn drop ;
2007-09-20 18:09:08 -04:00
2008-02-18 06:07:40 -05:00
: start-node ( port -- )
2008-02-18 10:08:59 -05:00
dup internet-server io.sockets:host-name
rot io.sockets:<inet> (start-node) ;
TUPLE: remote-process id node ;
2007-09-20 18:09:08 -04:00
2008-02-18 10:08:59 -05:00
C: <remote-process> remote-process
2007-09-20 18:09:08 -04:00
2008-02-18 10:08:59 -05:00
M: remote-process send ( message thread -- )
{ remote-process-id remote-process-node } get-slots
2008-02-26 02:20:27 -05:00
binary io.sockets:<client> [ 2array serialize ] with-stream ;
2007-09-20 18:09:08 -04:00
2008-02-18 06:07:40 -05:00
M: thread (serialize) ( obj -- )
thread-id local-node get-global
2008-02-18 10:08:59 -05:00
<remote-process>
2008-02-18 06:07:40 -05:00
(serialize) ;