private void sendNext() { if (this.sender == null) { return; } Operation op = null; synchronized (this.operationIterator) { if (this.operationIterator.hasNext()) { op = this.operationIterator.next(); } } if (op != null) { if (this.batchSize > 0 && this.batchSizeGuard.incrementAndGet() > this.batchSize) { throw new IllegalStateException((ERROR_MSG_BATCH_LIMIT_VIOLATED)); } sendOperation(op); } }
private void sendWithBatch() { if (this.operationIterator == null || !this.operationIterator.hasNext()) { throw new IllegalStateException("No operations to be sent"); } // Move the operations to local list to avoid concurrency issues with iterator // when sendNext could be called from handler of returning operation // before we get out of this method. ArrayList<Operation> batch = new ArrayList<>(); int count = 0; while (this.operationIterator.hasNext()) { batch.add(this.operationIterator.next()); count++; if (this.batchSize > 0 && count == this.batchSize) { break; } } for (Operation op : batch) { sendOperation(op); if (this.batchSize > 0 && this.batchSizeGuard.incrementAndGet() > this.batchSize) { throw new IllegalStateException((ERROR_MSG_BATCH_LIMIT_VIOLATED)); } } }