1 /* 2 * Copyright 2010 The Apache Software Foundation 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 package org.apache.hadoop.hbase.client.coprocessor; 21 22 import org.apache.hadoop.hbase.HConstants; 23 import org.apache.hadoop.hbase.io.HbaseObjectWritable; 24 import org.apache.hadoop.hbase.util.Bytes; 25 import org.apache.hadoop.hbase.util.Classes; 26 import org.apache.hadoop.io.Writable; 27 28 import java.io.DataInput; 29 import java.io.DataOutput; 30 import java.io.IOException; 31 import java.io.Serializable; 32 33 /** 34 * Represents the return value from a 35 * {@link org.apache.hadoop.hbase.client.coprocessor.Exec} invocation. 36 * This simply wraps the value for easier 37 * {@link org.apache.hadoop.hbase.io.HbaseObjectWritable} 38 * serialization. 39 * 40 * <p> 41 * This class is used internally by the HBase client code to properly serialize 42 * responses from {@link org.apache.hadoop.hbase.ipc.CoprocessorProtocol} 43 * method invocations. It should not be used directly by clients. 44 * </p> 45 * 46 * @see Exec 47 * @see org.apache.hadoop.hbase.client.HTable#coprocessorExec(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call) 48 * @see org.apache.hadoop.hbase.client.HTable#coprocessorExec(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call, org.apache.hadoop.hbase.client.coprocessor.Batch.Callback) 49 */ 50 public class ExecResult implements Writable { 51 private byte[] regionName; 52 private Object value; 53 54 public ExecResult() { 55 } 56 57 public ExecResult(Object value) { 58 this(HConstants.EMPTY_BYTE_ARRAY, value); 59 } 60 public ExecResult(byte[] region, Object value) { 61 this.regionName = region; 62 this.value = value; 63 } 64 65 public byte[] getRegionName() { 66 return regionName; 67 } 68 69 public Object getValue() { 70 return value; 71 } 72 73 @Override 74 public void write(DataOutput out) throws IOException { 75 Bytes.writeByteArray(out, regionName); 76 HbaseObjectWritable.writeObject(out, value, 77 value != null ? value.getClass() : Writable.class, null); 78 } 79 80 @Override 81 public void readFields(DataInput in) throws IOException { 82 regionName = Bytes.readByteArray(in); 83 value = HbaseObjectWritable.readObject(in, null); 84 } 85 }