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 java.io.IOException;
23  
24  import org.apache.hadoop.classification.InterfaceAudience;
25  
26  
27  /**
28   * A collection of interfaces and utilities used for interacting with custom RPC
29   * interfaces exposed by Coprocessors.
30   */
31  @InterfaceAudience.Private
32  public abstract class Batch {
33    /**
34     * Defines a unit of work to be executed.
35     *
36     * <p>
37     * When used with
38     * {@link org.apache.hadoop.hbase.client.HTable#coprocessorService(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call)}
39     * the implementations {@link Batch.Call#call(Object)} method will be invoked
40     * with a proxy to the
41     * {@link org.apache.hadoop.hbase.coprocessor.CoprocessorService}
42     * sub-type instance.
43     * </p>
44     * @see org.apache.hadoop.hbase.client.coprocessor
45     * @see org.apache.hadoop.hbase.client.HTable#coprocessorService(byte[])
46     * @see org.apache.hadoop.hbase.client.HTable#coprocessorService(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call)
47     * @param <T> the instance type to be passed to
48     * {@link Batch.Call#call(Object)}
49     * @param <R> the return type from {@link Batch.Call#call(Object)}
50     */
51    public interface Call<T,R> {
52      R call(T instance) throws IOException;
53    }
54  
55    /**
56     * Defines a generic callback to be triggered for each {@link Batch.Call#call(Object)}
57     * result.
58     *
59     * <p>
60     * When used with
61     * {@link org.apache.hadoop.hbase.client.HTable#coprocessorService(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call)}
62     * the implementation's {@link Batch.Callback#update(byte[], byte[], Object)}
63     * method will be called with the {@link Batch.Call#call(Object)} return value
64     * from each region in the selected range.
65     * </p>
66     * @param <R> the return type from the associated {@link Batch.Call#call(Object)}
67     * @see org.apache.hadoop.hbase.client.HTable#coprocessorService(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call)
68     */
69    public interface Callback<R> {
70      void update(byte[] region, byte[] row, R result);
71    }
72  }