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