private void tryRecoverCurrentBatch(Integer failedBatchNumber) { log.info("Trying to recover currentBatch"); long nextBatchNumber = ConcurrentAwaitableCounter.nextCount(failedBatchNumber); byte[] newBuffer = acquireBuffer(); if (concurrentBatch.compareAndSet(failedBatchNumber, new Batch(this, newBuffer, nextBatchNumber))) { log.info("Successfully recovered currentBatch"); } else { // It's normal, a concurrent thread could succeed to recover first. buffersToReuse.add(newBuffer); } }
private void doOnSealExclusive(Batch batch, long elapsedTimeMillis) { batchFillingTimeCounter.add((int) Math.max(elapsedTimeMillis, 0)); if (elapsedTimeMillis > 0) { // If elapsedTimeMillis is 0 or negative, it's likely because System.currentTimeMillis() is not monotonic, so not // accounting this time for determining batch sending timeout. lastBatchFillTimeMillis = elapsedTimeMillis; } addBatchToEmitQueue(batch); wakeUpEmittingThread(); if (!isTerminated()) { long nextBatchNumber = ConcurrentAwaitableCounter.nextCount(batch.batchNumber); byte[] newBuffer = acquireBuffer(); if (!concurrentBatch.compareAndSet(batch, new Batch(this, newBuffer, nextBatchNumber))) { buffersToReuse.add(newBuffer); // If compareAndSet failed, the service should be closed concurrently, i. e. we expect isTerminated() = true. // If we don't see this, there should be some bug in HttpPostEmitter. Preconditions.checkState(isTerminated()); } } }
concurrentBatch.set(new Batch(this, acquireBuffer(), firstBatchNumber));
private void tryRecoverCurrentBatch(Integer failedBatchNumber) { log.info("Trying to recover currentBatch"); long nextBatchNumber = ConcurrentAwaitableCounter.nextCount(failedBatchNumber); byte[] newBuffer = acquireBuffer(); if (concurrentBatch.compareAndSet(failedBatchNumber, new Batch(this, newBuffer, nextBatchNumber))) { log.info("Successfully recovered currentBatch"); } else { // It's normal, a concurrent thread could succeed to recover first. buffersToReuse.add(newBuffer); } }
private void doOnSealExclusive(Batch batch, long elapsedTimeMillis) { batchFillingTimeCounter.add((int) Math.max(elapsedTimeMillis, 0)); if (elapsedTimeMillis > 0) { // If elapsedTimeMillis is 0 or negative, it's likely because System.currentTimeMillis() is not monotonic, so not // accounting this time for determining batch sending timeout. lastFillTimeMillis = elapsedTimeMillis; } addBatchToEmitQueue(batch); wakeUpEmittingThread(); if (!isTerminated()) { long nextBatchNumber = ConcurrentAwaitableCounter.nextCount(batch.batchNumber); byte[] newBuffer = acquireBuffer(); if (!concurrentBatch.compareAndSet(batch, new Batch(this, newBuffer, nextBatchNumber))) { buffersToReuse.add(newBuffer); // If compareAndSet failed, the service should be closed concurrently, i. e. we expect isTerminated() = true. // If we don't see this, there should be some bug in HttpPostEmitter. Preconditions.checkState(isTerminated()); } } }
concurrentBatch.set(new Batch(this, acquireBuffer(), firstBatchNumber));