Skip to content

Instantly share code, notes, and snippets.

@kjunine
Created September 16, 2013 07:24
Show Gist options
  • Save kjunine/6577584 to your computer and use it in GitHub Desktop.
Save kjunine/6577584 to your computer and use it in GitHub Desktop.
Using HTablePool with HbaseTemplate.
package sample.utils;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.HTableInterfaceFactory;
import org.apache.hadoop.hbase.client.HTablePool;
public class PooledHTableFactory implements HTableInterfaceFactory {
private HTablePool tablePool;
public PooledHTableFactory(HTablePool tablePool) {
this.tablePool = tablePool;
}
@Override
public HTableInterface createHTableInterface(Configuration config,
byte[] tableName) {
return tablePool.getTable(tableName);
}
@Override
public void releaseHTableInterface(HTableInterface table)
throws IOException {
table.close();
}
}
<bean id="hbaseTemplate" class="org.springframework.data.hadoop.hbase.HbaseTemplate"
p:configuration-ref="hbaseConfiguration" p:tableFactory-ref="tableFactory" />
<bean id="tablePool" class="org.apache.hadoop.hbase.client.HTablePool">
<constructor-arg ref="hbaseConfiguration" />
<constructor-arg value="#" />
</bean>
<bean id="tableFactory" class="sample.utils.PooledHTableFactory">
<constructor-arg ref="tablePool" />
</bean>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment