| 
									
										
										
										
											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-03-29 00:00:20 -04:00
										 |  |  | USING: serialize sequences concurrency.messaging threads io | 
					
						
							|  |  |  | io.server qualified arrays namespaces kernel io.encodings.binary | 
					
						
							| 
									
										
										
										
											2008-03-20 16:30:59 -04:00
										 |  |  | accessors ;
 | 
					
						
							| 
									
										
										
										
											2008-05-05 03:19:25 -04:00
										 |  |  | FROM: io.sockets => host-name <inet> with-client ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 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-03-11 23:42:32 -04:00
										 |  |  |     deserialize | 
					
						
							|  |  |  |     [ first2 get-process send ] | 
					
						
							|  |  |  |     [ stop-server ] if* ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-18 06:07:40 -05:00
										 |  |  | : (start-node) ( addrspecs addrspec -- )
 | 
					
						
							| 
									
										
										
										
											2008-03-11 23:42:32 -04:00
										 |  |  |     local-node set-global
 | 
					
						
							| 
									
										
										
										
											2008-02-18 06:07:40 -05:00
										 |  |  |     [ | 
					
						
							|  |  |  |         "concurrency.distributed" | 
					
						
							| 
									
										
										
										
											2008-03-11 23:42:32 -04:00
										 |  |  |         binary | 
					
						
							|  |  |  |         [ handle-node-client ] with-server | 
					
						
							|  |  |  |     ] curry "Distributed concurrency server" spawn drop ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-18 06:07:40 -05:00
										 |  |  | : start-node ( port -- )
 | 
					
						
							| 
									
										
										
										
											2008-03-11 23:42:32 -04:00
										 |  |  |     [ internet-server ] | 
					
						
							| 
									
										
										
										
											2008-05-05 03:19:25 -04:00
										 |  |  |     [ host-name swap <inet> ] bi
 | 
					
						
							| 
									
										
										
										
											2008-03-11 23:42:32 -04:00
										 |  |  |     (start-node) ;
 | 
					
						
							| 
									
										
										
										
											2008-02-18 10:08:59 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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-03-11 23:42:32 -04:00
										 |  |  | : send-remote-message ( message node -- )
 | 
					
						
							| 
									
										
										
										
											2008-05-05 03:19:25 -04:00
										 |  |  |     binary [ serialize ] with-client ;
 | 
					
						
							| 
									
										
										
										
											2008-03-11 23:42:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-18 10:08:59 -05:00
										 |  |  | M: remote-process send ( message thread -- )
 | 
					
						
							| 
									
										
										
										
											2008-03-11 23:42:32 -04:00
										 |  |  |     [ id>> 2array ] [ node>> ] bi
 | 
					
						
							|  |  |  |     send-remote-message ;
 | 
					
						
							| 
									
										
										
										
											2007-09-20 18:09:08 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-18 06:07:40 -05:00
										 |  |  | M: thread (serialize) ( obj -- )
 | 
					
						
							| 
									
										
										
										
											2008-03-11 23:42:32 -04:00
										 |  |  |     thread-id local-node get-global <remote-process> | 
					
						
							| 
									
										
										
										
											2008-02-18 06:07:40 -05:00
										 |  |  |     (serialize) ;
 | 
					
						
							| 
									
										
										
										
											2008-03-11 23:42:32 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : stop-node ( node -- )
 | 
					
						
							|  |  |  |     f swap send-remote-message ;
 |