hbase开发-Connection连接创建

hbase中Connection创建,

HConnectionManager.getConnection(HBaseConfiguration.create());

HConnectionManager.createConnection(HBaseConfiguration.create();

//1.3.x及以前使用一下方式创建,HConnectionManager是ConnectionFactory子类,2.x及以上使用一下方式创建链接

Connection hbaseConn = ConnectionFactory.createConnection(HBaseConfiguration.create());

Admin admin = hbaseConn.getAdmin();

通过源码可以看到,Connection接口继承Abortable, Closeable。

Abortable接口,提供两个方法,用于检测服务端或者客户端链接及终止。

hbase开发-Connection连接创建_第1张图片

Closeable接口,提供关闭资源方法。

hbase开发-Connection连接创建_第2张图片

Connection接口:

hbase开发-Connection连接创建_第3张图片

HBaseConfiguration.create(): 加载hbase配置文件属性,默认加载当前类根目录下的配置文件hbase-default.xml,然后加载hbase-site.xml,后者会覆盖前者中的属性信息。

hbase开发-Connection连接创建_第4张图片

hbase开发-Connection连接创建_第5张图片

ConnectionFactory:链接工厂,用于创建Connection链接,如果没有conf配置,则默认加载类根据下配置文件,如果有则使用当前配置。提供以下多种方式创建链接。

hbase开发-Connection连接创建_第6张图片

客户端调用使用自带配置文件hbase-site.xml,将改文件放在项目根目录下即可。该文件中至少需要配置一下信息:



    
        hbase.rootdir
        hdfs://192.168.2.219:8020/hbase
    

    
        hbase.zookeeper.quorum
        192.168.2.219
    

    
        hbase.zookeeper.property.clientPort
        2181
    

    
        zookeeper.znode.parent
        /hbase
    

hbase开发-Connection连接创建_第7张图片

hbase开发-Connection连接创建_第8张图片

ConnectionImplementation:  创建Connection接口实现类(org.apache.hadoop.hbase.client.ConnectionImplementation)对象

hbase开发-Connection连接创建_第9张图片

constructor.newInstance(conf, pool, user);通过反射创建 ConnectionImplementation对象

hbase开发-Connection连接创建_第10张图片

你可能感兴趣的:(hbase,大数据-hadoop)