@InterfaceAudience.Public public class ConnectionFactory extends Object
Connection
s. Managing the lifecycle of
the Connection
s to the cluster is the responsibility of the caller. From a
Connection
, Table
implementations are retrieved with
Connection.getTable(org.apache.hadoop.hbase.TableName)
. Example:
Connection connection = ConnectionFactory.createConnection(config); Table table = connection.getTable(TableName.valueOf("table1")); try { // Use the table as needed, for a single operation and a single thread } finally { table.close(); connection.close(); }Since 2.2.0, Connection created by ConnectionFactory can contain user-specified kerberos credentials if caller has following two configurations set:
Similarly,
Connection
also returns Admin
and RegionLocator
implementations.Connection
Modifier and Type | Field and Description |
---|---|
static String |
HBASE_CLIENT_ASYNC_CONNECTION_IMPL |
Modifier | Constructor and Description |
---|---|
protected |
ConnectionFactory()
No public c.tors
|
Modifier and Type | Method and Description |
---|---|
static CompletableFuture<AsyncConnection> |
createAsyncConnection()
Call
createAsyncConnection(Configuration) using default HBaseConfiguration. |
static CompletableFuture<AsyncConnection> |
createAsyncConnection(org.apache.hadoop.conf.Configuration conf)
Call
createAsyncConnection(Configuration, User) using the given conf and a
User object created by UserProvider . |
static CompletableFuture<AsyncConnection> |
createAsyncConnection(org.apache.hadoop.conf.Configuration conf,
User user)
Create a new AsyncConnection instance using the passed
conf and user . |
static Connection |
createConnection()
Create a new Connection instance using default HBaseConfiguration.
|
static Connection |
createConnection(org.apache.hadoop.conf.Configuration conf)
Create a new Connection instance using the passed
conf instance. |
static Connection |
createConnection(org.apache.hadoop.conf.Configuration conf,
ExecutorService pool)
Create a new Connection instance using the passed
conf instance. |
static Connection |
createConnection(org.apache.hadoop.conf.Configuration conf,
ExecutorService pool,
User user)
Create a new Connection instance using the passed
conf instance. |
static Connection |
createConnection(org.apache.hadoop.conf.Configuration conf,
User user)
Create a new Connection instance using the passed
conf instance. |
public static final String HBASE_CLIENT_ASYNC_CONNECTION_IMPL
protected ConnectionFactory()
public static Connection createConnection() throws IOException
Connection.close()
on the returned connection
instance. Typical usage:
Connection connection = ConnectionFactory.createConnection(); Table table = connection.getTable(TableName.valueOf("mytable")); try { table.get(...); ... } finally { table.close(); connection.close(); }
conf
IOException
public static Connection createConnection(org.apache.hadoop.conf.Configuration conf) throws IOException
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. Connection.close()
on the returned connection
instance. Typical usage:
Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(TableName.valueOf("mytable")); try { table.get(...); ... } finally { table.close(); connection.close(); }
conf
- configurationconf
IOException
public static Connection createConnection(org.apache.hadoop.conf.Configuration conf, ExecutorService pool) throws IOException
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. Connection.close()
on the returned connection
instance. Typical usage:
Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(TableName.valueOf("mytable")); try { table.get(...); ... } finally { table.close(); connection.close(); }
conf
- configurationpool
- the thread pool to use for batch operationsconf
IOException
public static Connection createConnection(org.apache.hadoop.conf.Configuration conf, User user) throws IOException
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. Connection.close()
on the returned connection
instance. Typical usage:
Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(TableName.valueOf("table1")); try { table.get(...); ... } finally { table.close(); connection.close(); }
conf
- configurationuser
- the user the connection is forconf
IOException
public static Connection createConnection(org.apache.hadoop.conf.Configuration conf, ExecutorService pool, User user) throws IOException
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. Connection.close()
on the returned connection
instance. Typical usage:
Connection connection = ConnectionFactory.createConnection(conf); Table table = connection.getTable(TableName.valueOf("table1")); try { table.get(...); ... } finally { table.close(); connection.close(); }
conf
- configurationuser
- the user the connection is forpool
- the thread pool to use for batch operationsconf
IOException
public static CompletableFuture<AsyncConnection> createAsyncConnection()
createAsyncConnection(Configuration)
using default HBaseConfiguration.createAsyncConnection(Configuration)
public static CompletableFuture<AsyncConnection> createAsyncConnection(org.apache.hadoop.conf.Configuration conf)
createAsyncConnection(Configuration, User)
using the given conf
and a
User object created by UserProvider
. The given conf
will also be used to
initialize the UserProvider
.conf
- configurationcreateAsyncConnection(Configuration, User)
,
UserProvider
public static CompletableFuture<AsyncConnection> createAsyncConnection(org.apache.hadoop.conf.Configuration conf, User user)
conf
and user
.
AsyncConnection 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 Closeable.close()
on the returned
connection instance.
Usually you should only create one AsyncConnection instance in your code and use it everywhere as it is thread safe.
conf
- configurationuser
- the user the asynchronous connection is forCopyright © 2007–2021 The Apache Software Foundation. All rights reserved.