private void handleRpcInvocation ( RpcInvocation rpcInvocation ) { Method rpcMethod = null ; try { String methodName = rpcInvocation . getMethodName ( ) ; Class < ? > [ ] parameterTypes = rpcInvocation . getParameterTypes ( ) ; rpcMethod = lookupRpcMethod ( methodName , parameterTypes ) ; } catch ( ClassNotFoundException e ) { log . error ( "Could not load method arguments." , e ) ; RpcConnectionException rpcException = new RpcConnectionException ( "Could not load method arguments." , e ) ; getSender ( ) . tell ( new Status . Failure ( rpcException ) , getSelf ( ) ) ; } catch ( IOException e ) { log . error ( "Could not deserialize rpc invocation message." , e ) ; RpcConnectionException rpcException = new RpcConnectionException ( "Could not deserialize rpc invocation message." , e ) ; getSender ( ) . tell ( new Status . Failure ( rpcException ) , getSelf ( ) ) ; } catch ( final NoSuchMethodException e ) { log . error ( "Could not find rpc method for rpc invocation." , e ) ; RpcConnectionException rpcException = new RpcConnectionException ( "Could not find rpc method for rpc invocation." , e ) ; getSender ( ) . tell ( new Status . Failure ( rpcException ) , getSelf ( ) ) ; } if ( rpcMethod != null ) { try { // this supports declaration of anonymous classes rpcMethod . setAccessible ( true ) ; if ( rpcMethod . getReturnType ( ) . equals ( Void . TYPE ) ) { // No return value to send back rpcMethod . invoke ( rpcEndpoint , rpcInvocation . getArgs ( ) ) ; } else { final Object result ; try { result = rpcMethod . invoke ( rpcEndpoint , rpcInvocation . getArgs ( ) ) ; } catch ( InvocationTargetException e ) { log . debug ( "Reporting back error thrown in remote procedure {}" , rpcMethod , e ) ; // tell the sender about the failure getSender ( ) . tell ( new Status . Failure ( e . getTargetException ( ) ) , getSelf ( ) ) ; return ; } final String methodName = rpcMethod . getName ( ) ; if ( result instanceof CompletableFuture ) { final CompletableFuture < ? > responseFuture = ( CompletableFuture < ? > ) result ; sendAsyncResponse ( responseFuture , methodName ) ; } else { sendSyncResponse ( result , methodName ) ; } } } catch ( Throwable e ) { log . error ( "Error while executing remote procedure call {}." , rpcMethod , e ) ; // tell the sender about the failure getSender ( ) . tell ( new Status . Failure ( e ) , getSelf ( ) ) ; } } }
Handle rpc invocations by looking up the rpc method on the rpc endpoint and calling this method with the provided method arguments . If the method has a return value it is returned to the sender of the call .