com.datasift.dropwizard.hbase.HBaseClientProxy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dropwizard-extra-hbase Show documentation
Show all versions of dropwizard-extra-hbase Show documentation
Dropwizard integration for working with HBase in Scala.
package com.datasift.dropwizard.hbase;
import com.datasift.dropwizard.hbase.scanner.RowScanner;
import com.datasift.dropwizard.hbase.scanner.RowScannerProxy;
import com.stumbleupon.async.Deferred;
import com.yammer.dropwizard.util.Duration;
import com.yammer.dropwizard.util.Size;
import org.hbase.async.*;
import org.jboss.netty.util.Timer;
import java.util.ArrayList;
/**
* Proxies the {@link HBaseClient} API to an {@link org.hbase.async.HBaseClient}.
*/
public class HBaseClientProxy implements HBaseClient {
private final org.hbase.async.HBaseClient client;
/**
* Initialises this proxy for the given underlying {@code client}.
*
* @param client the client to proxy requests to.
*/
public HBaseClientProxy(final org.hbase.async.HBaseClient client) {
this.client = client;
}
/**
* Get the maximum time for which edits may be buffered before being flushed.
*
* @return the maximum time for which edits may be buffered.
*
* @see org.hbase.async.HBaseClient#getFlushInterval()
*/
public Duration getFlushInterval() {
return Duration.milliseconds(client.getFlushInterval());
}
/**
* Get the capacity of the increment buffer.
*
* @return the capacity of the increment buffer.
*
* @see org.hbase.async.HBaseClient#getIncrementBufferSize()
*/
public Size getIncrementBufferSize() {
return Size.bytes(client.getIncrementBufferSize());
}
/**
* Sets the maximum time for which edits may be buffered before being flushed.
*
* @param flushInterval the maximum time for which edits may be buffered.
*
* @return the previous flush interval.
*
* @see org.hbase.async.HBaseClient#setFlushInterval(short)
*/
public Duration setFlushInterval(final Duration flushInterval) {
final short interval = (short) flushInterval.toMilliseconds();
return Duration.milliseconds(client.setFlushInterval(interval));
}
/**
* Sets the capacity of the increment buffer.
*
* @param incrementBufferSize the capacity of the increment buffer.
*
* @return the previous increment buffer capacity.
*
* @see org.hbase.async.HBaseClient#setIncrementBufferSize(int)
*/
public Size setIncrementBufferSize(final Size incrementBufferSize) {
final int size = (int) incrementBufferSize.toBytes();
return Size.bytes(client.setIncrementBufferSize(size));
}
/**
* Atomically creates a cell if, and only if, it doesn't already exist.
*
* @param edit the new cell to create.
*
* @return true if the cell was created, false if the cell already exists.
*
* @see org.hbase.async.HBaseClient#atomicCreate(org.hbase.async.PutRequest)
*/
public Deferred create(final PutRequest edit) {
return client.atomicCreate(edit);
}
/**
* Buffer a durable increment for coalescing.
*
* @param request the increment to buffer
*
* @return the new value of the cell, after the increment.
*
* @see org.hbase.async.HBaseClient#bufferAtomicIncrement(org.hbase.async.AtomicIncrementRequest)
*/
public Deferred bufferIncrement(final AtomicIncrementRequest request) {
return client.bufferAtomicIncrement(request);
}
/**
* Atomically and durably increment a cell value.
*
* @param request the increment to make.
*
* @return the new value of the cell, after the increment.
*
* @see org.hbase.async.HBaseClient#atomicIncrement(org.hbase.async.AtomicIncrementRequest)
*/
public Deferred increment(final AtomicIncrementRequest request) {
return client.atomicIncrement(request);
}
/**
* Atomically increment a cell value, with optional durability.
*
* @param request the increment to make.
* @param durable whether to guarantee this increment succeeded durably.
*
* @return the new value of the cell, after the increment.
*
* @see org.hbase.async.HBaseClient#atomicIncrement(org.hbase.async.AtomicIncrementRequest, boolean)
*/
public Deferred increment(final AtomicIncrementRequest request,
final Boolean durable) {
return client.atomicIncrement(request, durable);
}
/**
* Atomically compares and sets (CAS) a single cell
*
* @param edit the cell to set.
* @param expected the expected current value.
*
* @return true if the expectation was met and the cell was set, otherwise, false.
*
* @see org.hbase.async.HBaseClient#compareAndSet(org.hbase.async.PutRequest, byte[])
*/
public Deferred compareAndSet(final PutRequest edit,
final byte[] expected) {
return client.compareAndSet(edit, expected);
}
/**
* Atomically compares and sets (CAS) a single cell.
*
* @param edit the cell to set.
* @param expected the expected current value.
*
* @return true if the expectation was met and the cell was set, otherwise, false.
*
* @see org.hbase.async.HBaseClient#compareAndSet(org.hbase.async.PutRequest, String)
*/
public Deferred compareAndSet(final PutRequest edit,
final String expected) {
return client.compareAndSet(edit, expected);
}
/**
* Deletes the specified cells
*
* @param request the cell(s) to delete.
*
* @return a {@link Deferred} indicating when the deletion completes.
*
* @see org.hbase.async.HBaseClient#delete(org.hbase.async.DeleteRequest)
*/
public Deferred