@Override public void flush() throws IOException { awaitStarted(); Object batchObj = concurrentBatch.get(); if (batchObj instanceof Batch) { flush((Batch) batchObj); } }
@Override public void flush() { Exception thrown = null; for (HttpPostEmitter httpPostEmitter : emitters.values()) { try { httpPostEmitter.flush(); } catch (Exception e) { // If flush was interrupted, exit the loop if (Thread.currentThread().isInterrupted()) { if (thrown != null) { e.addSuppressed(thrown); } throw Throwables.propagate(e); } if (thrown == null) { thrown = e; } else { if (thrown != e) { thrown.addSuppressed(e); } } } } if (thrown != null) { throw Throwables.propagate(thrown); } }
@Override @LifecycleStop public void close() throws IOException { synchronized (startLock) { if (running) { running = false; Object lastBatch = concurrentBatch.getAndSet(null); if (lastBatch instanceof Batch) { flush((Batch) lastBatch); } emittingThread.shuttingDown = true; // EmittingThread is interrupted after the last batch is flushed. emittingThread.interrupt(); } } }
@Test public void timeoutEmptyQueue() throws IOException, InterruptedException { float timeoutAllowanceFactor = 2.0f; final HttpEmitterConfig config = new HttpEmitterConfig.Builder("http://foo.bar") .setBatchingStrategy(BatchingStrategy.ONLY_EVENTS) .setHttpTimeoutAllowanceFactor(timeoutAllowanceFactor) .build(); final HttpPostEmitter emitter = new HttpPostEmitter(config, httpClient, objectMapper); long startMs = System.currentTimeMillis(); emitter.start(); emitter.emitAndReturnBatch(new IntEvent()); emitter.flush(); long fillTimeMs = System.currentTimeMillis() - startMs; Assert.assertThat((double) timeoutUsed.get(), Matchers.lessThan(fillTimeMs * (timeoutAllowanceFactor + 0.5))); startMs = System.currentTimeMillis(); final Batch batch = emitter.emitAndReturnBatch(new IntEvent()); Thread.sleep(1000); batch.seal(); emitter.flush(); fillTimeMs = System.currentTimeMillis() - startMs; Assert.assertThat((double) timeoutUsed.get(), Matchers.lessThan(fillTimeMs * (timeoutAllowanceFactor + 0.5))); } }
emitter.flush(); System.out.println("Allocated buffers: " + emitter.getTotalAllocatedBuffers()); for (int eventIndex = 0; eventIndex < N; eventIndex++) {
emitter.flush();
emitter.flush();
emitter.emit(event); emitter.flush(); waitForEmission(emitter, 1); closeNoFlush(emitter);
Assert.assertEquals(0, emitter.getFailedSendingTimeCounter().getTimeSumAndCount()); emitter.flush(); waitForEmission(emitter, 2); Assert.assertEquals(4, emitter.getTotalEmittedEvents());
@Override public void flush() throws IOException { awaitStarted(); Object batchObj = concurrentBatch.get(); if (batchObj instanceof Batch) { flush((Batch) batchObj); } }
@Override public void flush() { Exception thrown = null; for (HttpPostEmitter httpPostEmitter : emitters.values()) { try { httpPostEmitter.flush(); } catch (Exception e) { // If flush was interrupted, exit the loop if (Thread.currentThread().isInterrupted()) { if (thrown != null) { e.addSuppressed(thrown); } throw Throwables.propagate(e); } if (thrown == null) { thrown = e; } else { if (thrown != e) { thrown.addSuppressed(e); } } } } if (thrown != null) { throw Throwables.propagate(thrown); } }
@Override @LifecycleStop public void close() throws IOException { synchronized (startLock) { if (running) { running = false; Object lastBatch = concurrentBatch.getAndSet(null); if (lastBatch instanceof Batch) { flush((Batch) lastBatch); } emittingThread.shuttingDown = true; // EmittingThread is interrupted after the last batch is flushed. emittingThread.interrupt(); } } }