HBASE-1669 need dynamic extensibility of HBaseRPC code maps and interface lists

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@795290 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2009-07-18 00:45:27 +00:00
parent c3921a955d
commit 8809929dff
3 changed files with 48 additions and 33 deletions

View File

@ -274,6 +274,8 @@ Release 0.20.0 - Unreleased
HBASE-1058 Disable 1058 on catalog tables
HBASE-1583 Start/Stop of large cluster untenable
HBASE-1668 hbase-1609 broke TestHRegion.testScanSplitOnRegion unit test
HBASE-1669 need dynamic extensibility of HBaseRPC code maps and interface
lists (Clint Morgan via Stack)
IMPROVEMENTS
HBASE-1089 Add count of regions on filesystem to master UI; add percentage

View File

@ -32,6 +32,7 @@ import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.ScannerCallable;
import org.apache.hadoop.hbase.client.ServerCallable;
import org.apache.hadoop.hbase.ipc.HBaseRPC;
import org.apache.hadoop.hbase.ipc.TransactionalRegionInterface;
import org.apache.hadoop.hbase.util.Bytes;
@ -41,6 +42,11 @@ import org.apache.hadoop.hbase.util.Bytes;
*/
public class TransactionalTable extends HTable {
private static final byte RPC_CODE = 100;
static {
HBaseRPC.addToMap(TransactionalRegionInterface.class, RPC_CODE);
}
/**
* @param conf
* @param tableName

View File

@ -84,24 +84,53 @@ public class HBaseRPC {
super();
} // no public ctor
// Special code that means 'not-encoded'.
private static final byte NOT_ENCODED = 0;
private static byte code = NOT_ENCODED + 1;
/** Add a new interface to the ipc map.
* @param c Class whose methods we'll add to the map of methods to codes
* (and vice versa).
* @param startCode Current state of the byte code.
* @return State of <code>code</code> when this method is done.
*/
public static byte addToMap(final Class<?> c, final byte startCode) {
if (Invocation.CODE_TO_METHODNAME.get(startCode) != null) {
throw new IllegalArgumentException("Code " + startCode +
"already had entry");
}
byte localCode = startCode;
Method [] methods = c.getMethods();
// There are no guarantees about the order in which items are returned in
// so do a sort (Was seeing that sort was one way on one server and then
// another on different server).
Arrays.sort(methods, new Comparator<Method>() {
public int compare(Method left, Method right) {
return left.getName().compareTo(right.getName());
}
});
for (int i = 0; i < methods.length; i++) {
Invocation.addToMap(methods[i].getName(), localCode++);
}
return localCode;
}
static {
code = HBaseRPC.addToMap(VersionedProtocol.class, code);
code = HBaseRPC.addToMap(HMasterInterface.class, code);
code = HBaseRPC.addToMap(HMasterRegionInterface.class, code);
code = HBaseRPC.addToMap(HRegionInterface.class, code);
}
/** A method invocation, including the method name and its parameters.*/
private static class Invocation implements Writable, Configurable {
// Here, for hbase, we maintain two static maps of method names to code and
// vice versa.
private static final Map<Byte, String> CODE_TO_METHODNAME =
static final Map<Byte, String> CODE_TO_METHODNAME =
new HashMap<Byte, String>();
private static final Map<String, Byte> METHODNAME_TO_CODE =
new HashMap<String, Byte>();
// Special code that means 'not-encoded'.
private static final byte NOT_ENCODED = 0;
static {
byte code = NOT_ENCODED + 1;
code = addToMap(VersionedProtocol.class, code);
code = addToMap(HMasterInterface.class, code);
code = addToMap(HMasterRegionInterface.class, code);
code = addToMap(HRegionInterface.class, code);
}
// End of hbase modifications.
private String methodName;
@ -180,7 +209,7 @@ public class HBaseRPC {
}
// Hbase additions.
private static void addToMap(final String name, final byte code) {
static void addToMap(final String name, final byte code) {
if (METHODNAME_TO_CODE.containsKey(name)) {
return;
}
@ -188,28 +217,6 @@ public class HBaseRPC {
CODE_TO_METHODNAME.put(Byte.valueOf(code), name);
}
/*
* @param c Class whose methods we'll add to the map of methods to codes
* (and vice versa).
* @param code Current state of the byte code.
* @return State of <code>code</code> when this method is done.
*/
private static byte addToMap(final Class<?> c, final byte code) {
byte localCode = code;
Method [] methods = c.getMethods();
// There are no guarantees about the order in which items are returned in
// so do a sort (Was seeing that sort was one way on one server and then
// another on different server).
Arrays.sort(methods, new Comparator<Method>() {
public int compare(Method left, Method right) {
return left.getName().compareTo(right.getName());
}
});
for (int i = 0; i < methods.length; i++) {
addToMap(methods[i].getName(), localCode++);
}
return localCode;
}
/*
* Write out the code byte for passed Class.