public class HbaseInit{
private String QUORUM = "*****";
private String CLIENTPORT = "2015";
private Configuration conf = null;
private static HConnection conn = null;
static{
System.setProperty("HADOOP_USER_NAME", "sousuo");
}
public Map<String, String> getMapFromHbase(String tableName, String rowKey){
Map<String, String> hbaseRes = new HashMap<String, String>();
conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", QUORUM);
conf.set("hbase.zookeeper.property.clientPort", CLIENTPORT);
conf.set("zookeeper.znode.parent", "/hbase");
conf.set("hbase.client.retries.number", "2");
conf.set("hbase.client.pause", "100");
conf.set("zookeeper.recovery.retry", "3");
conf.set("zookeeper.session.timeout", "1000");
conf.set("zookeeper.recovery.retry.intervalmill", "200");
conf.set("ipc.socket.timeout", "2000");
conf.set("hbase.rpc.timeout", "2000");
conf.set("hbase.client.scanner.timeout.period", "5000");
conf.set("hbase.client.operation.timeout", "5000");
try {
logger.info("取表前++++++++++++++++++++++++++++++++++++++++++");
conn = HConnectionManager.createConnection(conf);
HTable table = new HTable(conf, tableName);
logger.info("取表后++++++++++++++++++++++++++++++++++++++++++");
Get get = new Get(Bytes.toBytes(rowKey));
Result result = table.get(get);
for (KeyValue rowKV : result.raw()) {
System.out.print("行名:" + new String(rowKV.getRow()) + " ");
System.out.print("时间戳:" + rowKV.getTimestamp() + " ");
System.out.print("列族名:" + new String(rowKV.getFamily()) + " ");
System.out.print("列名:" + new String(rowKV.getQualifier()) + " ");
System.out.println("值:" + new String(rowKV.getValue()));
hbaseRes.put("*******", new String(rowKV.getValue()));
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return hbaseRes;
}
}