Class ConnectionFactory

java.lang.Object
org.apache.hadoop.hbase.client.ConnectionFactory

@Public public class ConnectionFactory extends Object
A non-instantiable class that manages creation of 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(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:
  • hbase.client.keytab.file, points to a valid keytab on the local filesystem
  • hbase.client.kerberos.principal, gives the Kerberos principal to use
By this way, caller can directly connect to kerberized cluster without caring login and credentials renewal logic in application.
 
Similarly, Connection also returns Admin and RegionLocator implementations.
Since:
0.99.0
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • createConnection

      public static Connection createConnection() throws IOException
      Create a new Connection instance using default HBaseConfiguration. 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. Typical usage:
       try (Connection connection = ConnectionFactory.createConnection(conf);
         Table table = connection.getTable(TableName.valueOf("table1"))) {
         table.get(...);
         ...
       }
       
      Returns:
      Connection object for conf
      Throws:
      IOException
    • createConnection

      public static Connection createConnection(URI connectionUri) throws IOException
      Create a new Connection instance using default HBaseConfiguration. 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. Typical usage:
       try (Connection connection = ConnectionFactory.createConnection(conf);
         Table table = connection.getTable(TableName.valueOf("table1"))) {
         table.get(...);
         ...
       }
       
      Parameters:
      connectionUri - the connection uri for the hbase cluster
      Returns:
      Connection object for conf
      Throws:
      IOException
    • createConnection

      public static Connection createConnection(org.apache.hadoop.conf.Configuration conf) throws IOException
      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(if used), meta cache, and connections to region servers and masters.
      The caller is responsible for calling Connection.close() on the returned connection instance. Typical usage:
       try (Connection connection = ConnectionFactory.createConnection(conf);
         Table table = connection.getTable(TableName.valueOf("table1"))) {
         table.get(...);
         ...
       }
       
      Parameters:
      conf - configuration
      Returns:
      Connection object for conf
      Throws:
      IOException
    • createConnection

      public static Connection createConnection(URI connectionUri, org.apache.hadoop.conf.Configuration conf) throws IOException
      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(if used), meta cache, and connections to region servers and masters.
      The caller is responsible for calling Connection.close() on the returned connection instance. Typical usage:
       try (Connection connection = ConnectionFactory.createConnection(conf);
         Table table = connection.getTable(TableName.valueOf("table1"))) {
         table.get(...);
         ...
       }
       
      Parameters:
      connectionUri - the connection uri for the hbase cluster
      conf - configuration
      Returns:
      Connection object for conf
      Throws:
      IOException
    • createConnection

      public static Connection createConnection(org.apache.hadoop.conf.Configuration conf, ExecutorService pool) throws IOException
      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(if used), meta cache, and connections to region servers and masters.
      The caller is responsible for calling Connection.close() on the returned connection instance. Typical usage:
       try (Connection connection = ConnectionFactory.createConnection(conf);
         Table table = connection.getTable(TableName.valueOf("table1"))) {
         table.get(...);
         ...
       }
       
      Parameters:
      conf - configuration
      pool - the thread pool to use for batch operations
      Returns:
      Connection object for conf
      Throws:
      IOException
    • createConnection

      public static Connection createConnection(URI connectionUri, org.apache.hadoop.conf.Configuration conf, ExecutorService pool) throws IOException
      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(if used), meta cache, and connections to region servers and masters.
      The caller is responsible for calling Connection.close() on the returned connection instance. Typical usage:
       try (Connection connection = ConnectionFactory.createConnection(conf);
         Table table = connection.getTable(TableName.valueOf("table1"))) {
         table.get(...);
         ...
       }
       
      Parameters:
      connectionUri - the connection uri for the hbase cluster
      conf - configuration
      pool - the thread pool to use for batch operations
      Returns:
      Connection object for conf
      Throws:
      IOException
    • createConnection

      public static Connection createConnection(org.apache.hadoop.conf.Configuration conf, User user) throws IOException
      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(if used), meta cache, and connections to region servers and masters.
      The caller is responsible for calling Connection.close() on the returned connection instance. Typical usage:
       try (Connection connection = ConnectionFactory.createConnection(conf);
         Table table = connection.getTable(TableName.valueOf("table1"))) {
         table.get(...);
         ...
       }
       
      Parameters:
      conf - configuration
      user - the user the connection is for
      Returns:
      Connection object for conf
      Throws:
      IOException
    • createConnection

      public static Connection createConnection(URI connectionUri, org.apache.hadoop.conf.Configuration conf, User user) throws IOException
      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(if used), meta cache, and connections to region servers and masters.
      The caller is responsible for calling Connection.close() on the returned connection instance. Typical usage:
       try (Connection connection = ConnectionFactory.createConnection(conf);
         Table table = connection.getTable(TableName.valueOf("table1"))) {
         table.get(...);
         ...
       }
       
      Parameters:
      connectionUri - the connection uri for the hbase cluster
      conf - configuration
      user - the user the connection is for
      Returns:
      Connection object for conf
      Throws:
      IOException
    • createConnection

      public static Connection createConnection(org.apache.hadoop.conf.Configuration conf, ExecutorService pool, User user) throws IOException
      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(if used), meta cache, and connections to region servers and masters.
      The caller is responsible for calling Connection.close() on the returned connection instance. Typical usage:
       try (Connection connection = ConnectionFactory.createConnection(conf);
         Table table = connection.getTable(TableName.valueOf("table1"))) {
         table.get(...);
         ...
       }
       
      Parameters:
      conf - configuration
      user - the user the connection is for
      pool - the thread pool to use for batch operations
      Returns:
      Connection object for conf
      Throws:
      IOException
    • createConnection

      public static Connection createConnection(URI connectionUri, org.apache.hadoop.conf.Configuration conf, ExecutorService pool, User user) throws IOException
      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(if used), meta cache, and connections to region servers and masters.
      The caller is responsible for calling Connection.close() on the returned connection instance. Typical usage:
       try (Connection connection = ConnectionFactory.createConnection(conf);
         Table table = connection.getTable(TableName.valueOf("table1"))) {
         table.get(...);
         ...
       }
       
      Parameters:
      connectionUri - the connection uri for the hbase cluster
      conf - configuration
      user - the user the connection is for
      pool - the thread pool to use for batch operations
      Returns:
      Connection object for conf
      Throws:
      IOException
    • createConnection

      public static Connection createConnection(org.apache.hadoop.conf.Configuration conf, ExecutorService pool, User user, Map<String,byte[]> connectionAttributes) throws IOException
      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(if used), meta cache, and connections to region servers and masters.
      The caller is responsible for calling Connection.close() on the returned connection instance. Typical usage:
       try (Connection connection = ConnectionFactory.createConnection(conf);
         Table table = connection.getTable(TableName.valueOf("table1"))) {
         table.get(...);
         ...
       }
       
      Parameters:
      conf - configuration
      user - the user the connection is for
      pool - the thread pool to use for batch operations
      connectionAttributes - attributes to be sent along to server during connection establish
      Returns:
      Connection object for conf
      Throws:
      IOException
    • createConnection

      public static Connection createConnection(URI connectionUri, org.apache.hadoop.conf.Configuration conf, ExecutorService pool, User user, Map<String,byte[]> connectionAttributes) throws IOException
      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(if used), meta cache, and connections to region servers and masters.
      The caller is responsible for calling Connection.close() on the returned connection instance. Typical usage:
       Connection connection = ConnectionFactory.createConnection(conf);
       Table table = connection.getTable(TableName.valueOf("table1"));
       try (Connection connection = ConnectionFactory.createConnection(conf);
         Table table = connection.getTable(TableName.valueOf("table1"))) {
         table.get(...);
         ...
       }
       
      Parameters:
      connectionUri - the connection uri for the hbase cluster
      conf - configuration
      user - the user the connection is for
      pool - the thread pool to use for batch operations
      connectionAttributes - attributes to be sent along to server during connection establish
      Returns:
      Connection object for conf
      Throws:
      IOException
    • createAsyncConnection

      Call createAsyncConnection(Configuration) using default HBaseConfiguration.
      Returns:
      AsyncConnection object wrapped by CompletableFuture
      See Also:
    • createAsyncConnection

      Call createAsyncConnection(URI, Configuration) using default HBaseConfiguration.
      Parameters:
      connectionUri - the connection uri for the hbase cluster
      Returns:
      AsyncConnection object wrapped by CompletableFuture
      See Also:
    • createAsyncConnection

      public 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. The given conf will also be used to initialize the UserProvider.
      Parameters:
      conf - configuration
      Returns:
      AsyncConnection object wrapped by CompletableFuture
      See Also:
    • createAsyncConnection

      public static CompletableFuture<AsyncConnection> createAsyncConnection(URI connectionUri, org.apache.hadoop.conf.Configuration conf)
      Call createAsyncConnection(Configuration, User) using the given connectionUri, conf and a User object created by UserProvider. The given conf will also be used to initialize the UserProvider.
      Parameters:
      connectionUri - the connection uri for the hbase cluster
      conf - configuration
      Returns:
      AsyncConnection object wrapped by CompletableFuture
      See Also:
    • createAsyncConnection

      public static CompletableFuture<AsyncConnection> createAsyncConnection(org.apache.hadoop.conf.Configuration conf, User user)
      Create a new AsyncConnection instance using the passed 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.

      Parameters:
      conf - configuration
      user - the user the asynchronous connection is for
      Returns:
      AsyncConnection object wrapped by CompletableFuture
    • createAsyncConnection

      public static CompletableFuture<AsyncConnection> createAsyncConnection(URI connectionUri, org.apache.hadoop.conf.Configuration conf, User user)
      Create a new AsyncConnection instance using the passed connectionUri, conf and user. AsyncConnection encapsulates all housekeeping for a connection to the cluster. All tables and interfaces created from returned connection share zookeeper connection(if used), 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.

      Parameters:
      connectionUri - the connection uri for the hbase cluster
      conf - configuration
      user - the user the asynchronous connection is for
      Returns:
      AsyncConnection object wrapped by CompletableFuture
    • createAsyncConnection

      public static CompletableFuture<AsyncConnection> createAsyncConnection(org.apache.hadoop.conf.Configuration conf, User user, Map<String,byte[]> connectionAttributes)
      Create a new AsyncConnection instance using the passed 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.

      Parameters:
      conf - configuration
      user - the user the asynchronous connection is for
      connectionAttributes - attributes to be sent along to server during connection establish
      Returns:
      AsyncConnection object wrapped by CompletableFuture
    • createAsyncConnection

      public static CompletableFuture<AsyncConnection> createAsyncConnection(URI connectionUri, org.apache.hadoop.conf.Configuration conf, User user, Map<String,byte[]> connectionAttributes)
      Create a new AsyncConnection instance using the passed connectionUri, conf and user. AsyncConnection encapsulates all housekeeping for a connection to the cluster. All tables and interfaces created from returned connection share zookeeper connection(if used), 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.

      Parameters:
      connectionUri - the connection uri for the hbase cluster
      conf - configuration
      user - the user the asynchronous connection is for
      connectionAttributes - attributes to be sent along to server during connection establish
      Returns:
      AsyncConnection object wrapped by CompletableFuture