question

Upvotes
Accepted
1 2 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.

@NN

Hi,
As your query is related to UPA, I moved it to this UPA group.

Kind regards,
AHS

@NN

Thank you for your participation in the forum.

Are any of the replies below satisfactory in resolving your query?

If yes please click the 'Accept' text next to the most appropriate reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

AHS

@NN

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.

Thanks,

AHS

Upvotes
Accepted
78.8k 250 52 74

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
32.2k 40 11 20

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.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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