最近在试用Hbase1.0的客户端API,发觉变化还是挺大(以前版本也不熟)。到处都是deprecated。

现在应该是这样子:

Configuration  conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "quorum1,quorum2,quorum3");
conf.set("hbase.zookeeper.property.clientPort", "2181");

connection = ConnectionFactory.createConnection(conf);// HBase 0.99+

//connection = HConnectionManager.createConnection(conf); // HBase <0.99

Table table = connection.getTable(TableName.valueOf("TestTable"));

新的客户端API中,Connection处于关键位置,以下api说明翻译下:

关于 Connection接口的说明:
A cluster connection
encapsulating lower level individual connections to actual servers and a
connection to zookeeper. Connections are instantiated through the ConnectionFactory class.
The lifecycle of the connection is managed by the caller, who has to close() the
connection to release the resources.

The connection object contains logic to find the master, locate
regions out on the cluster, keeps a cache of locations and then knows
how to re-calibrate after they move. The individual connections to
servers, meta cache, zookeeper connection, etc are all
shared by the Table and Admin instances
obtained from this connection.

Connection creation is a heavy-weight operation. Connection
implementations are thread-safe, so that the client can create a
connection once, and share it with different threads. Table and Admin instances,

on the other hand, are light-weight and are not thread-safe. Typically,
a single connection per client application is instantiated and every
thread will obtain its own Table instance. Caching or pooling of Table and Admin is
not recommended.

This class replaces HConnection,
which is now deprecated.

Connection封装了底层与各实际服务器的连接以及与zookeeper的连接。Connection通过 ConnectionFactory类实例化。Connection的生命周期由调用者维护,调用者通过调用close(),释放资源。
连接对象包含发现master,定位region,缓存region位置一边当region移动后,重新矫正位置。通往各服务器的连接,meta数据缓存,zookeeper连接等,与通过Connection获取的Table,Admin实例都是共享的。
创建Connection是重量级
操作。
Connection是线程安全的,因此,多个客户端线程可以共享一个Connection。Table和Admin实例,相反地,是轻量级的并且非线程
安全。典型的用法,一个客户端程序共享一个单独的Connection,每一个线程获取自己的Table实例。不建议缓存或者池化
(pooling)Table、Admin。

关于 ConnectionFactory.createConnection函数的说明:

public static Connection createConnection(org.apache.hadoop.conf.Configuration conf)
Create a new Connection instance using the passed conf instance. Connection encapsulates all housekeeping for a connection to the cluster. All tables and interfaces created from returned connection share zookeeper connection, meta cache, and connections to region servers and masters. 
The caller is responsible for calling Connection.close() on
the returned connection instance.
Connection封装了连接到集群的所有维护工作。通过返回的connection生成的table、接口等共享zookeeper连接,meta缓存,到region server以及master的连接。
调用者负责释放connection实例。
Similarly, Connection also
returns Admin and RegionLocator implementations
类似返回table接口,Connection还可以返回Admin,RegionLoacator实例。

Hbase1.0 客户端api的更多相关文章

  1. HBase1.0以上版本的API改变

    HBase1.0以上版本已经废弃了 HTableInterface,HTable,HBaseAdmin等API的使用,新增了一些API来实现之前的功能: Connectioninterface: Co ...

  2. HBase1.0以上版本号的API改变

    HBase1.0以上版本号已经废弃了 HTableInterface,HTable,HBaseAdmin等API的使用.新增了一些API来实现之前的功能: Connectioninterface: C ...

  3. SignalR的Javascript客户端API使用方式整理

    SignalR的服务端提供了两种实现方式,分别是PersistentConnection和Hub,这两种方式的侧重点不同: PersistentConnection更接近于底层,编程接口比较简单,传输 ...

  4. JAVA客户端API调用memcached两种方式

    1. memcached client for java客户端API:memcached client for java 引入jar包:java-memcached-2.6.2.jar package ...

  5. Redis C客户端API - God's blog - 博客频道 - CSDN.NET

    Redis C客户端API - God's blog - 博客频道 - CSDN.NET Redis安装步骤: 1.redis server安装 wget http://redis.googlecod ...

  6. 通过 Jersey Http请求头,Http响应头,客户端 API 调用 REST 风格的 Web 服务

    原地址:http://blog.csdn.net/li575098618/article/details/47853263 Jersey 1.0 是一个开源的.可以用于生产环境的 JAX-RS(RES ...

  7. Jersey客户端API调用REST风格的Web服务

    Jersey 客户端 API 基础 jersey-1.14.jar 密码: cxug 要开始使用 Jersey 客户端 API,你首先需要创建一个 com.sun.jersey .api.client ...

  8. RabbitMQ系列教程之七:RabbitMQ的 C# 客户端 API 的简介

    今天这篇博文是我翻译的RabbitMQ的最后一篇文章了,介绍一下RabbitMQ的C#开发的接口.好了,言归正传吧. Net/C# 客户端 API简介1.主要的命名空间,接口和类  定义核心的API的 ...

  9. 从头编写 asp.net core 2.0 web api 基础框架 (1)

    工具: 1.Visual Studio 2017 V15.3.5+ 2.Postman (Chrome的App) 3.Chrome (最好是) 关于.net core或者.net core 2.0的相 ...

随机推荐

  1. slf4i + logback 配置

    一.所需jar包: slf4j-api-1.6.1.jar logback-classic-0.9.24.jar logback-core-0.9.24.jar 二.logback.xml配置示例: ...

  2. js 控制展开折叠 div html dom

    js 控制展开折叠 div    html dom <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ...

  3. php获取当前页面的完整url

    javascript实现: top.location.href 顶级窗口的地址 this.location.href 当前窗口的地址 php实现: //测试网址: http://localhost/b ...

  4. C语言里面捕获错误机制

    在C语言中异常处理一般有这么几种方式: 1.使用标准C库提供了abort()和exit()两个函数,它们可以强行终止程序的运行,其声明处于<stdlib.h>头文件中. 2.使用asser ...

  5. BootCDN和npm

    稳定.快速.免费的开源项目 CDN 服务 BootCDN: jQuery3 <script type="text/javascript" src="http://c ...

  6. Hibernate的持久化类状态

    Hibernate的持久化类状态 持久化类:就是一个实体类 与 数据库表建立了映射. Hibernate为了方便管理持久化类,将持久化类分成了三种状态. 瞬时态 transient (临时态):持久化 ...

  7. 【java IO File】统计项目代码总共多少行

    统计项目代码总共有多少行 思想: 1.首先将不需要迭代的文件夹,保存在集合中,不满足的就是需要迭代的文件夹 2.将需要进行统计行数的代码文件保存在集合中,满足的就是需要计算文件行数的文件 3.迭代方法 ...

  8. java 线程演示

    package unit8; public class Mainthread { public static void main(String[] args) { Thread t = new Thr ...

  9. Attribute在.net编程中的应用

    Attribute FYI Link: Attribute在.net编程中的应用(一) Attribute在.net编程中的应用(二) Attribute在.net编程中的应用(三) Attribut ...

  10. Swift3.0语言教程使用URL字符串

    Swift3.0语言教程使用URL字符串 Swift3.0语言教程使用URL字符串,和路径一样,URL其实也是字符串,我们可以将这些字符串称为URL字符串.本小节将讲解URL字符串的使用. 1.编码 ...