dehora / nakadi-java

🌀 Client library for the Nakadi Event Broker (examples: http://bit.ly/njc-examples, site: https://dehora.github.io/nakadi-java/)
MIT License
30 stars 19 forks source link

Handling InterruptedException #335

Open Dexteroo7 opened 6 years ago

Dexteroo7 commented 6 years ago

I noticed that when an InterruptedException is caught, we set the interrupt flag back using Thread.currentThread().interrupt(). Should we not also throw some exception, so that the higher level code, is aware than an InterruptedException was caught and handled by lower level code ? Something like https://www.yegor256.com/2015/10/20/interrupted-exception.html (check towards the end) He's just throwing a RuntimeException, we could have custom exceptions, depending on the use-case.

dehora commented 6 years ago

I noticed that when an InterruptedException is caught, we set the interrupt flag back using Thread.currentThread().interrupt(). Should we not also throw some exception

@Dexteroo7 can you point to the where that's happening and maybe a description of what the issue is; the client uses a background thread which means some exceptions need to be propagated differently and just throwing won't always work.

Dexteroo7 commented 6 years ago
  1. I would not call it an issue :) rather an improvement in the API
  2. An example scenario: Client is trying to restart the stream processor, calls StreamProcessor.stop(), but the thread gets interrupted. The exception gets handled in ExecutorServiceSupport.shutdown(). Ideally I would want to throw the exception up the stack, so that the client code calling StreamProcessor.stop(), get the exception as well and can handle it accordingly, otherwise the client would continue with the restart code path. The client could have handled the exception and gracefully stop the restart code path.