View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.client.coprocessor;
21  
22  import org.apache.hadoop.classification.InterfaceAudience;
23  import org.apache.hadoop.classification.InterfaceStability;
24  
25  import java.io.IOException;
26  
27  /**
28   * A collection of interfaces and utilities used for interacting with custom RPC
29   * interfaces exposed by Coprocessors.
30   */
31  @InterfaceAudience.Public
32  @InterfaceStability.Stable
33  public abstract class Batch {
34    /**
35     * Defines a unit of work to be executed.
36     *
37     * <p>
38     * When used with
39     * {@link org.apache.hadoop.hbase.client.HTable#coprocessorService(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call)}
40     * the implementations {@link Batch.Call#call(Object)} method will be invoked
41     * with a proxy to each region's coprocessor {@link com.google.protobuf.Service} implementation.
42     * </p>
43     * @see org.apache.hadoop.hbase.client.coprocessor
44     * @see org.apache.hadoop.hbase.client.HTable#coprocessorService(byte[])
45     * @see org.apache.hadoop.hbase.client.HTable#coprocessorService(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call)
46     * @param <T> the instance type to be passed to
47     * {@link Batch.Call#call(Object)}
48     * @param <R> the return type from {@link Batch.Call#call(Object)}
49     */
50    public interface Call<T,R> {
51      R call(T instance) throws IOException;
52    }
53  
54    /**
55     * Defines a generic callback to be triggered for each {@link Batch.Call#call(Object)}
56     * result.
57     *
58     * <p>
59     * When used with
60     * {@link org.apache.hadoop.hbase.client.HTable#coprocessorService(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call)}
61     * the implementation's {@link Batch.Callback#update(byte[], byte[], Object)}
62     * method will be called with the {@link Batch.Call#call(Object)} return value
63     * from each region in the selected range.
64     * </p>
65     * @param <R> the return type from the associated {@link Batch.Call#call(Object)}
66     * @see org.apache.hadoop.hbase.client.HTable#coprocessorService(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call)
67     */
68    public interface Callback<R> {
69      void update(byte[] region, byte[] row, R result);
70    }
71  }