/** Finish any pending request */ public void finishPendingRequest() { if (pendingRequest != null) { // There's a pending request, we need to build it ... add(pendingRequest.toRequest()); pendingRequest = null; } }
/** * Remove and return any requests that have been built by this builder since the last call to this * method. This method will return null if no requests have been built. If only one request was * built, then it will be returned. If multiple requests have been built, then this method will * return a {@link CompositeRequest} containing them. * * @return the request (or {@link CompositeRequest}) representing those requests that this builder * has created since the last call to this method, or null if there are no requests to return */ public Request pop() { int number = requests.size(); if (pendingRequest != null) { // There's a pending request, we need to build it ... Request newRequest = pendingRequest.toRequest(); if (number == 0) { // There's no other request ... return newRequest; } // We have at least one other request, so add the pending request ... addPending(); ++number; } else { // There is no pending request ... if (number == 0) { // And no enqueued request ... return null; } if (number == 1) { // There's only one request, so return just the one ... Request result = requests.getFirst(); requests.clear(); return result; } } assert number >= 2; // Build a composite request (reusing the existing list), and then replace the list Request result = CompositeRequest.with(requests); requests = new LinkedList<Request>(); return result; }
protected final BatchRequestBuilder addPending() { if (pendingRequest != null) { requests.add(pendingRequest.toRequest()); pendingRequest = null; } return this; }