/** * Type-inferred factory method for {@link Mutable} */ public static <T> Mutable<T> newMutable(T val) { return new Mutable<T>(val); }
/** * Returns a hash code of the <code>Mutable</code>'s value. */ @Override public int hashCode() { T v = get(); if(v == null) return 0; return v.hashCode(); }
private boolean internalCopyRow(RowResult<byte[]> rr, long maxBytes, @Output Map<Cell, byte[]> writeMap, @Output MutableLong bytesPut, @Output Mutable<byte[]> lastRowName) { Map<Cell, byte[]> values = rowTransform.apply(rr); writeMap.putAll(values); for (Map.Entry<Cell, byte[]> e : values.entrySet()) { bytesPut.add(e.getValue().length + Cells.getApproxSizeOfCell(e.getKey())); } if (bytesPut.longValue() >= maxBytes) { lastRowName.set(rr.getRowName()); return false; } return true; } }
/** * Returns <code>true</code> if this <code>Mutable</code> * is equal to the given object. */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof Mutable<?>)) return false; final Mutable<?> other = (Mutable<?>) obj; T v = get(); Object otherV = other.get(); if (v == null) { if (otherV != null) return false; } else if (!v.equals(otherV)) return false; return true; }
private boolean internalCopyRow(RowResult<byte[]> rr, long maxBytes, Transaction writeT, @Output MutableLong bytesPut, @Output Mutable<byte[]> lastRowName) { Map<Cell, byte[]> values = rowTransform.apply(rr); writeT.put(destTable, values); for (Map.Entry<Cell, byte[]> e : values.entrySet()) { bytesPut.add(e.getValue().length + Cells.getApproxSizeOfCell(e.getKey())); } if (bytesPut.longValue() >= maxBytes) { lastRowName.set(rr.getRowName()); return false; } return true; } }
return ret.get();
private boolean internalCopyRow(RowResult<byte[]> rr, long maxBytes, @Output Map<Cell, byte[]> writeMap, @Output MutableLong bytesPut, @Output Mutable<byte[]> lastRowName) { Map<Cell, byte[]> values = rowTransform.apply(rr); writeMap.putAll(values); for (Map.Entry<Cell, byte[]> e : values.entrySet()) { bytesPut.add(e.getValue().length + Cells.getApproxSizeOfCell(e.getKey())); } if (bytesPut.longValue() >= maxBytes) { lastRowName.set(rr.getRowName()); return false; } return true; } }
public static<T> Mutable<T> create() { return new Mutable<T>(); }
return ret.get();
private boolean internalCopyRow(RowResult<byte[]> rr, long maxBytes, Transaction writeT, @Output MutableLong bytesPut, @Output Mutable<byte[]> lastRowName) { Map<Cell, byte[]> values = rowTransform.apply(rr); writeT.put(destTable, values); for (Map.Entry<Cell, byte[]> e : values.entrySet()) { bytesPut.add(e.getValue().length + Cells.getApproxSizeOfCell(e.getKey())); } if (bytesPut.longValue() >= maxBytes) { lastRowName.set(rr.getRowName()); return false; } return true; } }
/** * Type-inferred factory method for {@link Mutable} */ public static <T> Mutable<T> newMutable(T val) { return new Mutable<T>(val); }
@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(); }
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(); }
public static<T> Mutable<T> create() { return new Mutable<T>(); }
@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()); }
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(); }
@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()); }