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.hbase.classification.InterfaceAudience;
23 import org.apache.hadoop.hbase.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 @InterfaceAudience.Public
51 @InterfaceStability.Stable
52 public interface Call<T,R> {
53 R call(T instance) throws IOException;
54 }
55
56 /**
57 * Defines a generic callback to be triggered for each {@link Batch.Call#call(Object)}
58 * result.
59 *
60 * <p>
61 * When used with
62 * {@link org.apache.hadoop.hbase.client.HTable#coprocessorService(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call)}
63 * the implementation's {@link Batch.Callback#update(byte[], byte[], Object)}
64 * method will be called with the {@link Batch.Call#call(Object)} return value
65 * from each region in the selected range.
66 * </p>
67 * @param <R> the return type from the associated {@link Batch.Call#call(Object)}
68 * @see org.apache.hadoop.hbase.client.HTable#coprocessorService(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call)
69 */
70 @InterfaceAudience.Public
71 @InterfaceStability.Stable
72 public interface Callback<R> {
73 void update(byte[] region, byte[] row, R result);
74 }
75 }