question

Upvotes
Accepted
1 1 1 4

At what frequency, Dispatch method dispatches the messages on the Reactor Channel?

The below code snippet is from the Consumer Value Add example. On Executing this, looks like the reactor dispatches the messages after every 10 seconds. But doesn't look like it is configured in the example code. I wanted to ask if this Reactor's implicit behavior to dispatch the messages after every 10 seconds or this can be controlled by the API user?

// dispatch until no more messages

while ((ret = reactorChnl.dispatch(dispatchOptions, errorInfo)) > 0) {}

if (ret == ReactorReturnCodes.FAILURE)

{

if (reactorChnl.state() != ReactorChannel.State.CLOSED &&

reactorChnl.state() != ReactorChannel.State.DOWN_RECONNECTING)

{

System.out.println("ReactorChannel dispatch failed: " + ret + "(" + errorInfo.error().text() + ")");

uninitialize();

System.exit(ReactorReturnCodes.FAILURE);

}

}

elektronelektron-sdkrrteta-apielektron-transport-apireactor
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
52.9k 136 44 63

In the Consumer Value Add example, reactorChnl.dispatch() will be called after selector.select() returns and there is data available to be read in the reactor channel.

private void run()		
{		
	int selectRetVal, selectTime = 1000;
	while (true)
	{
        Set<SelectionKey> keySet = null;
        try
        {
        	selectRetVal = selector.select(selectTime);
              if (selectRetVal > 0)
            {
                keySet = selector.selectedKeys();
            }
        }
…
}

Then, reactorChnl.dispatch() will be called until there is no more messages to process.

while ((ret = reactorChnl.dispatch(dispatchOptions, errorInfo)) > 0) {}

The return value of ReactorChannel.dispatch() can be:

  • A positive value if dispatching succeeded and there are more messages to process
  • ReactorReturnCodes.SUCCESS if dispatching succeeded and there are no more messages to process
  • ReactorReturnCodes.FAILURE, if dispatching failed (refer to errorInfo for additional information)

From this information, the Consumer Value Add example will dispatch the messages when there are messages available to process. It will not dispatch the messages after every 10 seconds except the code was modified or the data comes every 10 seconds.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
31.8k 37 11 19

Reactor dispatch is controlled by dispatchOptions, which is defined by maxMessages to process, which by default is 100. Therefore, usually dispatch fully dispatches the messages available on the descriptor, and if more is expected, it can be set higher.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.