Skip to content

Instantly share code, notes, and snippets.

@tsuna tsuna/ScannerTest.java forked from AlexYangYu/gist:5476160
Last active Dec 16, 2015

Embed
What would you like to do?
Recursive asynchronous HBase scanning
package me.alexyang.scanner;
import java.nio.charset.Charset;
import java.util.ArrayList;
import org.jboss.netty.util.CharsetUtil;
import com.stumbleupon.async.Callback;
import com.stumbleupon.async.Deferred;
import org.hbase.async.HBaseClient;
import org.hbase.async.KeyValue;
import org.hbase.async.Scanner;
/**
* @author Alex Yang <alex890714@gmail.com>
*/
public class ScannerTest {
public static void main(String[] args) throws Exception {
final HBaseClient hbase = new HBaseClient("centos-pd.alexyang.me");
try {
hbase.ensureTableExists("query").joinUninterruptibly();
final Scanner scanner = hbase.newScanner("query");
try {
scanner.setFamily("dims");
scanner.setQualifier("val");
final ArrayList<String> results = new ArrayList<String>();
class ResultHandler implements Callback<Object, ArrayList<ArrayList<KeyValue>>> {
public Object call(ArrayList<ArrayList<KeyValue>> t) throws Exception {
if (t == null) {
return null;
}
for (ArrayList<KeyValue> arr : t) {
for (KeyValue kv : arr) {
results.add(new String(kv.value(), CharsetUtil.ISO_8859_1));
}
}
return scanner.nextRows().addCallback(ResultHandler.this);
}
}
scanner.nextRows().addCallback(new ResultHandler()).join();
for (String str : results) {
System.out.println(str);
}
} finally {
scanner.close().joinUninterruptibly();
}
} finally {
hbase.shutdown().joinUninterruptibly();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.