001/*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020package org.apache.hadoop.hbase.client.coprocessor;
021
022import java.io.IOException;
023
024import org.apache.yetus.audience.InterfaceAudience;
025
026/**
027 * A collection of interfaces and utilities used for interacting with custom RPC
028 * interfaces exposed by Coprocessors.
029 */
030@InterfaceAudience.Public
031public abstract class Batch {
032
033  /**
034   * Defines a unit of work to be executed.
035   * <p/>
036   * When used with
037   * {@link org.apache.hadoop.hbase.client.Table#coprocessorService(Class, byte[], byte[], Batch.Call)}
038   * the implementations {@link Batch.Call#call(Object)} method will be invoked with a proxy to each
039   * region's coprocessor {@link org.apache.hbase.thirdparty.com.google.protobuf.Service}
040   * implementation.
041   * @see org.apache.hadoop.hbase.client.coprocessor.Batch
042   * @see org.apache.hadoop.hbase.client.Table#coprocessorService(byte[])
043   * @see org.apache.hadoop.hbase.client.Table#coprocessorService(Class, byte[], byte[], Batch.Call)
044   * @param <T> the instance type to be passed to {@link Batch.Call#call(Object)}
045   * @param <R> the return type from {@link Batch.Call#call(Object)}
046   */
047  @InterfaceAudience.Public
048  public interface Call<T, R> {
049    R call(T instance) throws IOException;
050  }
051
052  /**
053   * Defines a generic callback to be triggered for each {@link Batch.Call#call(Object)} result.
054   * <p/>
055   * When used with
056   * {@link org.apache.hadoop.hbase.client.Table#coprocessorService(Class, byte[], byte[], Batch.Call)}
057   * the implementation's {@link Batch.Callback#update(byte[], byte[], Object)} method will be
058   * called with the {@link Batch.Call#call(Object)} return value from each region in the selected
059   * range.
060   * @param <R> the return type from the associated {@link Batch.Call#call(Object)}
061   * @see org.apache.hadoop.hbase.client.Table#coprocessorService(Class, byte[], byte[],
062   *      org.apache.hadoop.hbase.client.coprocessor.Batch.Call)
063   */
064  @InterfaceAudience.Public
065  public interface Callback<R> {
066    void update(byte[] region, byte[] row, R result);
067  }
068}