factor/extra/concurrency/distributed/distributed.factor

34 lines
965 B
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
concurrency.threads io io.server qualified arrays
namespaces kernel ;
2007-09-20 18:09:08 -04:00
QUALIFIED: io.sockets
IN: concurrency.distributed
: handle-node-client ( -- )
2008-02-18 06:07:40 -05:00
deserialize first2 thread 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"
[ handle-node-client ] with-server
] 2curry f spawn drop ;
2007-09-20 18:09:08 -04:00
2008-02-18 06:07:40 -05:00
SYMBOL: local-node ( -- addrspec )
2007-09-20 18:09:08 -04:00
2008-02-18 06:07:40 -05:00
: start-node ( port -- )
dup internet-server host-name rot <inet> (start-node) ;
2007-09-20 18:09:08 -04:00
2008-02-18 06:07:40 -05:00
TUPLE: remote-thread pid node ;
2007-09-20 18:09:08 -04:00
2008-02-18 06:07:40 -05:00
M: remote-thread send ( message thread -- )
{ remote-thread-pid remote-thread-node } get-slots
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
remote-thread construct-boa
(serialize) ;