elasticsearch/elasticsearch — pull request #2001 by jprante (2012-06-03 11:07:57+00:00)
Title: SafeTransportClient for multithreaded environments

Hi kimchy,

here is my suggestion for an additional feature for the TransportClient.

The SafeTransportClient is "safe" in a sense that in a multithreaded environment it can limit the active action listeners. If there are too many action listeners active and a new one is going to be executed, the client will stall until other action listeners have responded. And if the SafeTransportClient is closed, for example when the process is suddenly being interrupted, it will first wait for all the responses of the outstanding action listeners before the shutdown continues.

The SafeTransportClient gets three more parameters, maximumActiveListeners, millisBeforeContinue, and maximumTimeouts.

Unfortunately I had to copy the TransportClient source to extend it into a new class SafeTransportClient.

The code is not tested thoroughly but it should work. I hope the sketch is useful. Right now, I guard the TransportClient with a very similar wrapper code.

Jörg