コード例 #1
0
ファイル: RPC.java プロジェクト: jonathangizmo/HadoopDistJ
 /**
  * Get the protocol name. If the protocol class has a ProtocolAnnotation, then get the protocol
  * name from the annotation; otherwise the class name is the protocol name.
  */
 public static String getProtocolName(Class<?> protocol) {
   if (protocol == null) {
     return null;
   }
   ProtocolInfo anno = protocol.getAnnotation(ProtocolInfo.class);
   return (anno == null) ? protocol.getName() : anno.protocolName();
 }
コード例 #2
0
ファイル: RPC.java プロジェクト: jonathangizmo/HadoopDistJ
 /**
  * Get the protocol version from protocol class. If the protocol class has a ProtocolAnnotation,
  * then get the protocol name from the annotation; otherwise the class name is the protocol name.
  */
 public static long getProtocolVersion(Class<?> protocol) {
   if (protocol == null) {
     throw new IllegalArgumentException("Null protocol");
   }
   long version;
   ProtocolInfo anno = protocol.getAnnotation(ProtocolInfo.class);
   if (anno != null) {
     version = anno.protocolVersion();
     if (version != -1) return version;
   }
   try {
     Field versionField = protocol.getField("versionID");
     versionField.setAccessible(true);
     return versionField.getLong(protocol);
   } catch (NoSuchFieldException ex) {
     throw new RuntimeException(ex);
   } catch (IllegalAccessException ex) {
     throw new RuntimeException(ex);
   }
 }