i3wangyi commented on a change in pull request #367: Add transient cache for CustomRestClient implementation URL: https://github.com/apache/helix/pull/367#discussion_r309955047
########## File path: helix-rest/src/main/java/org/apache/helix/rest/client/CustomRestClientImpl.java ########## @@ -52,16 +56,26 @@ private static final String ACCEPT_CONTENT_TYPE = "application/json"; private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - private HttpClient _httpClient; + private final HttpClient _httpClient; + private final Semaphore _semaphore; + // a transient cache holds the HttpResponse of HttpPosts, only valid when cache is enabled + private final Map<Integer, HttpResponse> _cachedResults = new HashMap<>(); private interface JsonConverter { Map<String, Boolean> convert(JsonNode jsonNode); } - public CustomRestClientImpl(HttpClient httpClient) { + CustomRestClientImpl(HttpClient httpClient) { _httpClient = httpClient; + _semaphore = new Semaphore(10); Review comment: @jiajunwang @dasahcc My original design of using semaphore is for allowing more than 1 thread to send http request at a time but also it gives the ability for rest threads wait for the cache to be populated. The latest commit is a better idea. Locking based on request ids, different request id wouldn't be blocked. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services