private object CallJavaMethod()

in csharp/Adapter/Microsoft.Spark.CSharp/Interop/Ipc/JvmBridge.cs [69:140]


        private object CallJavaMethod(bool isStatic, object classNameOrJvmObjectReference, string methodName, params object[] parameters)
        {
            object returnValue = null;
            try
            {
                var overallPayload = PayloadHelper.BuildPayload(isStatic, classNameOrJvmObjectReference, methodName, parameters);

                var socket = GetConnection();
                using (var s = socket.GetStream())
                {
                    SerDe.Write(s, overallPayload);
                    s.Flush();

                    var isMethodCallFailed = SerDe.ReadInt(s);
                    //TODO - add boolean instead of int in the backend
                    if (isMethodCallFailed != 0)
                    {
                        var jvmFullStackTrace = SerDe.ReadString(s);
                        var errorMessage = BuildErrorMessage(isStatic, classNameOrJvmObjectReference, methodName, parameters);
                        logger.LogError(errorMessage);
                        logger.LogError(jvmFullStackTrace);
                        throw new Exception(errorMessage);
                    }

                    var typeAsChar = Convert.ToChar(s.ReadByte());
                    switch (typeAsChar) //TODO - add support for other types
                    {
                        case 'n':
                            break;

                        case 'j':
                            returnValue = SerDe.ReadString(s);
                            break;

                        case 'c':
                            returnValue = SerDe.ReadString(s);
                            break;

                        case 'i':
                            returnValue = SerDe.ReadInt(s);
                            break;

                        case 'd':
                            returnValue = SerDe.ReadDouble(s);
                            break;

                        case 'b':
                            returnValue = Convert.ToBoolean(s.ReadByte());
                            break;

                        case 'l':
                            returnValue = ReadCollection(s);

                            break;

                        default:
                            // convert typeAsChar to UInt32 because the char may be non-printable
                            throw new NotSupportedException(string.Format("Identifier for type 0x{0:X} not supported", Convert.ToUInt32(typeAsChar)));

                    }
                }
                sockets.Enqueue(socket);
            }
            catch (Exception e)
            {
                logger.LogException(e);
                throw;
            }

            return returnValue;

        }