You are looking at historical revision 21249 of this page. It may differ significantly from its current revision.

remote-mailbox-threads

Description

This is an extension of the mailbox-threads egg to allow communication between remote threads via zmq. The s11n egg is used to serialize messages so its limitations apply for what can be sent.

Author

Moritz Heidkamp

Requirements

zmq, s11n and mailbox-threads

Documentation

All procedures exported by mailbox-threads are also exported by remote-mailbox-threads, the only difference being that thread-send can also send messages to remote threads (see connect-remote-thread on how to connect to a remote thread). The functions documented here are only those which are provided additionally.

[procedure] (publish-thread! thread . endpoints)

Publish thread via endpoints (a list of zmq endpoint strings). For each invocation of publish-thread! a thread with a message loop for the given endpoints is started.

[procedure] (connect-remote-thread . endpoints)

Connect to remote thread(s) at endpoints (a list of zmq endpoint strings). The return value will be a remote-thread record which can be sent messages just like normal threads using thread-send. The remote threads must be published by using publish-thread! at the remote side. If more than one endpoint is given in endpoints, messages will be sent round-robin style thus you should make sure that all messages sent to the remote thread can be handled by any of the given endpoints.

Example

Consumer:

(use remote-mailbox-threads)

(publish-thread! (current-thread) 
                 "tcp://127.0.0.1:12345"
                 "ipc:///tmp/nomnom")

(print "waiting for things to consume")

(let loop ((msg (thread-receive)))
  (display "nom nom nom:")
  (print msg)
  (loop (thread-receive)))

Producer:



(use remote-mailbox-threads)

(define consumer (connect-remote-thread "tcp://127.0.0.1:12345"))
(define another-consumer (connect-remote-thread "ipc:///tmp/nomnom"))
(thread-send consumer 'carrot)
(thread-send another-consumer 'egg)

Note that the producer connects to two different remote threads, both of which refer to the same exported thread of the producer.

License

 Copyright (c) 2010, Moritz Heidkamp
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
     * Redistributions of source code must retain the above copyright
       notice, this list of conditions and the following disclaimer.
     * Redistributions in binary form must reproduce the above copyright
       notice, this list of conditions and the following disclaimer in the
       documentation and/or other materials provided with the distribution.
     * Neither the name of the <organization> nor the
       names of its contributors may be used to endorse or promote products
       derived from this software without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.