當前位置: 首頁>>代碼示例>>Java>>正文


Java HTable.getConnection方法代碼示例

本文整理匯總了Java中org.apache.hadoop.hbase.client.HTable.getConnection方法的典型用法代碼示例。如果您正苦於以下問題:Java HTable.getConnection方法的具體用法?Java HTable.getConnection怎麽用?Java HTable.getConnection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.hbase.client.HTable的用法示例。


在下文中一共展示了HTable.getConnection方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setHTable

import org.apache.hadoop.hbase.client.HTable; //導入方法依賴的package包/類
/**
 * Allows subclasses to set the {@link HTable}.
 *
 * Will attempt to reuse the underlying Connection for our own needs, including
 * retreiving an Admin interface to the HBase cluster.
 *
 * @param table  The table to get the data from.
 * @throws IOException 
 * @deprecated Use {@link #initializeTable(Connection, TableName)} instead.
 */
@Deprecated
protected void setHTable(HTable table) throws IOException {
  this.table = table;
  this.connection = table.getConnection();
  try {
    this.regionLocator = table.getRegionLocator();
    this.admin = this.connection.getAdmin();
  } catch (NeedUnmanagedConnectionException exception) {
    LOG.warn("You are using an HTable instance that relies on an HBase-managed Connection. " +
        "This is usually due to directly creating an HTable, which is deprecated. Instead, you " +
        "should create a Connection object and then request a Table instance from it. If you " +
        "don't need the Table instance for your own use, you should instead use the " +
        "TableInputFormatBase.initalizeTable method directly.");
    LOG.info("Creating an additional unmanaged connection because user provided one can't be " +
        "used for administrative actions. We'll close it when we close out the table.");
    LOG.debug("Details about our failure to request an administrative interface.", exception);
    // Do we need a "copy the settings from this Connection" method? are things like the User
    // properly maintained by just looking again at the Configuration?
    this.connection = ConnectionFactory.createConnection(this.connection.getConfiguration());
    this.regionLocator = this.connection.getRegionLocator(table.getName());
    this.admin = this.connection.getAdmin();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:34,代碼來源:TableInputFormatBase.java

示例2: doBulkLoad

import org.apache.hadoop.hbase.client.HTable; //導入方法依賴的package包/類
/**
 * Perform a bulk load of the given directory into the given
 * pre-existing table.  This method is not threadsafe.
 *
 * @param hfofDir the directory that was provided as the output path
 * of a job using HFileOutputFormat
 * @param table the table to load into
 * @throws TableNotFoundException if table does not yet exist
 */
@SuppressWarnings("deprecation")
public void doBulkLoad(Path hfofDir, final HTable table)
  throws TableNotFoundException, IOException
{
  Admin admin = null;
  Table t = table;
  Connection conn = table.getConnection();
  boolean closeConnWhenFinished = false;
  try {
    if (conn instanceof ClusterConnection && ((ClusterConnection) conn).isManaged()) {
      LOG.warn("managed connection cannot be used for bulkload. Creating unmanaged connection.");
      // can only use unmanaged connections from here on out.
      conn = ConnectionFactory.createConnection(table.getConfiguration());
      t = conn.getTable(table.getName());
      closeConnWhenFinished = true;
      if (conn instanceof ClusterConnection && ((ClusterConnection) conn).isManaged()) {
        throw new RuntimeException("Failed to create unmanaged connection.");
      }
      admin = conn.getAdmin();
    } else {
      admin = conn.getAdmin();
    }
    try (RegionLocator rl = conn.getRegionLocator(t.getName())) {
      doBulkLoad(hfofDir, admin, t, rl);
    }
  } finally {
    if (admin != null) admin.close();
    if (closeConnWhenFinished) {
      t.close();
      conn.close();
    }
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:43,代碼來源:LoadIncrementalHFiles.java


注:本文中的org.apache.hadoop.hbase.client.HTable.getConnection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。