public Object invokeMethod ( String methodName , Object [ ] args , Type retType ) throws ServiceInvocationException { checkCurrentThread ( methodName ) ; Utils . notNull ( methodName ) ; Utils . notNull ( args ) ; // Let the target prepare the arguments if needed mInvocationTarget . prepareArguments ( args ) ; // Serialize arguments String payload = GsonHelper . gson . toJson ( args ) ; InvocationRequest request = new InvocationRequest ( mServiceDescriptor . getAppIdentifier ( ) , mServiceDescriptor . getServiceName ( ) , methodName , payload ) ; // Let the target perform the execution InvocationResponse response = mInvocationTarget . executeService ( request ) ; // Analyze the response if ( ! response . isResult ( ) ) { throw new ServiceInvocationException ( response . getErrorMessage ( ) ) ; } else if ( retType . equals ( void . class ) ) { return null ; } else { return GsonHelper . gson . fromJson ( response . getPayload ( ) , retType ) ; } }
Invokes a remote service providing the name of the method to invoke name and the list of parameters . The invocation is a blocking network request and thus should not be performed on the main thread .