THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
- The close(timeout) should work when called from a user caller thread or the internal sender thread.
- In sender thread only close(-1, TimeUnit.MILLISECONDS) should be called because:
- close() or close(0, TimeUnit.MILLISECONDS) should not be called because that will make producer block forever.
- close(500, TimeUnit.MILLISECONDS) has the same effect as close(-1, TimeUnit.MILLISECONDS) only except it will block for 500 milliseconds.
- Because it is possible the close(timeout) is called for multiple times, it has to be idempotent.
Proposed Changes
To close a producer forcefully, the following changes are going to be made:
- Add a forceClose flag to sender.
- When forceClose flag is set, sender will not send any more messages but fail all the messages in RecordAccumulator and wake up the threads waiting on a callback. These threads may be doing:
- synchronized send
- flush()
- Cleanup metrics and release other resources.
When close(positive, TimeUnit.MILLISECONDS) is called, it will try to do a normal close first. If the normal close did not finish before timeout, it then close the producer forcefully.
Compatibility, Deprecation, and Migration Plan
...