private static <T> long countInternal(BatchingVisitable<T> visitable, int batchSize) { final long[] count = new long[1]; visitable.batchAccept(batchSize, AbortingVisitors.<T, RuntimeException>batching( item -> { count[0]++; return true; })); return count[0]; }
@Override public <K extends Exception> boolean batchAccept( int batchSize, AbortingVisitor<? super List<T>, K> visitor) throws K { return delegate().batchAccept(batchSize, visitor); }
@Override protected <K extends Exception> void batchAcceptSizeHint( int batchSizeHint, ConsistentVisitor<SortedMap<Long, Multimap<TableReference, Cell>>, K> visitor) throws K { ClosableIterator<RowResult<Value>> iterator = getIteratorToScrub(batchSizeHint, maxScrubTimestamp, startRow, endRow); try { BatchingVisitableFromIterable.create(iterator).batchAccept( batchSizeHint, batch -> visitor.visitOne(transformRows(batch))); } finally { iterator.close(); } } };
@Override public void cleanup(TransactionManager resource, Throwable initThrowable) { // Propagate errors, but there's no need to do cleanup as each task is responsible for that, // and this class assumes the tasks are independent. if (!(initThrowable instanceof NotInitializedException)) { throw Throwables.rewrapAndThrowUncheckedException(initThrowable); } } }
public static <T> boolean isEmpty(BatchingVisitable<T> v) { return v.batchAccept(1, AbortingVisitors.<T, RuntimeException>batching(AbortingVisitors.<T>alwaysFalse())); }
@Override public BatchingVisitable<MetadataRowResult> apply(BatchingVisitable<RowResult<byte[]>> visitable) { return BatchingVisitables.transform(visitable, new Function<RowResult<byte[]>, MetadataRowResult>() { @Override public MetadataRowResult apply(RowResult<byte[]> row) { return MetadataRowResult.of(row); } }); } });
public BatchingVisitableView<T> visitWhile(Predicate<T> condition) { return BatchingVisitables.visitWhile(delegate(), condition); }
public static <T> BatchingVisitableView<T> singleton(final T t) { return BatchingVisitableView.of(new BatchingVisitable<T>() { @Override public <K extends Exception> boolean batchAccept(int batchSize, AbortingVisitor<? super List<T>, K> v) throws K { return v.visit(ImmutableList.of(t)); } }); }
/** * If Throwable is a RuntimeException or Error, rewrap and throw it. If not, throw a * new PalantirRuntimeException(ex) */ public static RuntimeException rewrapAndThrowUncheckedException(String newMessage, Throwable ex) { rewrapAndThrowIfInstance(newMessage, ex, RuntimeException.class); rewrapAndThrowIfInstance(newMessage, ex, Error.class); throw createPalantirRuntimeException(newMessage, ex); }
public BatchingVisitableView<T> hintBatchSize(int batchSizeHint) { return BatchingVisitables.hintPageSize(delegate(), batchSizeHint); }
@Override public BatchingVisitable<Index2IdxRowResult> apply(BatchingVisitable<RowResult<byte[]>> visitable) { return BatchingVisitables.transform(visitable, new Function<RowResult<byte[]>, Index2IdxRowResult>() { @Override public Index2IdxRowResult apply(RowResult<byte[]> row) { return Index2IdxRowResult.of(row); } }); } });