Created
September 16, 2013 07:24
-
-
Save kjunine/6577584 to your computer and use it in GitHub Desktop.
Using HTablePool with HbaseTemplate.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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