Examples of HTableInterface


Examples of org.apache.hadoop.hbase.client.HTableInterface

   */
  private void batch(byte[] tableName, List<Row> rows) throws IOException {
    if (rows.isEmpty()) {
      return;
    }
    HTableInterface table = null;
    try {
      table = this.pool.getTable(tableName);
      table.batch(rows);
      this.metrics.appliedOpsRate.inc(rows.size());
    } catch (InterruptedException ix) {
      throw new IOException(ix);
    } finally {
      if (table != null) {
        table.close();
      }
    }
  }
View Full Code Here

Examples of org.apache.hadoop.hbase.client.HTableInterface

  @Override
  public <T> T execute(String tableName, TableCallback<T> action) {
    Assert.notNull(action, "Callback object must not be null");
    Assert.notNull(tableName, "No table specified");

    HTableInterface table = getTable(tableName);

    try {
      boolean previousFlushSetting = applyFlushSetting(table);
      T result = action.doInTable(table);
      flushIfNecessary(table, previousFlushSetting);
View Full Code Here

Examples of org.apache.hadoop.hbase.client.HTableInterface

    Set<String> boundTables = new LinkedHashSet<String>();

    for (String tableName : tableNames) {
      if (!HbaseSynchronizationManager.hasResource(tableName)) {
        boundTables.add(tableName);
        HTableInterface table = HbaseUtils.getHTable(tableName, getConfiguration(), getCharset(), getTableFactory());
        HbaseSynchronizationManager.bindResource(tableName, table);
      }
    }

    try {
      Object retVal = methodInvocation.proceed();
      return retVal;
    } catch (Exception ex) {
      if (this.exceptionConversionEnabled) {
        throw convertHBaseException(ex);
      }
      else {
        throw ex;
      }
    } finally {
      for (String tableName : boundTables) {
        HTableInterface table = (HTableInterface) HbaseSynchronizationManager.unbindResourceIfPossible(tableName);
        if (table != null) {
          HbaseUtils.releaseTable(tableName, table);
        }
        else {
          log.warn("Table [" + tableName + "] unbound from the thread by somebody else; cannot guarantee proper clean-up");
View Full Code Here

Examples of org.apache.hadoop.hbase.client.HTableInterface

  public static HTableInterface getHTable(String tableName, Configuration configuration, Charset charset, HTableInterfaceFactory tableFactory) {
    if (HbaseSynchronizationManager.hasResource(tableName)) {
      return (HTable) HbaseSynchronizationManager.getResource(tableName);
    }

    HTableInterface t = null;
    try {
      if (tableFactory != null) {
        t = tableFactory.createHTableInterface(configuration, tableName.getBytes(charset));
      }
      else {
View Full Code Here

Examples of org.apache.hadoop.hbase.client.HTableInterface

    // set ThreadLocal Map if none found
    if (map == null) {
      map = new LinkedHashMap<String, HTableInterface>();
      resources.set(map);
    }
    HTableInterface oldValue = map.put(key, value);
    if (oldValue != null) {
      throw new IllegalStateException("Already value [" + oldValue + "] for key [" + key
          + "] bound to thread [" + Thread.currentThread().getName() + "]");
    }
    if (logger.isTraceEnabled()) {
View Full Code Here

Examples of org.apache.hadoop.hbase.client.HTableInterface

   * @return the previously bound value (usually the active resource object)
   * @throws IllegalStateException if there is no value bound to the thread
   * @see ResourceTransactionManager#getResourceFactory()
   */
  public static HTableInterface unbindResource(String key) throws IllegalStateException {
    HTableInterface value = doUnbindResource(key);
    if (value == null) {
      throw new IllegalStateException("No value for key [" + key + "] bound to thread ["
          + Thread.currentThread().getName() + "]");
    }
    return value;
View Full Code Here

Examples of org.apache.hadoop.hbase.client.HTableInterface

  private static HTableInterface doUnbindResource(Object actualKey) {
    Map<String, HTableInterface> map = resources.get();
    if (map == null) {
      return null;
    }
    HTableInterface value = map.remove(actualKey);
    // Remove entire ThreadLocal if empty...
    if (map.isEmpty()) {
      resources.remove();
    }
View Full Code Here

Examples of org.apache.hadoop.hbase.client.HTableInterface

     s.addFamily(COLUMN_FAMILY);
     return s;
   }
  
   public void addWordCount(WordCount w) throws IOException{
     HTableInterface words = pool.getTable(TABLE_NAME);
     Put p = mkPut(w);
     words.put(p);
     words.close();
   }
View Full Code Here

Examples of org.apache.hadoop.hbase.client.HTableInterface

     words.put(p);
     words.close();
   }
  
   public List<WordCount> getWordCount(String word) throws IOException {
     HTableInterface words = pool.getTable(TABLE_NAME);
     Get g = mkGet(word);
     Result result = words.get(g);
     if (result.isEmpty()) {
          log.info(String.format("word %s not found.", word));
          return null;
     }

     List<WordCount> wordCounts = WordCount.GetWordCountFromResults(result);
     words.close();
     return wordCounts;
   }
View Full Code Here

Examples of org.apache.hadoop.hbase.client.HTableInterface

     words.close();
     return wordCounts;
   }
  
   public void deleteUser(String word) throws IOException {
     HTableInterface words = pool.getTable(TABLE_NAME);

       Delete d = mkDel(word);
       words.delete(d);

       words.close();
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.