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.io.HbaseObjectWritable;
23 import org.apache.hadoop.hbase.util.Bytes;
24 import org.apache.hadoop.hbase.util.Classes;
25 import org.apache.hadoop.io.Writable;
26
27 import java.io.DataInput;
28 import java.io.DataOutput;
29 import java.io.IOException;
30 import java.io.Serializable;
31
32 /**
33 * Represents the return value from a
34 * {@link org.apache.hadoop.hbase.client.coprocessor.Exec} invocation.
35 * This simply wraps the value for easier
36 * {@link org.apache.hadoop.hbase.io.HbaseObjectWritable}
37 * serialization.
38 *
39 * <p>
40 * This class is used internally by the HBase client code to properly serialize
41 * responses from {@link org.apache.hadoop.hbase.ipc.CoprocessorProtocol}
42 * method invocations. It should not be used directly by clients.
43 * </p>
44 *
45 * @see Exec
46 * @see org.apache.hadoop.hbase.client.HTable#coprocessorExec(Class, byte[], byte[], org.apache.hadoop.hbase.client.coprocessor.Batch.Call)
47 * @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)
48 */
49 public class ExecResult implements Writable {
50 private byte[] regionName;
51 private Object value;
52
53 public ExecResult() {
54 }
55
56 public ExecResult(byte[] region, Object value) {
57 this.regionName = region;
58 this.value = value;
59 }
60
61 public byte[] getRegionName() {
62 return regionName;
63 }
64
65 public Object getValue() {
66 return value;
67 }
68
69 @Override
70 public void write(DataOutput out) throws IOException {
71 Bytes.writeByteArray(out, regionName);
72 HbaseObjectWritable.writeObject(out, value,
73 value != null ? value.getClass() : Writable.class, null);
74 }
75
76 @Override
77 public void readFields(DataInput in) throws IOException {
78 regionName = Bytes.readByteArray(in);
79 value = HbaseObjectWritable.readObject(in, null);
80 }
81 }