@@ -42,6 +42,7 @@ public final class MethodDescriptor<ReqT, RespT> {
4242 private final MethodType type ;
4343 private final String fullMethodName ;
4444 @ Nullable private final String serviceName ;
45+ @ Nullable private final String methodName ;
4546 private final Marshaller <ReqT > requestMarshaller ;
4647 private final Marshaller <RespT > responseMarshaller ;
4748 private final @ Nullable Object schemaDescriptor ;
@@ -225,6 +226,7 @@ private MethodDescriptor(
225226 this .type = Preconditions .checkNotNull (type , "type" );
226227 this .fullMethodName = Preconditions .checkNotNull (fullMethodName , "fullMethodName" );
227228 this .serviceName = extractFullServiceName (fullMethodName );
229+ this .methodName = extractMethodName (fullMethodName );
228230 this .requestMarshaller = Preconditions .checkNotNull (requestMarshaller , "requestMarshaller" );
229231 this .responseMarshaller = Preconditions .checkNotNull (responseMarshaller , "responseMarshaller" );
230232 this .schemaDescriptor = schemaDescriptor ;
@@ -262,6 +264,17 @@ public String getServiceName() {
262264 return serviceName ;
263265 }
264266
267+ /**
268+ * A convenience method for {@code extractMethodName(getFullMethodName())}.
269+ *
270+ * @since 1.32.0
271+ */
272+ @ Nullable
273+ @ ExperimentalApi ("https://github.com/grpc/grpc-java/issues/5635" )
274+ public String getMethodName () {
275+ return methodName ;
276+ }
277+
265278 /**
266279 * Parse a response payload from the given {@link InputStream}.
267280 *
@@ -398,6 +411,21 @@ public static String extractFullServiceName(String fullMethodName) {
398411 return fullMethodName .substring (0 , index );
399412 }
400413
414+ /**
415+ * Extract the method name out of a fully qualified method name. May return {@code null}
416+ * if the input is malformed, but you cannot rely on it for the validity of the input.
417+ *
418+ * @since 1.32.0
419+ */
420+ @ Nullable
421+ public static String extractMethodName (String fullMethodName ) {
422+ int index = checkNotNull (fullMethodName , "fullMethodName" ).lastIndexOf ('/' );
423+ if (index == -1 ) {
424+ return null ;
425+ }
426+ return fullMethodName .substring (index + 1 );
427+ }
428+
401429 /**
402430 * Creates a new builder for a {@link MethodDescriptor}.
403431 *
0 commit comments