executeRemoteFunctionRunnable method

bool executeRemoteFunctionRunnable(
  1. DataPackage rpcRequest
)

Implementation

bool executeRemoteFunctionRunnable(DataPackage rpcRequest)
{
    RemoteFunctionRequest request;
    if(!rpcRequest.controlVal.hasRemoteFunctionRequest())
    {
        Logger.logError("Failed to execute RPC request data package. Could not find definition of RemoteFunctionRequest.");

        DataPackage response =
            RemoteFunctionRunnable.prepareResponsePackage(RemoteFunctionStatus.REMOTE_FUNCTION_REQUEST_INVALID, rpcRequest);

        if(response != null)
        {
            this._outputController.add(response);
        }

        return false;
    }

    request = rpcRequest.controlVal.remoteFunctionRequest;

    RemoteFunctionIdentifier remoteFunctionIdentifier = request.remoteFunctionIdentifier;

    String functionName = remoteFunctionIdentifier.functionName;
    if(!this._registeredRunnables.containsKey(functionName))
    {
        Logger.logError("Failed to execute RPC request. Entity \"" + this._entityName + "\" does not have a registered remote function called \"" + functionName + "\".");

        DataPackage response =
            RemoteFunctionRunnable.prepareResponsePackage(RemoteFunctionStatus.FAILED_FUNCTION_NOT_FOUND_OR_FAILED_TO_EXECUTE, rpcRequest);

        if(response != null)
        {
            this._outputController.add(response);
        }

        return false;
    }

    RemoteFunctionRunnable runnable = this._registeredRunnables[functionName]!;
    DataPackage response = runnable.executeRemoteFunctionRequest(rpcRequest);

    if(response != null)
    {
        this._outputController.add(response);
    }

    return true;
}