/** * Creates a new Mutable with a null value to start with. */ public static <T> Mutable<T> newMutable() { return newMutable(null); } }
@Nullable public static <T> T getFirst(BatchingVisitable<T> visitable, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); visitable.batchAccept(1, AbortingVisitors.<T, RuntimeException>batching(item -> { ret.set(item); return false; })); return ret.get(); }
@Nullable public static <T> T getLast(BatchingVisitable<T> visitable, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); visitable.batchAccept(DEFAULT_BATCH_SIZE, AbortingVisitors.<T, RuntimeException>batching(item -> { ret.set(item); return true; })); return ret.get(); }
final Ordering<? super T> o, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); v.batchAccept( DEFAULT_BATCH_SIZE,
final Ordering<? super T> o, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); v.batchAccept( DEFAULT_BATCH_SIZE,
private byte[] internalCopyRange(BatchingVisitable<RowResult<byte[]>> bv, final long maxBytes, final Transaction txn) { final Mutable<byte[]> lastRowName = Mutables.newMutable(null); final MutableLong bytesPut = new MutableLong(0L); bv.batchAccept(readBatchSize, AbortingVisitors.batching( // Replacing this with a lambda results in an unreported exception compile error // even though no exception can be thrown :-( new AbortingVisitor<RowResult<byte[]>, RuntimeException>() { @Override public boolean visit(RowResult<byte[]> rr) throws RuntimeException { return TransactionRangeMigrator.this.internalCopyRow(rr, maxBytes, txn, bytesPut, lastRowName); } })); return lastRowName.get(); }
private byte[] internalCopyRange(BatchingVisitable<RowResult<byte[]>> bv, final long maxBytes, @Output final Map<Cell, byte[]> writeMap) { final Mutable<byte[]> lastRowName = Mutables.newMutable(null); final MutableLong bytesPut = new MutableLong(0L); bv.batchAccept(readBatchSize, AbortingVisitors.batching( // Replacing this with a lambda results in an unreported exception compile error // even though no exception can be thrown :-( new AbortingVisitor<RowResult<byte[]>, RuntimeException>() { @Override public boolean visit(RowResult<byte[]> rr) throws RuntimeException { return KvsRangeMigrator.this.internalCopyRow(rr, maxBytes, writeMap, bytesPut, lastRowName); } })); return lastRowName.get(); }
/** * Creates a new Mutable with a null value to start with. */ public static <T> Mutable<T> newMutable() { return newMutable(null); } }
@Test public void testBatchWrap2() { BatchingVisitable<Long> visitor = ListVisitor.create(Lists.newArrayList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L)); final Mutable<Boolean> hasTripped = Mutables.newMutable(); AbortingVisitor<List<? extends Long>, RuntimeException> bv = item -> { hasTripped.set(true); assertEquals("batched item had wrong size", 8, item.size()); return false; }; AbortingVisitor<List<Long>, RuntimeException> wrap = AbortingVisitors.wrapBatching(bv); BatchingVisitableView.of(visitor).batchAccept(1000, wrap); assertTrue("should have been tripped!", hasTripped.get()); }
@Test public void testBatchWrap() { BatchingVisitable<Long> visitor = ListVisitor.create(Lists.newArrayList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L)); final Mutable<Boolean> hasTripped = Mutables.newMutable(); AbortingVisitor<List<Object>, RuntimeException> bv = item -> { hasTripped.set(true); assertEquals("batched item had wrong size", 8, item.size()); return false; }; AbortingVisitor<List<Long>, RuntimeException> wrap = AbortingVisitors.wrapBatching(bv); BatchingVisitableView.of(visitor).batchAccept(1000, wrap); assertTrue("should have been tripped!", hasTripped.get()); }
@Test public void testBatchHints() { BatchingVisitable<Long> visitor = ListVisitor.create(Lists.newArrayList(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L)); Function<List<Long>, List<String>> trans = (input) -> { assertEquals("batched item had wrong size", 2, input.size()); return Lists.transform(input, Functions.toStringFunction()); }; BatchingVisitableView<String> visitable = BatchingVisitableView.of(visitor).transformBatch(trans) .hintBatchSize(2); final Mutable<Boolean> hasTripped = Mutables.newMutable(); visitable.batchAccept(10000, item -> { hasTripped.set(true); assertEquals("batched item had wrong size", 8, item.size()); return false; }); assertTrue("should have been tripped!", hasTripped.get()); }
final Mutable<Integer> numSuccess = Mutables.newMutable(0); final Mutable<Integer> numFailure = Mutables.newMutable(0); for (int i = 0; i < numThreads; ++i) { final int clientID = i;
@Nullable public static <T> T getFirst(BatchingVisitable<T> visitable, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); visitable.batchAccept(1, AbortingVisitors.<T, RuntimeException>batching(item -> { ret.set(item); return false; })); return ret.get(); }
@Nullable public static <T> T getLast(BatchingVisitable<T> visitable, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); visitable.batchAccept(DEFAULT_BATCH_SIZE, AbortingVisitors.<T, RuntimeException>batching(item -> { ret.set(item); return true; })); return ret.get(); }
final Ordering<? super T> o, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); v.batchAccept( DEFAULT_BATCH_SIZE,
final Ordering<? super T> o, @Nullable T defaultElement) { final Mutable<T> ret = Mutables.newMutable(defaultElement); v.batchAccept( DEFAULT_BATCH_SIZE,
private byte[] internalCopyRange(BatchingVisitable<RowResult<byte[]>> bv, final long maxBytes, final Transaction txn) { final Mutable<byte[]> lastRowName = Mutables.newMutable(null); final MutableLong bytesPut = new MutableLong(0L); bv.batchAccept(readBatchSize, AbortingVisitors.batching( // Replacing this with a lambda results in an unreported exception compile error // even though no exception can be thrown :-( new AbortingVisitor<RowResult<byte[]>, RuntimeException>() { @Override public boolean visit(RowResult<byte[]> rr) throws RuntimeException { return TransactionRangeMigrator.this.internalCopyRow(rr, maxBytes, txn, bytesPut, lastRowName); } })); return lastRowName.get(); }
private byte[] internalCopyRange(BatchingVisitable<RowResult<byte[]>> bv, final long maxBytes, @Output final Map<Cell, byte[]> writeMap) { final Mutable<byte[]> lastRowName = Mutables.newMutable(null); final MutableLong bytesPut = new MutableLong(0L); bv.batchAccept(readBatchSize, AbortingVisitors.batching( // Replacing this with a lambda results in an unreported exception compile error // even though no exception can be thrown :-( new AbortingVisitor<RowResult<byte[]>, RuntimeException>() { @Override public boolean visit(RowResult<byte[]> rr) throws RuntimeException { return KvsRangeMigrator.this.internalCopyRow(rr, maxBytes, writeMap, bytesPut, lastRowName); } })); return lastRowName.get(); }