@Override public BatchResult<Integer> execute(ClusterState currentState, List<Integer> tasks) throws Exception { this.tasks.addAll(tasks); return BatchResult.<Integer>builder() .successes(tasks) .build(ClusterState.builder(currentState).build()); }
@Override public BatchResult<String> execute(ClusterState currentState, List<String> tasks) throws Exception { executionOrder.addAll( tasks); // do this first, so startedProcessing can be used as a notification that this // is done. startedProcessing.release(tasks.size()); allowProcessing.acquire(tasks.size()); return BatchResult.<String>builder() .successes(tasks) .build(ClusterState.builder(currentState).build()); }
@Override public BatchResult<ClusterChangedEvent> execute( ClusterState currentState, List<ClusterChangedEvent> tasks) throws Exception { ClusterState accumulator = ClusterState.builder(currentState).build(); BatchResult.Builder<ClusterChangedEvent> builder = BatchResult.builder(); try { // we only need to apply the latest cluster state update accumulator = applyUpdate(accumulator, tasks.get(tasks.size() - 1)); builder.successes(tasks); } catch (Throwable t) { builder.failures(tasks, t); } return builder.build(accumulator); }
@Override public BatchResult<Task> execute(ClusterState currentState, List<Task> tasks) throws Exception { for (Set<Task> expectedSet : taskGroups) { long count = tasks.stream().filter(expectedSet::contains).count(); assertThat( "batched set should be executed together or not at all. Expected " + expectedSet + "s. Executing " + tasks, count, anyOf(equalTo(0L), equalTo((long) expectedSet.size()))); } tasks.forEach(Task::execute); counter.addAndGet(tasks.size()); ClusterState maybeUpdatedClusterState = currentState; if (randomBoolean()) { maybeUpdatedClusterState = ClusterState.builder(currentState).build(); batches.incrementAndGet(); semaphore.acquire(); } return BatchResult.<Task>builder().successes(tasks).build(maybeUpdatedClusterState); }