public static String getPoolAddress( final String hostAddress, final int registryPort, final String poolId) { try { return new RMIAddress(hostAddress, registryPort, PoolConfig.getPoolName(poolId)).toString(); } catch (final UnknownHostException e) { } catch (final MalformedURLException e) { } return null; }
public void testPool() throws IOException { PoolConfig config = new PoolConfig(); config.setMaxTotal(20); config.setMaxIdle(5); config.setMaxWaitMillis(1000); config.setTestOnBorrow(true); /* properties */ Properties props = new Properties(); props.setProperty("hbase.zookeeper.quorum", "host1,host2,host3"); props.setProperty("hbase.zookeeper.property.clientPort", "2181"); props.setProperty("hbase.master", "host1:60000"); props.setProperty("hbase.rootdir", "hdfs://host1:9000/hbase"); /* connection pool */ HbaseConnectionPool pool = new HbaseConnectionPool(config, props); HTableInterface table = null; HConnection conn = pool.getConnection(); table = conn.getTable(TableName.valueOf("relation")); Get get = new Get(Bytes.toBytes("rowKey")); Result r = table.get(get); for (Cell cell : r.rawCells()) { System.out.println( "Rowkey : " + Bytes.toString(r.getRow()) + " Familiy:Quilifier : " + Bytes.toString(CellUtil.cloneQualifier(cell)) + " Value : " + Bytes.toString(CellUtil.cloneValue(cell))); } table.close(); System.out.println(table); pool.returnConnection(conn); pool.close(); }