@InterfaceAudience.Public @InterfaceStability.Evolving public class ConnectionFactory extends java.lang.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(Configuration conf)
Create a new Connection instance using the passed
conf instance. |
static Connection |
createConnection(Configuration conf,
java.util.concurrent.ExecutorService pool)
Create a new Connection instance using the passed
conf instance. |
static Connection |
createConnection(Configuration conf,
java.util.concurrent.ExecutorService pool,
User user)
Create a new Connection instance using the passed
conf instance. |
static Connection |
createConnection(Configuration conf,
User user)
Create a new Connection instance using the passed
conf instance. |
public static Connection createConnection() throws java.io.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();
}
confjava.io.IOExceptionpublic static Connection createConnection(Configuration conf) throws java.io.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 - configurationconfjava.io.IOExceptionpublic static Connection createConnection(Configuration conf, java.util.concurrent.ExecutorService pool) throws java.io.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 operationsconfjava.io.IOExceptionpublic static Connection createConnection(Configuration conf, User user) throws java.io.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 forconfjava.io.IOExceptionpublic static Connection createConnection(Configuration conf, java.util.concurrent.ExecutorService pool, User user) throws java.io.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 operationsconfjava.io.IOException