@InterfaceAudience.Public @InterfaceStability.Evolving public class ConnectionFactory extends Object
Connections.
Managing the lifecycle of the Connections 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();
}
confIOExceptionpublic 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 - configurationconfIOExceptionpublic 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 operationsconfIOExceptionpublic 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 forconfIOExceptionpublic 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 operationsconfIOExceptionCopyright © 2007–2016 The Apache Software Foundation. All rights reserved.