@Override public void close() { flush(); try { executor.shutdown(); } catch (Exception e) { // ignore } try { httpClient.close(); } catch (Exception e) { // ignore } }
protected GoogleAnalyticsResponse postSingle(GoogleAnalyticsRequest<?> gaReq) { HttpRequest httpReq = createHttpRequest(gaReq); HttpResponse httpResp = httpClient.post(httpReq); GoogleAnalyticsResponse response = new GoogleAnalyticsResponse(); response.setStatusCode(httpResp.getStatusCode()); response.setRequestParams(httpReq.getBodyParams()); if (config.isGatherStats()) { gatherStats(gaReq); } return response; }
private void submitBatch(boolean force) { if (currentBatch.isEmpty()) { return; } if (isSubmitBatch(force)) { // Synchronized block is to ensure only one of the writers will actually write the batch. synchronized (currentBatch) { // If two threads pass the if condition and then one of them actually writes, // other will do the same since they were blocked sync block. this ensures that // others will not post it even if multiple threads were to wait at sync block at same time // https://en.wikipedia.org/wiki/Double-checked_locking if (isSubmitBatch(force)) { logger.debug("Submitting a batch of " + currentBatch.size() + " requests to GA"); httpClient.postBatch(new HttpBatchRequest().setUrl(config.getBatchUrl()).setRequests(currentBatch)); currentBatch.clear(); } } } }
protected GoogleAnalyticsResponse postSingle(GoogleAnalyticsRequest<?> gaReq) { HttpRequest httpReq = createHttpRequest(gaReq); HttpResponse httpResp = httpClient.post(httpReq); GoogleAnalyticsResponse response = new GoogleAnalyticsResponse(); response.setStatusCode(httpResp.getStatusCode()); response.setRequestParams(httpReq.getBodyParams()); if (config.isGatherStats()) { gatherStats(gaReq); } return response; }
private void submitBatch(boolean force) { if (currentBatch.isEmpty()) { return; } if (isSubmitBatch(force)) { // Synchronized block is to ensure only one of the writers will actually write the batch. synchronized (currentBatch) { // If two threads pass the if condition and then one of them actually writes, // other will do the same since they were blocked sync block. this ensures that // others will not post it even if multiple threads were to wait at sync block at same time // https://en.wikipedia.org/wiki/Double-checked_locking if (isSubmitBatch(force)) { logger.debug("Submitting a batch of " + currentBatch.size() + " requests to GA"); httpClient.postBatch(new HttpBatchRequest().setUrl(config.getBatchUrl()).setRequests(currentBatch)); currentBatch.clear(); } } } }
@Override public void close() { flush(); try { executor.shutdown(); } catch (Exception e) { // ignore } try { httpClient.close(); } catch (Exception e) { // ignore } }