Author: stack
Date: Sat Jul 18 00:45:27 2009
New Revision: 795290

URL: http://svn.apache.org/viewvc?rev=795290&view=rev
Log:
HBASE-1669 need dynamic extensibility of HBaseRPC code maps and interface lists

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    
hadoop/hbase/trunk/src/contrib/transactional/src/java/org/apache/hadoop/hbase/client/transactional/TransactionalTable.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=795290&r1=795289&r2=795290&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Sat Jul 18 00:45:27 2009
@@ -274,6 +274,8 @@
    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

Modified: 
hadoop/hbase/trunk/src/contrib/transactional/src/java/org/apache/hadoop/hbase/client/transactional/TransactionalTable.java
URL: 
http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/contrib/transactional/src/java/org/apache/hadoop/hbase/client/transactional/TransactionalTable.java?rev=795290&r1=795289&r2=795290&view=diff
==============================================================================
--- 
hadoop/hbase/trunk/src/contrib/transactional/src/java/org/apache/hadoop/hbase/client/transactional/TransactionalTable.java
 (original)
+++ 
hadoop/hbase/trunk/src/contrib/transactional/src/java/org/apache/hadoop/hbase/client/transactional/TransactionalTable.java
 Sat Jul 18 00:45:27 2009
@@ -32,6 +32,7 @@
 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 @@
  */
 public class TransactionalTable extends HTable {
 
+  private static final byte RPC_CODE = 100;
+  static {
+    HBaseRPC.addToMap(TransactionalRegionInterface.class, RPC_CODE);
+  }
+  
   /**
    * @param conf
    * @param tableName

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java
URL: 
http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java?rev=795290&r1=795289&r2=795290&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java 
(original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPC.java Sat 
Jul 18 00:45:27 2009
@@ -84,24 +84,53 @@
     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 @@
     }
     
     // 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 @@
       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.


Reply via email to