@@ -257,6 +257,7 @@ private class Connection extends Thread {
257257 private final ConnectionId remoteId ; // connection id
258258 private AuthMethod authMethod ; // authentication method
259259 private Token <? extends TokenIdentifier > token ;
260+ private int serviceClass ;
260261 private SaslRpcClient saslRpcClient ;
261262
262263 private Socket socket = null ; // connected socket
@@ -279,7 +280,7 @@ private class Connection extends Thread {
279280
280281 private final Object sendRpcRequestLock = new Object ();
281282
282- public Connection (ConnectionId remoteId ) throws IOException {
283+ public Connection (ConnectionId remoteId , int serviceClass ) throws IOException {
283284 this .remoteId = remoteId ;
284285 this .server = remoteId .getAddress ();
285286 if (server .isUnresolved ()) {
@@ -296,6 +297,7 @@ public Connection(ConnectionId remoteId) throws IOException {
296297 this .tcpNoDelay = remoteId .getTcpNoDelay ();
297298 this .doPing = remoteId .getDoPing ();
298299 this .pingInterval = remoteId .getPingInterval ();
300+ this .serviceClass = serviceClass ;
299301 if (LOG .isDebugEnabled ()) {
300302 LOG .debug ("The ping interval is " + this .pingInterval + " ms." );
301303 }
@@ -747,7 +749,9 @@ private void handleConnectionFailure(int curRetries, IOException ioe
747749 * +----------------------------------+
748750 * | "hrpc" 4 bytes |
749751 * +----------------------------------+
750- * | Version (1 bytes) |
752+ * | Version (1 byte) |
753+ * +----------------------------------+
754+ * | Service Class (1 byte) |
751755 * +----------------------------------+
752756 * | Authmethod (1 byte) |
753757 * +----------------------------------+
@@ -760,6 +764,7 @@ private void writeConnectionHeader(OutputStream outStream)
760764 // Write out the header, version and authentication method
761765 out .write (Server .HEADER .array ());
762766 out .write (Server .CURRENT_VERSION );
767+ out .write (serviceClass );
763768 authMethod .write (out );
764769 Server .IpcSerializationType .PROTOBUF .write (out );
765770 out .flush ();
@@ -1179,19 +1184,33 @@ public Writable call(RPC.RpcKind rpcKind, Writable param, InetSocketAddress addr
11791184
11801185
11811186 /**
1182- * Same as {@link #call(RPC.RpcKind, Writable, InetSocketAddress,
1187+ * Same as {@link #call(RPC.RpcKind, Writable, InetSocketAddress,
11831188 * Class, UserGroupInformation, int, Configuration)}
11841189 * except that rpcKind is writable.
11851190 */
1186- public Writable call (Writable param , InetSocketAddress addr ,
1191+ public Writable call (Writable param , InetSocketAddress addr ,
11871192 Class <?> protocol , UserGroupInformation ticket ,
1188- int rpcTimeout , Configuration conf )
1193+ int rpcTimeout , Configuration conf )
11891194 throws InterruptedException , IOException {
1190- ConnectionId remoteId = ConnectionId .getConnectionId (addr , protocol ,
1195+ ConnectionId remoteId = ConnectionId .getConnectionId (addr , protocol ,
11911196 ticket , rpcTimeout , conf );
11921197 return call (RPC .RpcKind .RPC_BUILTIN , param , remoteId );
11931198 }
11941199
1200+ /**
1201+ * Same as {@link #call(Writable, InetSocketAddress,
1202+ * Class, UserGroupInformation, int, Configuration)}
1203+ * except that specifying serviceClass.
1204+ */
1205+ public Writable call (Writable param , InetSocketAddress addr ,
1206+ Class <?> protocol , UserGroupInformation ticket ,
1207+ int rpcTimeout , int serviceClass , Configuration conf )
1208+ throws InterruptedException , IOException {
1209+ ConnectionId remoteId = ConnectionId .getConnectionId (addr , protocol ,
1210+ ticket , rpcTimeout , conf );
1211+ return call (RPC .RpcKind .RPC_BUILTIN , param , remoteId , serviceClass );
1212+ }
1213+
11951214 /**
11961215 * Make a call, passing <code>param</code>, to the IPC server running at
11971216 * <code>address</code> which is servicing the <code>protocol</code> protocol,
@@ -1218,21 +1237,39 @@ public Writable call(Writable param, ConnectionId remoteId)
12181237 return call (RPC .RpcKind .RPC_BUILTIN , param , remoteId );
12191238 }
12201239
1240+ /**
1241+ * Make a call, passing <code>rpcRequest</code>, to the IPC server defined by
1242+ * <code>remoteId</code>, returning the rpc respond.
1243+ *
1244+ * @param rpcKind
1245+ * @param rpcRequest - contains serialized method and method parameters
1246+ * @param remoteId - the target rpc server
1247+ * @returns the rpc response
1248+ * Throws exceptions if there are network problems or if the remote code
1249+ * threw an exception.
1250+ */
1251+ public Writable call (RPC .RpcKind rpcKind , Writable rpcRequest ,
1252+ ConnectionId remoteId ) throws InterruptedException , IOException {
1253+ return call (rpcKind , rpcRequest , remoteId , RPC .RPC_SERVICE_CLASS_DEFAULT );
1254+ }
1255+
12211256 /**
12221257 * Make a call, passing <code>rpcRequest</code>, to the IPC server defined by
12231258 * <code>remoteId</code>, returning the rpc respond.
12241259 *
12251260 * @param rpcKind
12261261 * @param rpcRequest - contains serialized method and method parameters
12271262 * @param remoteId - the target rpc server
1263+ * @param serviceClass - service class for RPC
12281264 * @returns the rpc response
12291265 * Throws exceptions if there are network problems or if the remote code
12301266 * threw an exception.
12311267 */
12321268 public Writable call (RPC .RpcKind rpcKind , Writable rpcRequest ,
1233- ConnectionId remoteId ) throws InterruptedException , IOException {
1269+ ConnectionId remoteId , int serviceClass )
1270+ throws InterruptedException , IOException {
12341271 Call call = new Call (rpcKind , rpcRequest );
1235- Connection connection = getConnection (remoteId , call );
1272+ Connection connection = getConnection (remoteId , call , serviceClass );
12361273 try {
12371274 connection .sendRpcRequest (call ); // send the rpc request
12381275 } catch (RejectedExecutionException e ) {
@@ -1289,7 +1326,7 @@ Set<ConnectionId> getConnectionIds() {
12891326 /** Get a connection from the pool, or create a new one and add it to the
12901327 * pool. Connections to a given ConnectionId are reused. */
12911328 private Connection getConnection (ConnectionId remoteId ,
1292- Call call )
1329+ Call call , int serviceClass )
12931330 throws IOException , InterruptedException {
12941331 if (!running .get ()) {
12951332 // the client is stopped
@@ -1304,7 +1341,7 @@ private Connection getConnection(ConnectionId remoteId,
13041341 synchronized (connections ) {
13051342 connection = connections .get (remoteId );
13061343 if (connection == null ) {
1307- connection = new Connection (remoteId );
1344+ connection = new Connection (remoteId , serviceClass );
13081345 connections .put (remoteId , connection );
13091346 }
13101347 }
0 commit comments