@Override public void run() { final long actualDelay = clock.nanoTime() - startTimeNs; addToPendingNanos(-actualDelay); callback.run(); } }, delay, TimeUnit.NANOSECONDS);
@Override public void run() { final long actualDelay = clock.nanoTime() - startTimeNs; addToPendingNanos(-actualDelay); callback.run(); } }, delay, TimeUnit.NANOSECONDS);
@Override public void run() { final long actualDelay = clock.nanoTime() - startTimeNs; addToPendingNanos(-actualDelay); callback.run(); } }, delay, TimeUnit.NANOSECONDS);
@Override public void run() { final long actualDelay = clock.nanoTime() - startTimeNs; addToPendingNanos(-actualDelay); callback.run(); } }, delay, TimeUnit.NANOSECONDS);
@Override public void run() { final long actualDelay = clock.nanoTime() - startTimeNs; addToPendingNanos(-actualDelay); callback.run(); } }, delay, TimeUnit.NANOSECONDS);
@Override public void flush() { try { incCounter(metrics.numFlushes); long startNs = clock.nanoTime(); asyncTable.flush(); updateTimer(metrics.flushNs, clock.nanoTime() - startNs); } catch (Exception e) { String errMsg = "Failed to flush remote store"; logger.error(errMsg, e); throw new SamzaException(errMsg, e); } }
protected <T> CompletableFuture<T> instrument(Func1<T> func, Counter counter, Timer timer) { incCounter(counter); final long startNs = clock.nanoTime(); CompletableFuture<T> ioFuture = func.apply(); if (callbackExecutor != null) { ioFuture.thenApplyAsync(r -> { updateTimer(timer, clock.nanoTime() - startNs); return r; }, callbackExecutor); } else { ioFuture.thenApply(r -> { updateTimer(timer, clock.nanoTime() - startNs); return r; }); } return ioFuture; } }
/** * Handle timer ticks for this {@link OperatorImpl} and propagate the results and timer tick to registered operators. * <p> * Delegates to {@link #handleTimer(MessageCollector, TaskCoordinator)} for handling the timer tick. * * @param collector the {@link MessageCollector} in the context * @param coordinator the {@link TaskCoordinator} in the context */ public final void onTimer(MessageCollector collector, TaskCoordinator coordinator) { long startNs = this.highResClock.nanoTime(); Collection<RM> results = handleTimer(collector, coordinator); long endNs = this.highResClock.nanoTime(); this.handleTimerNs.update(endNs - startNs); results.forEach(rm -> this.registeredOperators.forEach(op -> op.onMessage(rm, collector, coordinator))); this.registeredOperators.forEach(op -> op.onTimer(collector, coordinator)); }
@Override public CompletableFuture<Void> deleteAsync(K key) { incCounter(metrics.numDeletes); long startNs = clock.nanoTime(); Preconditions.checkNotNull(table, "Cannot delete from a read-only table: " + table); return table.deleteAsync(key).handle((result, e) -> { if (e != null) { throw new SamzaException("Failed to delete the record for " + key, e); } else if (!isWriteAround) { cache.delete(key); } updateTimer(metrics.deleteNs, clock.nanoTime() - startNs); return result; }); }
@Override public CompletableFuture<Void> deleteAllAsync(List<K> keys) { incCounter(metrics.numDeleteAlls); long startNs = clock.nanoTime(); Preconditions.checkNotNull(table, "Cannot delete from a read-only table: " + table); return table.deleteAllAsync(keys).handle((result, e) -> { if (e != null) { throw new SamzaException("Failed to delete the record for " + keys, e); } else if (!isWriteAround) { cache.deleteAll(keys); } updateTimer(metrics.deleteAllNs, clock.nanoTime() - startNs); return result; }); }
public TaskCallbackImpl createCallback(TaskName taskName, IncomingMessageEnvelope envelope, ReadableCoordinator coordinator) { final TaskCallbackImpl callback = new TaskCallbackImpl(listener, taskName, envelope, coordinator, seqNum++, clock.nanoTime()); if (timer != null) { Runnable timerTask = new Runnable() { @Override public void run() { ThreadUtil.logThreadDump("Thread dump at task callback timeout"); String msg = "Callback for task {} " + callback.taskName + " timed out after " + timeout + " ms."; callback.failure(new SamzaException(msg)); } }; ScheduledFuture scheduledFuture = timer.schedule(timerTask, timeout, TimeUnit.MILLISECONDS); callback.setScheduledFuture(scheduledFuture); } return callback; }
/** * Handle timer ticks for this {@link OperatorImpl} and propagate the results and timer tick to registered operators. * <p> * Delegates to {@link #handleTimer(MessageCollector, TaskCoordinator)} for handling the timer tick. * * @param collector the {@link MessageCollector} in the context * @param coordinator the {@link TaskCoordinator} in the context */ public final void onTimer(MessageCollector collector, TaskCoordinator coordinator) { long startNs = this.highResClock.nanoTime(); Collection<RM> results = handleTimer(collector, coordinator); long endNs = this.highResClock.nanoTime(); this.handleTimerNs.update(endNs - startNs); results.forEach(rm -> this.registeredOperators.forEach(op -> op.onMessage(rm, collector, coordinator))); this.registeredOperators.forEach(op -> op.onTimer(collector, coordinator)); }
/** * Handle timer ticks for this {@link OperatorImpl} and propagate the results and timer tick to registered operators. * <p> * Delegates to {@link #handleTimer(MessageCollector, TaskCoordinator)} for handling the timer tick. * * @param collector the {@link MessageCollector} in the context * @param coordinator the {@link TaskCoordinator} in the context */ public final void onTimer(MessageCollector collector, TaskCoordinator coordinator) { long startNs = this.highResClock.nanoTime(); Collection<RM> results = handleTimer(collector, coordinator); long endNs = this.highResClock.nanoTime(); this.handleTimerNs.update(endNs - startNs); results.forEach(rm -> this.registeredOperators.forEach(op -> op.onMessage(rm, collector, coordinator))); this.registeredOperators.forEach(op -> op.onTimer(collector, coordinator)); }
/** * Handle timer ticks for this {@link OperatorImpl} and propagate the results and timer tick to registered operators. * <p> * Delegates to {@link #handleTimer(MessageCollector, TaskCoordinator)} for handling the timer tick. * * @param collector the {@link MessageCollector} in the context * @param coordinator the {@link TaskCoordinator} in the context */ public final void onTimer(MessageCollector collector, TaskCoordinator coordinator) { long startNs = this.highResClock.nanoTime(); Collection<RM> results = handleTimer(collector, coordinator); long endNs = this.highResClock.nanoTime(); this.handleTimerNs.update(endNs - startNs); results.forEach(rm -> this.registeredOperators.forEach(op -> op.onMessage(rm, collector, coordinator))); this.registeredOperators.forEach(op -> op.onTimer(collector, coordinator)); }
/** * Handle timer ticks for this {@link OperatorImpl} and propagate the results and timer tick to registered operators. * <p> * Delegates to {@link #handleTimer(MessageCollector, TaskCoordinator)} for handling the timer tick. * * @param collector the {@link MessageCollector} in the context * @param coordinator the {@link TaskCoordinator} in the context */ public final void onTimer(MessageCollector collector, TaskCoordinator coordinator) { long startNs = this.highResClock.nanoTime(); Collection<RM> results = handleTimer(collector, coordinator); long endNs = this.highResClock.nanoTime(); this.handleTimerNs.update(endNs - startNs); results.forEach(rm -> this.registeredOperators.forEach(op -> op.onMessage(rm, collector, coordinator))); this.registeredOperators.forEach(op -> op.onTimer(collector, coordinator)); }
public TaskCallbackImpl createCallback(TaskName taskName, IncomingMessageEnvelope envelope, ReadableCoordinator coordinator) { final TaskCallbackImpl callback = new TaskCallbackImpl(listener, taskName, envelope, coordinator, seqNum++, clock.nanoTime()); if (timer != null) { Runnable timerTask = new Runnable() { @Override public void run() { Util.logThreadDump("Thread dump at task callback timeout"); String msg = "Callback for task {} " + callback.taskName + " timed out after " + timeout + " ms."; callback.failure(new SamzaException(msg)); } }; ScheduledFuture scheduledFuture = timer.schedule(timerTask, timeout, TimeUnit.MILLISECONDS); callback.setScheduledFuture(scheduledFuture); } return callback; }
private void setActualDelay(long actualDelayNs) { Mockito.when(clock.nanoTime()).thenReturn(0L).thenReturn(actualDelayNs); }