/// <summary> /// Starts Ignite with given configuration. /// </summary> /// <returns>Started Ignite.</returns> public static unsafe IIgnite Start(IgniteConfiguration cfg) { IgniteArgumentCheck.NotNull(cfg, "cfg"); lock (SyncRoot) { // 0. Init logger var log = cfg.Logger ?? new JavaLogger(); log.Debug("Starting Ignite.NET " + Assembly.GetExecutingAssembly().GetName().Version); // 1. Check GC settings. CheckServerGc(cfg, log); // 2. Create context. IgniteUtils.LoadDlls(cfg.JvmDllPath, log); var cbs = new UnmanagedCallbacks(log); IgniteManager.CreateJvmContext(cfg, cbs, log); log.Debug("JVM started."); var gridName = cfg.IgniteInstanceName; if (cfg.AutoGenerateIgniteInstanceName) { gridName = (gridName ?? "ignite-instance-") + Guid.NewGuid(); } // 3. Create startup object which will guide us through the rest of the process. _startup = new Startup(cfg, cbs); PlatformJniTarget interopProc = null; try { // 4. Initiate Ignite start. UU.IgnitionStart(cbs.Context, cfg.SpringConfigUrl, gridName, ClientMode, cfg.Logger != null); // 5. At this point start routine is finished. We expect STARTUP object to have all necessary data. var node = _startup.Ignite; interopProc = (PlatformJniTarget)node.InteropProcessor; var javaLogger = log as JavaLogger; if (javaLogger != null) { javaLogger.SetIgnite(node); } // 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.Target.Context, gridName, true); } // 3. Throw error further (use startup error if exists because it is more precise). if (_startup.Error != null) { // Wrap in a new exception to preserve original stack trace. throw new IgniteException("Failed to start Ignite.NET, check inner exception for details", _startup.Error); } throw; } finally { var ignite = _startup.Ignite; _startup = null; if (ignite != null) { ignite.ProcessorReleaseStart(); } } } }
/// <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(); IgniteManager.CreateJvmContext(cfg, cbs); var gridName = cfgEx != null ? cfgEx.GridName : null; var cfgPath = Environment.GetEnvironmentVariable(EnvIgniteSpringConfigUrlPrefix) + cfg.SpringConfigUrl; // 3. Create startup object which will guide us through the rest of the process. _startup = new Startup(cfg, cbs); IUnmanagedTarget interopProc = null; try { // 4. Initiate Ignite start. UU.IgnitionStart(cbs.Context, cfgPath, gridName, 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; if (interopProc != null) { UU.ProcessorReleaseStart(interopProc); } } } }