Example #1
0
        private void Error(void *target, int errType, sbyte *errClsChars, int errClsCharsLen, sbyte *errMsgChars,
                           int errMsgCharsLen, void *errData, int errDataLen)
        {
            string errCls = IgniteUtils.Utf8UnmanagedToString(errClsChars, errClsCharsLen);
            string errMsg = IgniteUtils.Utf8UnmanagedToString(errMsgChars, errMsgCharsLen);

            switch (errType)
            {
            case ErrGeneric:
                if (_ignite != null && errDataLen > 0)
                {
                    // Stream disposal intentionally omitted: IGNITE-1598
                    var stream = new PlatformRawMemory(errData, errDataLen).GetStream();

                    throw ExceptionUtils.GetException(_ignite, errCls, errMsg, _ignite.Marshaller.StartUnmarshal(stream));
                }

                throw ExceptionUtils.GetException(_ignite, errCls, errMsg);

            case ErrJvmInit:
                throw ExceptionUtils.GetJvmInitializeException(errCls, errMsg);

            case ErrJvmAttach:
                throw new IgniteException("Failed to attach to JVM.");

            default:
                throw new IgniteException("Unknown exception [cls=" + errCls + ", msg=" + errMsg + ']');
            }
        }
        private void LoggerLog(void *target, int level, sbyte *messageChars, int messageCharsLen, sbyte *categoryChars,
                               int categoryCharsLen, sbyte *errorInfoChars, int errorInfoCharsLen, long memPtr)
        {
            // When custom logger in .NET is not defined, Java should not call us.
            Debug.Assert(!(_log is JavaLogger));

            SafeCall(() =>
            {
                var message     = IgniteUtils.Utf8UnmanagedToString(messageChars, messageCharsLen);
                var category    = IgniteUtils.Utf8UnmanagedToString(categoryChars, categoryCharsLen);
                var nativeError = IgniteUtils.Utf8UnmanagedToString(errorInfoChars, errorInfoCharsLen);

                Exception ex = null;

                if (memPtr != 0 && _ignite != null)
                {
                    using (var stream = IgniteManager.Memory.Get(memPtr).GetStream())
                    {
                        ex = _ignite.Marshaller.Unmarshal <Exception>(stream);
                    }
                }

                _log.Log((LogLevel)level, message, null, CultureInfo.InvariantCulture, category, nativeError, ex);
            }, true);
        }
        private void Error(void *target, int errType, sbyte *errClsChars, int errClsCharsLen, sbyte *errMsgChars,
                           int errMsgCharsLen, sbyte *stackTraceChars, int stackTraceCharsLen, void *errData, int errDataLen)
        {
            // errData mechanism is only needed for CachePartialUpdateException and is no longer used,
            // since CacheImpl handles all errors itself.
            Debug.Assert(errDataLen == 0);
            Debug.Assert(errData == null);

            string errCls     = IgniteUtils.Utf8UnmanagedToString(errClsChars, errClsCharsLen);
            string errMsg     = IgniteUtils.Utf8UnmanagedToString(errMsgChars, errMsgCharsLen);
            string stackTrace = IgniteUtils.Utf8UnmanagedToString(stackTraceChars, stackTraceCharsLen);

            switch (errType)
            {
            case ErrGeneric:
                throw ExceptionUtils.GetException(_ignite, errCls, errMsg, stackTrace);

            case ErrJvmInit:
                throw ExceptionUtils.GetJvmInitializeException(errCls, errMsg, stackTrace);

            case ErrJvmAttach:
                throw new IgniteException("Failed to attach to JVM.");

            default:
                throw new IgniteException("Unknown exception [cls=" + errCls + ", msg=" + errMsg + ']');
            }
        }
        private static void ConsoleWrite(sbyte *chars, int charsLen, bool isErr)
        {
            try
            {
                var str = IgniteUtils.Utf8UnmanagedToString(chars, charsLen);

                var target = isErr ? Console.Error : Console.Out;

                target.Write(str);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("ConsoleWrite unmanaged callback failed: " + ex);
            }
        }
Example #5
0
        /// <summary>
        /// Converts jstring to string.
        /// </summary>
        public string JStringToString(IntPtr jstring)
        {
            if (jstring == IntPtr.Zero)
            {
                return(null);
            }

            var chars = GetStringUtfChars(jstring);
            var len   = GetStringUtfLength(jstring);

            try
            {
                return(IgniteUtils.Utf8UnmanagedToString((sbyte *)chars, len));
            }
            finally
            {
                ReleaseStringUtfChars(jstring, chars);
            }
        }