当前位置: 首页>>代码示例>>Java>>正文


Java Batch类代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.client.coprocessor.Batch的典型用法代码示例。如果您正苦于以下问题:Java Batch类的具体用法?Java Batch怎么用?Java Batch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Batch类属于org.apache.hadoop.hbase.client.coprocessor包,在下文中一共展示了Batch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processBatchCallback

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
/**
 * Randomly pick a connection and process the batch of actions for a given table
 * @param actions the actions
 * @param tableName table name
 * @param results the results array
 * @param callback 
 * @throws IOException
 */
@SuppressWarnings("deprecation")
public <R> void processBatchCallback(List<? extends Row> actions, TableName tableName,
    Object[] results, Batch.Callback<R> callback) throws IOException {
  // Currently used by RegionStateStore
  // A deprecated method is used as multiple threads accessing RegionStateStore do a single put
  // and htable is not thread safe. Alternative would be to create an Htable instance for each 
  // put but that is not very efficient.
  // See HBASE-11610 for more details.
  try {
    hConnections[ThreadLocalRandom.current().nextInt(noOfConnections)].processBatchCallback(
      actions, tableName, this.batchPool, results, callback);
  } catch (InterruptedException e) {
    throw new InterruptedIOException(e.getMessage());
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:24,代码来源:MultiHConnection.java

示例2: sum

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
private static Map<byte [], Long> sum(final Table table, final byte [] family,
  final byte [] qualifier, final byte [] start, final byte [] end)
    throws ServiceException, Throwable {
return table.coprocessorService(ColumnAggregationProtos.ColumnAggregationService.class,
    start, end,
  new Batch.Call<ColumnAggregationProtos.ColumnAggregationService, Long>() {
    @Override
    public Long call(ColumnAggregationProtos.ColumnAggregationService instance)
    throws IOException {
      BlockingRpcCallback<ColumnAggregationProtos.SumResponse> rpcCallback =
          new BlockingRpcCallback<ColumnAggregationProtos.SumResponse>();
      ColumnAggregationProtos.SumRequest.Builder builder =
        ColumnAggregationProtos.SumRequest.newBuilder();
      builder.setFamily(ByteStringer.wrap(family));
      if (qualifier != null && qualifier.length > 0) {
        builder.setQualifier(ByteStringer.wrap(qualifier));
      }
      instance.sum(null, builder.build(), rpcCallback);
      return rpcCallback.get().getSum();
    }
  });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:23,代码来源:TestCoprocessorTableEndpoint.java

示例3: sum

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
private Map<byte [], Long> sum(final Table table, final byte [] family,
    final byte [] qualifier, final byte [] start, final byte [] end)
throws ServiceException, Throwable {
  return table.coprocessorService(ColumnAggregationProtos.ColumnAggregationService.class,
      start, end,
    new Batch.Call<ColumnAggregationProtos.ColumnAggregationService, Long>() {
      @Override
      public Long call(ColumnAggregationProtos.ColumnAggregationService instance)
      throws IOException {
        BlockingRpcCallback<ColumnAggregationProtos.SumResponse> rpcCallback =
            new BlockingRpcCallback<ColumnAggregationProtos.SumResponse>();
        ColumnAggregationProtos.SumRequest.Builder builder =
          ColumnAggregationProtos.SumRequest.newBuilder();
        builder.setFamily(ByteStringer.wrap(family));
        if (qualifier != null && qualifier.length > 0) {
          builder.setQualifier(ByteStringer.wrap(qualifier));
        }
        instance.sum(null, builder.build(), rpcCallback);
        return rpcCallback.get().getSum();
      }
    });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:23,代码来源:TestCoprocessorEndpoint.java

示例4: hello

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
private Map<byte [], String> hello(final Table table, final String send, final byte [] start,
    final byte [] end)
throws ServiceException, Throwable {
  return table.coprocessorService(PingProtos.PingService.class,
      start, end,
      new Batch.Call<PingProtos.PingService, String>() {
        @Override
        public String call(PingProtos.PingService instance) throws IOException {
          BlockingRpcCallback<PingProtos.HelloResponse> rpcCallback =
            new BlockingRpcCallback<PingProtos.HelloResponse>();
          PingProtos.HelloRequest.Builder builder = PingProtos.HelloRequest.newBuilder();
          if (send != null) builder.setName(send);
          instance.hello(null, builder.build(), rpcCallback);
          PingProtos.HelloResponse r = rpcCallback.get();
          return r != null && r.hasResponse()? r.getResponse(): null;
        }
      });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:19,代码来源:TestServerCustomProtocol.java

示例5: compoundOfHelloAndPing

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
private Map<byte [], String> compoundOfHelloAndPing(final Table table, final byte [] start,
    final byte [] end)
throws ServiceException, Throwable {
  return table.coprocessorService(PingProtos.PingService.class,
      start, end,
      new Batch.Call<PingProtos.PingService, String>() {
        @Override
        public String call(PingProtos.PingService instance) throws IOException {
          BlockingRpcCallback<PingProtos.HelloResponse> rpcCallback =
            new BlockingRpcCallback<PingProtos.HelloResponse>();
          PingProtos.HelloRequest.Builder builder = PingProtos.HelloRequest.newBuilder();
          // Call ping on same instance.  Use result calling hello on same instance.
          builder.setName(doPing(instance));
          instance.hello(null, builder.build(), rpcCallback);
          PingProtos.HelloResponse r = rpcCallback.get();
          return r != null && r.hasResponse()? r.getResponse(): null;
        }
      });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:20,代码来源:TestServerCustomProtocol.java

示例6: noop

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
private Map<byte [], String> noop(final Table table, final byte [] start,
    final byte [] end)
throws ServiceException, Throwable {
  return table.coprocessorService(PingProtos.PingService.class, start, end,
      new Batch.Call<PingProtos.PingService, String>() {
        @Override
        public String call(PingProtos.PingService instance) throws IOException {
          BlockingRpcCallback<PingProtos.NoopResponse> rpcCallback =
            new BlockingRpcCallback<PingProtos.NoopResponse>();
          PingProtos.NoopRequest.Builder builder = PingProtos.NoopRequest.newBuilder();
          instance.noop(null, builder.build(), rpcCallback);
          rpcCallback.get();
          // Looks like null is expected when void.  That is what the test below is looking for
          return null;
        }
      });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:18,代码来源:TestServerCustomProtocol.java

示例7: processBatchCallback

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
/**
 * Send the queries in parallel on the different region servers. Retries on failures.
 * If the method returns it means that there is no error, and the 'results' array will
 * contain no exception. On error, an exception is thrown, and the 'results' array will
 * contain results and exceptions.
 * @deprecated since 0.96 - Use {@link HTable#processBatchCallback} instead
 */
@Override
@Deprecated
public <R> void processBatchCallback(
  List<? extends Row> list,
  TableName tableName,
  ExecutorService pool,
  Object[] results,
  Batch.Callback<R> callback)
  throws IOException, InterruptedException {

  AsyncRequestFuture ars = this.asyncProcess.submitAll(
      pool, tableName, list, callback, results);
  ars.waitUntilDone();
  if (ars.hasError()) {
    throw ars.getErrors();
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:25,代码来源:ConnectionManager.java

示例8: coprocessorService

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public <T extends Service, R> Map<byte[],R> coprocessorService(final Class<T> service,
    byte[] startKey, byte[] endKey, final Batch.Call<T,R> callable)
    throws ServiceException, Throwable {
  final Map<byte[],R> results =  Collections.synchronizedMap(
      new TreeMap<byte[], R>(Bytes.BYTES_COMPARATOR));
  coprocessorService(service, startKey, endKey, callable, new Batch.Callback<R>() {
    @Override
    public void update(byte[] region, byte[] row, R value) {
      if (region != null) {
        results.put(region, value);
      }
    }
  });
  return results;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:20,代码来源:HTable.java

示例9: submitMultiActions

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
<CResult> AsyncRequestFuture submitMultiActions(TableName tableName,
    List<Action<Row>> retainedActions, long nonceGroup, Batch.Callback<CResult> callback,
    Object[] results, boolean needResults, List<Exception> locationErrors,
    List<Integer> locationErrorRows, Map<ServerName, MultiAction<Row>> actionsByServer,
    ExecutorService pool) {
  AsyncRequestFutureImpl<CResult> ars = createAsyncRequestFuture(
    tableName, retainedActions, nonceGroup, pool, callback, results, needResults);
  // Add location errors if any
  if (locationErrors != null) {
    for (int i = 0; i < locationErrors.size(); ++i) {
      int originalIndex = locationErrorRows.get(i);
      Row row = retainedActions.get(originalIndex).getAction();
      ars.manageError(originalIndex, row,
        Retry.NO_LOCATION_PROBLEM, locationErrors.get(i), null);
    }
  }
  ars.sendMultiAction(actionsByServer, 1, null, false);
  return ars;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:20,代码来源:AsyncProcess.java

示例10: submitAll

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
/**
 * Submit immediately the list of rows, whatever the server status. Kept for backward
 * compatibility: it allows to be used with the batch interface that return an array of objects.
 *
 * @param pool ExecutorService to use.
 * @param tableName name of the table for which the submission is made.
 * @param rows the list of rows.
 * @param callback the callback.
 * @param results Optional array to return the results thru; backward compat.
 */
public <CResult> AsyncRequestFuture submitAll(ExecutorService pool, TableName tableName,
    List<? extends Row> rows, Batch.Callback<CResult> callback, Object[] results) {
  List<Action<Row>> actions = new ArrayList<Action<Row>>(rows.size());

  // The position will be used by the processBatch to match the object array returned.
  int posInList = -1;
  NonceGenerator ng = this.connection.getNonceGenerator();
  for (Row r : rows) {
    posInList++;
    if (r instanceof Put) {
      Put put = (Put) r;
      if (put.isEmpty()) {
        throw new IllegalArgumentException("No columns to insert for #" + (posInList+1)+ " item");
      }
    }
    Action<Row> action = new Action<Row>(r, posInList);
    setNonce(ng, r, action);
    actions.add(action);
  }
  AsyncRequestFutureImpl<CResult> ars = createAsyncRequestFuture(
      tableName, actions, ng.getNonceGroup(), getPool(pool), callback, results, results != null);
  ars.groupAndSendMultiAction(actions, 1);
  return ars;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:35,代码来源:AsyncProcess.java

示例11: testSubmitWithCB

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
@Test
public void testSubmitWithCB() throws Exception {
  ClusterConnection hc = createHConnection();
  final AtomicInteger updateCalled = new AtomicInteger(0);
  Batch.Callback<Object> cb = new Batch.Callback<Object>() {
    @Override
    public void update(byte[] region, byte[] row, Object result) {
      updateCalled.incrementAndGet();
    }
  };
  AsyncProcess ap = new MyAsyncProcess(hc, conf);

  List<Put> puts = new ArrayList<Put>();
  puts.add(createPut(1, true));

  final AsyncRequestFuture ars = ap.submit(DUMMY_TABLE, puts, false, cb, false);
  Assert.assertTrue(puts.isEmpty());
  ars.waitUntilDone();
  Assert.assertEquals(updateCalled.get(), 1);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:TestAsyncProcess.java

示例12: invokeBulkDeleteProtocol

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
private long invokeBulkDeleteProtocol(byte[] tableName, final Scan scan, final int rowBatchSize,
    final byte deleteType, final Long timeStamp) throws Throwable {
  HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName);
  long noOfDeletedRows = 0L;
  Batch.Call<BulkDeleteProtocol, BulkDeleteResponse> callable = 
      new Batch.Call<BulkDeleteProtocol, BulkDeleteResponse>() {
    public BulkDeleteResponse call(BulkDeleteProtocol instance) throws IOException {
      return instance.delete(scan, deleteType, timeStamp, rowBatchSize);
    }
  };
  Map<byte[], BulkDeleteResponse> result = ht.coprocessorExec(BulkDeleteProtocol.class,
      scan.getStartRow(), scan.getStopRow(), callable);
  for (BulkDeleteResponse response : result.values()) {
    noOfDeletedRows += response.getRowsDeleted();
  }
  return noOfDeletedRows;
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:18,代码来源:TestBulkDeleteProtocol.java

示例13: testCompountCall

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
@Test
public void testCompountCall() throws Throwable {
  HTable table = new HTable(util.getConfiguration(), TEST_TABLE);

  Map<byte[],String> results = table.coprocessorExec(PingProtocol.class,
      ROW_A, ROW_C,
      new Batch.Call<PingProtocol,String>() {
        public String call(PingProtocol instance) {
          return instance.hello(instance.ping());
        }
      });

  verifyRegionResults(table, results, "Hello, pong", ROW_A);
  verifyRegionResults(table, results, "Hello, pong", ROW_B);
  verifyRegionResults(table, results, "Hello, pong", ROW_C);
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:17,代码来源:TestServerCustomProtocol.java

示例14: testNullCall

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
@Test
public void testNullCall() throws Throwable {
  HTable table = new HTable(util.getConfiguration(), TEST_TABLE);

  Map<byte[],String> results = table.coprocessorExec(PingProtocol.class,
      ROW_A, ROW_C,
      new Batch.Call<PingProtocol,String>() {
        public String call(PingProtocol instance) {
          return instance.hello(null);
        }
      });

  verifyRegionResults(table, results, "Who are you?", ROW_A);
  verifyRegionResults(table, results, "Who are you?", ROW_B);
  verifyRegionResults(table, results, "Who are you?", ROW_C);
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:17,代码来源:TestServerCustomProtocol.java

示例15: testNullReturn

import org.apache.hadoop.hbase.client.coprocessor.Batch; //导入依赖的package包/类
@Test
public void testNullReturn() throws Throwable {
  HTable table = new HTable(util.getConfiguration(), TEST_TABLE);

  Map<byte[],String> results = table.coprocessorExec(PingProtocol.class,
      ROW_A, ROW_C,
      new Batch.Call<PingProtocol,String>(){
        public String call(PingProtocol instance) {
          return instance.hello("nobody");
        }
      });

  verifyRegionResults(table, results, null, ROW_A);
  verifyRegionResults(table, results, null, ROW_B);
  verifyRegionResults(table, results, null, ROW_C);
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:17,代码来源:TestServerCustomProtocol.java


注:本文中的org.apache.hadoop.hbase.client.coprocessor.Batch类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。