ToolTalk User's Guide

Can I run more than one handler of a given ptype?

Yes, you can run more than one handler of a given ptype. However, the ToolTalk service does not have a concept of load balancing; that is, the ToolTalk service will choose one of the handlers and deliver additional matching messages to the chosen handler only. There are several ways to force the ToolTalk service to deliver messages to other handlers:

  1. Use tt_message_reject.

    If a message comes in and a process does not want to handle it because the process is busy, the process can reject the message. The ToolTalk service will then try the next possible handler (and apply the disposition options when it runs out of registered handlers.)

    This method requires the process to be in an event loop; that is, it must call tt_message_receive when the tt_fd is active. However, if the process is in a heavy computational loop, this method fails.

  2. Unregister the pattern when busy. For example:

   m = tt_message_receive();
   if (m is the message that causes us to go busy) {
        tt_pattern_unregister(p);
   }

The ToolTalk service will not route matching messages to the process when the pattern is not registered. When you want the process to receive messages again, re-register the pattern.


Note –

This method causes a race condition. For example, a second message could be sent and routed to the process in the time between the first tt_message_receive call and the tt_pattern_unregister call.


  1. A combination of Methods 1 and 2.

    You can use a combination of the first two techniques in the following manner:

get the message
   unregister the pattern
   loop, calling tt_message_receive until it returns 0; reject
   all the returned messages
   handle the message
   re-register the pattern
   repeat


Note –

This method assumes that the process only registers one pattern.