Programming with Direct Subscribers

Create a direct subscriber object. Code a callback method. Code a dispatch loop. Close the direct subscriber.

Procedure

  1. Code a direct callback method.
    Within the callback, loop to unpack the data items.
    Avoid introducing latency within the callback.
    Programs can use the same callback with more than one direct subscriber object, and in more than one thread.
  2. Create a direct subscriber object.
    The object will exist in memory until the process terminates.

    Programs may use a direct subscriber in multiple threads. However, contention to dispatch a direct subscriber object can decrease performance and increase latency.

  3. Code a dispatch loop for the direct subscriber.
    A dispatch loop repeatedly calls the dispatch method.
    The dispatch method checks whether inbound data is available for a direct subscriber object.
    • Data - If a data buffer is available, dispatch invokes the callback method, passing the buffer and a closure object as arguments to the callback. When the callback returns, the direct subscriber automatically acknowledges that it has received the buffer. Then the dispatch call returns.
    • No Data - If a data buffer is not available, dispatch waits until data becomes available, or until the timeout expires.
    You can supply a closure object that is specific to the direct subscriber object, or you can supply a global closure object common to more than one direct subscriber.

Clean up before the application process exits.

  1. Close the direct subscriber object.
    Closing a direct subscriber causes any executing dispatch calls to return immediately. Closing also invalidates the direct subscriber, which disallows any subsequent method calls.

    However, closing a direct subscriber does not free its memory.