Source:
<code>private void runMoves(final String firstContextId, final String secondContextId) { String srcId = firstContextId; String destId = secondContextId; for (int i = 0; i < iterations; i++) { final Set<LongRange> srcRangeSet = partitionManager.getRangeSet(srcId, SimpleEMTask.KEY); final long numToMove = getNumUnits(srcRangeSet) / 2; LOG.info("Move partitions of total size " + numToMove + " from " + srcId + " to " + destId); final Set<LongRange> rangeSetToMove = getRangeSetToMove(srcId, destId, srcRangeSet, numToMove); for (final LongRange range : rangeSetToMove) { LOG.info("- " + range + ", size: " + (range.getMaximumLong() - range.getMinimumLong() + 1)); } final boolean[] moveSucceeded = {false}; try (final TraceScope moveTraceScope = Trace.startSpan("simpleMove", Sampler.ALWAYS)) { emService.move(SimpleEMTask.KEY, rangeSetToMove, srcId, destId, new EventHandler<AvroElasticMemoryMessage>() { @Override public void onNext(final AvroElasticMemoryMessage emMsg) { synchronized (SimpleEMDriver.this) { moveSucceeded[0] = emMsg.getResultMsg().getResult().equals(Result.SUCCESS) ? true : false; LOG.info("Move " + emMsg.getOperationId() + (moveSucceeded[0] ? " succeeded" : " failed")); SimpleEMDriver.this.notifyAll(); } } }); } final String tmpContextId = srcId; srcId = destId; destId = tmpContextId; synchronized (this) { try { wait(periodMillis); <START> if (!moveSucceeded[0]) { <END> throw new RuntimeException("Move failed on iteration " + i); } } catch (InterruptedException e) { throw new RuntimeException("Move wait interrupted on iteration " + i, e); } } } }</code><technical_language>This code relies of moveSucceeded[0] determine current move operation succeeded failed. in current move finished, previous move succeeded? this code, waiting for periodMillis milliseconds, current move ended failure next operation. pretty this is intended do</technical_language>

Target:
private void runMoves(final String firstContextId, final String secondContextId) { String srcId = firstContextId; String destId = secondContextId; for (int i = 0; i < iterations; i++) { final Set<LongRange> srcRangeSet = partitionManager.getRangeSet(srcId, SimpleEMTask.KEY); final long numToMove = getNumUnits(srcRangeSet) / 2; LOG.info("Move partitions of total size " + numToMove + " from " + srcId + " to " + destId); final Set<LongRange> rangeSetToMove = getRangeSetToMove(srcId, destId, srcRangeSet, numToMove); for (final LongRange range : rangeSetToMove) { LOG.info("- " + range + ", size: " + (range.getMaximumLong() - range.getMinimumLong() + 1)); } final boolean[] moveSucceeded = {false}; try (final TraceScope moveTraceScope = Trace.startSpan("simpleMove", Sampler.ALWAYS)) { emService.move(SimpleEMTask.KEY, rangeSetToMove, srcId, destId, new EventHandler<AvroElasticMemoryMessage>() { @Override public void onNext(final AvroElasticMemoryMessage emMsg) { synchronized (SimpleEMDriver.this) { moveSucceeded[0] = emMsg.getResultMsg().getResult().equals(Result.SUCCESS) ? true : false; LOG.info("Move " + emMsg.getOperationId() + (moveSucceeded[0] ? " succeeded" : " failed")); SimpleEMDriver.this.notifyAll(); } } }); } final String tmpContextId = srcId; srcId = destId; destId = tmpContextId; synchronized (this) { try { wait(periodMillis); if (!moveSucceeded[0]) { throw new RuntimeException("Move failed on iteration " + i); } } catch (final InterruptedException e) { throw new RuntimeException("Move wait interrupted on iteration " + i, e); } } } }