@InterfaceAudience.Public @InterfaceStability.Evolving 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(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(); }Similarly,
Connection
also returns Admin
and RegionLocator
implementations.
This class replaces HConnectionManager
, which is now deprecated.Connection
Modifier | Constructor and Description |
---|---|
protected |
ConnectionFactory()
No public c.tors
|
Modifier and Type | Method and Description |
---|---|
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 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
Copyright © 2007–2016 The Apache Software Foundation. All rights reserved.