Beispiel #1
0
        internal static void IgnitionStart(UnmanagedContext ctx, string cfgPath, string gridName,
                                           bool clientMode, bool userLogger)
        {
            using (var mem = IgniteManager.Memory.Allocate().GetStream())
            {
                mem.WriteBool(clientMode);
                mem.WriteBool(userLogger);

                sbyte *cfgPath0  = IgniteUtils.StringToUtf8Unmanaged(cfgPath);
                sbyte *gridName0 = IgniteUtils.StringToUtf8Unmanaged(gridName);

                try
                {
                    // OnStart receives the same InteropProcessor as here (just as another GlobalRef) and stores it.
                    // Release current reference immediately.
                    void *res = JNI.IgnitionStart(ctx.NativeContext, cfgPath0, gridName0, InteropFactoryId,
                                                  mem.SynchronizeOutput());

                    JNI.Release(res);
                }
                finally
                {
                    Marshal.FreeHGlobal(new IntPtr(cfgPath0));
                    Marshal.FreeHGlobal(new IntPtr(gridName0));
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets the native method.
        /// </summary>
        private unsafe NativeMethod GetNativeMethod(string name, string sig, Delegate d)
        {
            _delegates.Add(d);

            return new NativeMethod
            {
                Name = (IntPtr)IgniteUtils.StringToUtf8Unmanaged(name),
                Signature = (IntPtr)IgniteUtils.StringToUtf8Unmanaged(sig),
                FuncPtr = Marshal.GetFunctionPointerForDelegate(d)
            };
        }
Beispiel #3
0
        internal static void ThrowToJava(void *ctx, Exception e)
        {
            char *msgChars = (char *)IgniteUtils.StringToUtf8Unmanaged(e.Message);

            try
            {
                JNI.ThrowToJava(ctx, msgChars);
            }
            finally
            {
                Marshal.FreeHGlobal(new IntPtr(msgChars));
            }
        }
Beispiel #4
0
        internal static bool IgnitionStop(void *ctx, string gridName, bool cancel)
        {
            sbyte *gridName0 = IgniteUtils.StringToUtf8Unmanaged(gridName);

            try
            {
                return(JNI.IgnitionStop(ctx, gridName0, cancel));
            }
            finally
            {
                Marshal.FreeHGlobal(new IntPtr(gridName0));
            }
        }
Beispiel #5
0
        internal static void ProcessorDestroyCache(IUnmanagedTarget target, string name)
        {
            sbyte *name0 = IgniteUtils.StringToUtf8Unmanaged(name);

            try
            {
                JNI.ProcessorDestroyCache(target.Context, target.Target, name0);
            }
            finally
            {
                Marshal.FreeHGlobal(new IntPtr(name0));
            }
        }
Beispiel #6
0
        internal static IUnmanagedTarget ServicesGetServiceProxy(IUnmanagedTarget target, string name, bool sticky)
        {
            var nameChars = (char *)IgniteUtils.StringToUtf8Unmanaged(name);

            try
            {
                return(target.ChangeTarget(JNI.ServicesGetServiceProxy(target.Context, target.Target, nameChars, sticky)));
            }
            finally
            {
                Marshal.FreeHGlobal(new IntPtr(nameChars));
            }
        }
Beispiel #7
0
        internal static void ServicesCancel(IUnmanagedTarget target, string name)
        {
            var nameChars = (char *)IgniteUtils.StringToUtf8Unmanaged(name);

            try
            {
                JNI.ServicesCancel(target.Context, target.Target, nameChars);
            }
            finally
            {
                Marshal.FreeHGlobal(new IntPtr(nameChars));
            }
        }
Beispiel #8
0
        internal static IUnmanagedTarget ProcessorDataStreamer(IUnmanagedTarget target, string name, bool keepBinary)
        {
            sbyte *name0 = IgniteUtils.StringToUtf8Unmanaged(name);

            try
            {
                void *res = JNI.ProcessorDataStreamer(target.Context, target.Target, name0, keepBinary);

                return(target.ChangeTarget(res));
            }
            finally
            {
                Marshal.FreeHGlobal(new IntPtr(name0));
            }
        }
Beispiel #9
0
        internal static IUnmanagedTarget ProcessorGetOrCreateNearCache(IUnmanagedTarget target, string name, long memPtr)
        {
            sbyte *name0 = IgniteUtils.StringToUtf8Unmanaged(name);

            try
            {
                void *res = JNI.ProcessorGetOrCreateNearCache(target.Context, target.Target, name0, memPtr);

                return(target.ChangeTarget(res));
            }
            finally
            {
                Marshal.FreeHGlobal(new IntPtr(name0));
            }
        }
Beispiel #10
0
        internal static IUnmanagedTarget ProcessorAffinity(IUnmanagedTarget target, string name)
        {
            sbyte* name0 = IgniteUtils.StringToUtf8Unmanaged(name);

            try
            {
                void* res = JNI.ProcessorAffinity(target.Context, target.Target, name0);

                return target.ChangeTarget(res);
            }
            finally
            {
                Marshal.FreeHGlobal(new IntPtr(name0));
            }
        }
Beispiel #11
0
        internal static IUnmanagedTarget ProcessorAtomicReference(IUnmanagedTarget target, string name, long memPtr,
                                                                  bool create)
        {
            var name0 = IgniteUtils.StringToUtf8Unmanaged(name);

            try
            {
                var res = JNI.ProcessorAtomicReference(target.Context, target.Target, name0, memPtr, create);

                return(res == null ? null : target.ChangeTarget(res));
            }
            finally
            {
                Marshal.FreeHGlobal(new IntPtr(name0));
            }
        }
Beispiel #12
0
        /// <summary>
        /// Throws an exception to java.
        /// </summary>
        public void ThrowToJava(Exception e)
        {
            Debug.Assert(e != null);
            var msgChars = IgniteUtils.StringToUtf8Unmanaged(e.Message);

            try
            {
                using (var cls = FindClass("org/apache/ignite/IgniteException"))
                {
                    _throwNew(_envPtr, cls.Target, new IntPtr(msgChars));
                }
            }
            finally
            {
                Marshal.FreeHGlobal(new IntPtr(msgChars));
            }
        }
Beispiel #13
0
        /// <summary>
        /// Creates new jstring from string.
        /// </summary>
        public GlobalRef NewStringUtf(string str)
        {
            if (str == null)
            {
                return(null);
            }

            var chars = IgniteUtils.StringToUtf8Unmanaged(str);

            try
            {
                return(NewStringUtf(chars));
            }
            finally
            {
                Marshal.FreeHGlobal(new IntPtr(chars));
            }
        }
Beispiel #14
0
        internal static void ProcessorLoggerLog(IUnmanagedTarget target, int level, string message, string category,
                                                string errorInfo)
        {
            var message0   = IgniteUtils.StringToUtf8Unmanaged(message);
            var category0  = IgniteUtils.StringToUtf8Unmanaged(category);
            var errorInfo0 = IgniteUtils.StringToUtf8Unmanaged(errorInfo);

            try
            {
                JNI.ProcessorLoggerLog(target.Context, target.Target, level, message0, category0, errorInfo0);
            }
            finally
            {
                Marshal.FreeHGlobal(new IntPtr(message0));
                Marshal.FreeHGlobal(new IntPtr(category0));
                Marshal.FreeHGlobal(new IntPtr(errorInfo0));
            }
        }
Beispiel #15
0
        internal static IUnmanagedTarget IgnitionStart(UnmanagedContext ctx, string cfgPath, string gridName,
                                                       bool clientMode)
        {
            using (var mem = IgniteManager.Memory.Allocate().GetStream())
            {
                mem.WriteBool(clientMode);

                sbyte *cfgPath0  = IgniteUtils.StringToUtf8Unmanaged(cfgPath);
                sbyte *gridName0 = IgniteUtils.StringToUtf8Unmanaged(gridName);

                try
                {
                    void *res = JNI.IgnitionStart(ctx.NativeContext, cfgPath0, gridName0, InteropFactoryId,
                                                  mem.SynchronizeOutput());

                    return(new UnmanagedTarget(ctx, res));
                }
                finally
                {
                    Marshal.FreeHGlobal(new IntPtr(cfgPath0));
                    Marshal.FreeHGlobal(new IntPtr(gridName0));
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// Starts Ignite with given configuration.
        /// </summary>
        /// <returns>Started Ignite.</returns>
        public unsafe static IIgnite Start(IgniteConfiguration cfg)
        {
            IgniteArgumentCheck.NotNull(cfg, "cfg");

            // Copy configuration to avoid changes to user-provided instance.
            IgniteConfigurationEx cfgEx = cfg as IgniteConfigurationEx;

            cfg = cfgEx == null ? new IgniteConfiguration(cfg) : new IgniteConfigurationEx(cfgEx);

            // Set default Spring config if needed.
            if (cfg.SpringConfigUrl == null)
            {
                cfg.SpringConfigUrl = DefaultCfg;
            }

            lock (SyncRoot)
            {
                // 1. Check GC settings.
                CheckServerGc(cfg);

                // 2. Create context.
                IgniteUtils.LoadDlls(cfg.JvmDllPath);

                var cbs = new UnmanagedCallbacks();

                void *ctx = IgniteManager.GetContext(cfg, cbs);

                sbyte *cfgPath0 = IgniteUtils.StringToUtf8Unmanaged(cfg.SpringConfigUrl ?? DefaultCfg);

                string gridName  = cfgEx != null ? cfgEx.GridName : null;
                sbyte *gridName0 = IgniteUtils.StringToUtf8Unmanaged(gridName);

                // 3. Create startup object which will guide us through the rest of the process.
                _startup = new Startup(cfg, cbs)
                {
                    Context = ctx
                };

                IUnmanagedTarget interopProc = null;

                try
                {
                    // 4. Initiate Ignite start.
                    UU.IgnitionStart(cbs.Context, cfg.SpringConfigUrl ?? DefaultCfg,
                                     cfgEx != null ? cfgEx.GridName : null, ClientMode);

                    // 5. At this point start routine is finished. We expect STARTUP object to have all necessary data.
                    var node = _startup.Ignite;
                    interopProc = node.InteropProcessor;

                    // 6. On-start callback (notify lifecycle components).
                    node.OnStart();

                    Nodes[new NodeKey(_startup.Name)] = node;

                    return(node);
                }
                catch (Exception)
                {
                    // 1. Perform keys cleanup.
                    string name = _startup.Name;

                    if (name != null)
                    {
                        NodeKey key = new NodeKey(name);

                        if (Nodes.ContainsKey(key))
                        {
                            Nodes.Remove(key);
                        }
                    }

                    // 2. Stop Ignite node if it was started.
                    if (interopProc != null)
                    {
                        UU.IgnitionStop(interopProc.Context, gridName, true);
                    }

                    // 3. Throw error further (use startup error if exists because it is more precise).
                    if (_startup.Error != null)
                    {
                        throw _startup.Error;
                    }

                    throw;
                }
                finally
                {
                    _startup = null;

                    Marshal.FreeHGlobal((IntPtr)cfgPath0);

                    if ((IntPtr)gridName0 != IntPtr.Zero)
                    {
                        Marshal.FreeHGlobal((IntPtr)gridName0);
                    }

                    if (interopProc != null)
                    {
                        UU.ProcessorReleaseStart(interopProc);
                    }
                }
            }
        }