Instead of doing,
semaphore.acquire();
Could do something like,
if(!semaphore.tryAcquire(2, TimeUnit.SECONDS))
{
listener.afterBulk(executionId, bulkRequest,
new RuntimeException(
"Elasticsearch may not be responding."));
return;
}
It would be great, if the timeout could be configurable.
Also another query is, isn't it OK to release the semaphore, even before invoking the listener method?
Is there any reason, not to use tryAcquire() instead of acquire()?