Source:
<code>private ListenableFuture<TaskStatus> attachCallbacks(final Task task, final ListenableFuture<TaskStatus> statusFuture) { final ServiceMetricEvent.Builder metricBuilder = new ServiceMetricEvent.Builder(); IndexTaskUtils.setTaskDimensions(metricBuilder, task); Futures.addCallback( statusFuture, new FutureCallback<TaskStatus>() { @Override public void onSuccess(final TaskStatus status) { log.info("Received %s status for task: %s", status.getStatusCode(), status.getId()); handleStatus(status); } @Override public void onFailure(final Throwable t) { log.makeAlert(t, "Failed to run task") .addData("task", task.getId()) .addData("type", task.getType()) .addData("dataSource", task.getDataSource()) .emit(); handleStatus(TaskStatus.failure(task.getId())); } private void handleStatus(final TaskStatus status) { try { if (!active) { log.info("Abandoning task due to shutdown: %s", task.getId()); return; } notifyStatus(task, status, "notified status change from task"); if (status.isComplete()) { IndexTaskUtils.setTaskStatusDimensions(metricBuilder, status); emitter.emit(metricBuilder.build("task/run/time", status.getDuration())); log.info( "Task %s: %s (%d run duration)", status.getStatusCode(), task, status.getDuration() ); if (status.isSuccess()) { totalSuccessfulTaskCount.computeIfAbsent(task.getDataSource(), k -> new AtomicLong()); <START> totalSuccessfulTaskCount.get(task.getDataSource()).incrementAndGet(); <END> } else { totalFailedTaskCount.computeIfAbsent(task.getDataSource(), k -> new AtomicLong()); totalFailedTaskCount.get(task.getDataSource()).incrementAndGet(); } } } catch (Exception e) { log.makeAlert(e, "Failed to handle task status") .addData("task", task.getId()) .addData("statusCode", status.getStatusCode()) .emit(); } } } ); return statusFuture; }</code><technical_language>computeIfAbsent() returns proper instance of AtomicLong, call incrementAndGet() instance below. This is avoid unnecessary get(). java totalSuccessfulTaskCount.computeIfAbsent(task.getDataSource(), -> new AtomicLong()) .incrementAndGet();</technical_language>

Target:
private ListenableFuture<TaskStatus> attachCallbacks(final Task task, final ListenableFuture<TaskStatus> statusFuture) { final ServiceMetricEvent.Builder metricBuilder = new ServiceMetricEvent.Builder(); IndexTaskUtils.setTaskDimensions(metricBuilder, task); Futures.addCallback( statusFuture, new FutureCallback<TaskStatus>() { @Override public void onSuccess(final TaskStatus status) { log.info("Received %s status for task: %s", status.getStatusCode(), status.getId()); handleStatus(status); } @Override public void onFailure(final Throwable t) { log.makeAlert(t, "Failed to run task") .addData("task", task.getId()) .addData("type", task.getType()) .addData("dataSource", task.getDataSource()) .emit(); handleStatus(TaskStatus.failure(task.getId())); } private void handleStatus(final TaskStatus status) { try { if (!active) { log.info("Abandoning task due to shutdown: %s", task.getId()); return; } notifyStatus(task, status, "notified status change from task"); if (status.isComplete()) { IndexTaskUtils.setTaskStatusDimensions(metricBuilder, status); emitter.emit(metricBuilder.build("task/run/time", status.getDuration())); log.info( "Task %s: %s (%d run duration)", status.getStatusCode(), task, status.getDuration() ); if (status.isSuccess()) { totalSuccessfulTaskCount.computeIfAbsent(task.getDataSource(), k -> new AtomicLong()) .incrementAndGet(); } else { totalFailedTaskCount.computeIfAbsent(task.getDataSource(), k -> new AtomicLong()) .incrementAndGet(); } } } catch (Exception e) { log.makeAlert(e, "Failed to handle task status") .addData("task", task.getId()) .addData("statusCode", status.getStatusCode()) .emit(); } } } ); return statusFuture; }