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