/// <summary> /// Constructor. /// </summary> /// <param name="cfg">Configuration.</param> /// <param name="name">Grid name.</param> /// <param name="proc">Interop processor.</param> /// <param name="marsh">Marshaller.</param> /// <param name="lifecycleBeans">Lifecycle beans.</param> /// <param name="cbs">Callbacks.</param> public Ignite(IgniteConfiguration cfg, string name, IUnmanagedTarget proc, Marshaller marsh, IList <LifecycleBeanHolder> lifecycleBeans, UnmanagedCallbacks cbs) { Debug.Assert(cfg != null); Debug.Assert(proc != null); Debug.Assert(marsh != null); Debug.Assert(lifecycleBeans != null); Debug.Assert(cbs != null); _cfg = cfg; _name = name; _proc = proc; _marsh = marsh; _lifecycleBeans = lifecycleBeans; _cbs = cbs; marsh.Ignite = this; _prj = new ClusterGroupImpl(proc, UU.ProcessorProjection(proc), marsh, this, null); _binary = new Binary.Binary(marsh); _proxy = new IgniteProxy(this); cbs.Initialize(this); // Grid is not completely started here, can't initialize interop transactions right away. _transactions = new Lazy <TransactionsImpl>( () => new TransactionsImpl(UU.ProcessorTransactions(proc), marsh, GetLocalNode().Id)); }
/// <summary> /// Create JVM. /// </summary> /// <param name="cfg">Configuration.</param> /// <param name="cbs">Callbacks.</param> /// <returns>Context.</returns> internal static void CreateJvmContext(IgniteConfiguration cfg, UnmanagedCallbacks cbs) { lock (SyncRoot) { // 1. Warn about possible configuration inconsistency. JvmConfiguration jvmCfg = JvmConfig(cfg); if (!cfg.SuppressWarnings && _jvmCfg != null) { if (!_jvmCfg.Equals(jvmCfg)) { Console.WriteLine("Attempting to start Ignite node with different Java " + "configuration; current Java configuration will be ignored (consider " + "starting node in separate process) [oldConfig=" + _jvmCfg + ", newConfig=" + jvmCfg + ']'); } } // 2. Create unmanaged pointer. void *ctx = CreateJvm(cfg, cbs); cbs.SetContext(ctx); // 3. If this is the first JVM created, preserve it. if (_ctx == null) { _ctx = ctx; _jvmCfg = jvmCfg; } } }
/// <summary> /// Create JVM. /// </summary> /// <param name="cfg">Configuration.</param> /// <param name="cbs">Callbacks.</param> /// <returns>Context.</returns> internal static void CreateJvmContext(IgniteConfiguration cfg, UnmanagedCallbacks cbs) { lock (SyncRoot) { // 1. Warn about possible configuration inconsistency. JvmConfiguration jvmCfg = JvmConfig(cfg); if (!cfg.SuppressWarnings && _jvmCfg != null) { if (!_jvmCfg.Equals(jvmCfg)) { Console.WriteLine("Attempting to start Ignite node with different Java " + "configuration; current Java configuration will be ignored (consider " + "starting node in separate process) [oldConfig=" + _jvmCfg + ", newConfig=" + jvmCfg + ']'); } } // 2. Create unmanaged pointer. void* ctx = CreateJvm(cfg, cbs); cbs.SetContext(ctx); // 3. If this is the first JVM created, preserve it. if (_ctx == null) { _ctx = ctx; _jvmCfg = jvmCfg; } } }
/// <summary> /// Constructor. /// </summary> /// <param name="cfg">Configuration.</param> /// <param name="name">Grid name.</param> /// <param name="proc">Interop processor.</param> /// <param name="marsh">Marshaller.</param> /// <param name="lifecycleHandlers">Lifecycle beans.</param> /// <param name="cbs">Callbacks.</param> public Ignite(IgniteConfiguration cfg, string name, IPlatformTargetInternal proc, Marshaller marsh, IList <LifecycleHandlerHolder> lifecycleHandlers, UnmanagedCallbacks cbs) : base(proc) { Debug.Assert(cfg != null); Debug.Assert(proc != null); Debug.Assert(marsh != null); Debug.Assert(lifecycleHandlers != null); Debug.Assert(cbs != null); _cfg = cfg; _name = name; _proc = proc; _marsh = marsh; _lifecycleHandlers = lifecycleHandlers; _cbs = cbs; marsh.Ignite = this; _prj = new ClusterGroupImpl(Target.OutObjectInternal((int)Op.GetClusterGroup), null); _binary = new Binary.Binary(marsh); _binaryProc = new BinaryProcessor(DoOutOpObject((int)Op.GetBinaryProcessor)); cbs.Initialize(this); // Set reconnected task to completed state for convenience. _clientReconnectTaskCompletionSource.SetResult(false); SetCompactFooter(); _pluginProcessor = new PluginProcessor(this); }
/// <summary> /// Create JVM. /// </summary> /// <returns>JVM.</returns> private static void *CreateJvm(IgniteConfiguration cfg, UnmanagedCallbacks cbs) { var ggHome = IgniteHome.Resolve(cfg); var cp = Classpath.CreateClasspath(ggHome, cfg, false); var jvmOpts = GetMergedJvmOptions(cfg); var hasGgHome = !string.IsNullOrWhiteSpace(ggHome); var opts = new sbyte *[1 + jvmOpts.Count + (hasGgHome ? 1 : 0)]; int idx = 0; opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cp); if (hasGgHome) { opts[idx++] = IgniteUtils.StringToUtf8Unmanaged("-DIGNITE_HOME=" + ggHome); } foreach (string cfgOpt in jvmOpts) { opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cfgOpt); } try { IntPtr mem = Marshal.AllocHGlobal(opts.Length * 8); fixed(sbyte **opts0 = opts) { PlatformMemoryUtils.CopyMemory(opts0, mem.ToPointer(), opts.Length * 8); } try { return(UU.CreateContext(mem.ToPointer(), opts.Length, cbs.CallbacksPointer)); } finally { Marshal.FreeHGlobal(mem); } } finally { foreach (sbyte *opt in opts) { Marshal.FreeHGlobal((IntPtr)opt); } } }
/// <summary> /// Create JVM. /// </summary> /// <returns>JVM.</returns> private static void *CreateJvm(IgniteConfiguration cfg, UnmanagedCallbacks cbs) { var cp = Classpath.CreateClasspath(cfg); var jvmOpts = GetMergedJvmOptions(cfg); var opts = new sbyte *[1 + jvmOpts.Count]; int idx = 0; opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cp); foreach (string cfgOpt in jvmOpts) { opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cfgOpt); } try { IntPtr mem = Marshal.AllocHGlobal(opts.Length * 8); fixed(sbyte **opts0 = opts) { PlatformMemoryUtils.CopyMemory(opts0, mem.ToPointer(), opts.Length * 8); } try { return(UU.CreateContext(mem.ToPointer(), opts.Length, cbs.CallbacksPointer)); } finally { Marshal.FreeHGlobal(mem); } } finally { foreach (sbyte *opt in opts) { Marshal.FreeHGlobal((IntPtr)opt); } } }
/// <summary> /// Constructor. /// </summary> /// <param name="cfg">Configuration.</param> /// <param name="name">Grid name.</param> /// <param name="proc">Interop processor.</param> /// <param name="marsh">Marshaller.</param> /// <param name="lifecycleBeans">Lifecycle beans.</param> /// <param name="cbs">Callbacks.</param> public Ignite(IgniteConfiguration cfg, string name, IUnmanagedTarget proc, Marshaller marsh, IList <LifecycleBeanHolder> lifecycleBeans, UnmanagedCallbacks cbs) { Debug.Assert(cfg != null); Debug.Assert(proc != null); Debug.Assert(marsh != null); Debug.Assert(lifecycleBeans != null); Debug.Assert(cbs != null); _cfg = cfg; _name = name; _proc = proc; _marsh = marsh; _lifecycleBeans = lifecycleBeans; _cbs = cbs; marsh.Ignite = this; _prj = new ClusterGroupImpl(proc, UU.ProcessorProjection(proc), marsh, this, null); _binary = new Binary.Binary(marsh); _binaryProc = new BinaryProcessor(UU.ProcessorBinaryProcessor(proc), marsh); _proxy = new IgniteProxy(this); cbs.Initialize(this); // Grid is not completely started here, can't initialize interop transactions right away. _transactions = new Lazy <TransactionsImpl>( () => new TransactionsImpl(UU.ProcessorTransactions(proc), marsh, GetLocalNode().Id)); // Set reconnected task to completed state for convenience. _clientReconnectTaskCompletionSource.SetResult(false); SetCompactFooter(); _pluginProcessor = new PluginProcessor(this); }
/// <summary> /// Create JVM. /// </summary> /// <param name="cfg">Configuration.</param> /// <param name="log">Logger</param> /// <returns>Callback context.</returns> internal static UnmanagedCallbacks CreateJvmContext(IgniteConfiguration cfg, ILogger log) { lock (SyncRoot) { // 1. Warn about possible configuration inconsistency. JvmConfiguration jvmCfg = JvmConfig(cfg); if (!cfg.SuppressWarnings && _jvmCfg != null) { if (!_jvmCfg.Equals(jvmCfg)) { log.Warn("Attempting to start Ignite node with different Java " + "configuration; current Java configuration will be ignored (consider " + "starting node in separate process) [oldConfig=" + _jvmCfg + ", newConfig=" + jvmCfg + ']'); } } // 2. Create unmanaged pointer. var jvm = CreateJvm(cfg, log); if (cfg.RedirectJavaConsoleOutput) { jvm.EnableJavaConsoleWriter(); } var cbs = new UnmanagedCallbacks(log, jvm); jvm.RegisterCallbacks(cbs); // 3. If this is the first JVM created, preserve configuration. if (_jvmCfg == null) { _jvmCfg = jvmCfg; } return(cbs); } }
/// <summary> /// Constructor. /// </summary> /// <param name="cfg">Configuration.</param> /// <param name="cbs"></param> internal Startup(IgniteConfiguration cfg, UnmanagedCallbacks cbs) { Configuration = cfg; Callbacks = cbs; }
/// <summary> /// Create JVM. /// </summary> /// <returns>JVM.</returns> private static void* CreateJvm(IgniteConfiguration cfg, UnmanagedCallbacks cbs) { var cp = Classpath.CreateClasspath(cfg); var jvmOpts = GetMergedJvmOptions(cfg); var opts = new sbyte*[1 + jvmOpts.Count]; int idx = 0; opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cp); foreach (string cfgOpt in jvmOpts) opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cfgOpt); try { IntPtr mem = Marshal.AllocHGlobal(opts.Length * 8); fixed (sbyte** opts0 = opts) { PlatformMemoryUtils.CopyMemory(opts0, mem.ToPointer(), opts.Length * 8); } try { return UU.CreateContext(mem.ToPointer(), opts.Length, cbs.CallbacksPointer); } finally { Marshal.FreeHGlobal(mem); } } finally { foreach (sbyte* opt in opts) Marshal.FreeHGlobal((IntPtr)opt); } }
/// <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 static unsafe IIgnite Start(IgniteConfiguration cfg) { IgniteArgumentCheck.NotNull(cfg, "cfg"); 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 = cfg.GridName; var cfgPath = cfg.SpringConfigUrl == null ? null : 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); } } }
/// <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); } } }
/// <summary> /// Registers callback handlers. /// </summary> public long RegisterHandlers(UnmanagedCallbacks cbs) { Debug.Assert(cbs != null); return _callbackRegistry.AllocateCritical(cbs); }
/// <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); } } } }
/// <summary> /// Create JVM. /// </summary> /// <returns>JVM.</returns> private static void* CreateJvm(IgniteConfiguration cfg, UnmanagedCallbacks cbs) { var ggHome = GetIgniteHome(cfg); var cp = CreateClasspath(ggHome, cfg, false); var jvmOpts = GetMergedJvmOptions(cfg); var hasGgHome = !string.IsNullOrWhiteSpace(ggHome); var opts = new sbyte*[1 + jvmOpts.Count + (hasGgHome ? 1 : 0)]; int idx = 0; opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cp); if (hasGgHome) opts[idx++] = IgniteUtils.StringToUtf8Unmanaged("-DIGNITE_HOME=" + ggHome); foreach (string cfgOpt in jvmOpts) opts[idx++] = IgniteUtils.StringToUtf8Unmanaged(cfgOpt); try { IntPtr mem = Marshal.AllocHGlobal(opts.Length * 8); fixed (sbyte** opts0 = opts) { PlatformMemoryUtils.CopyMemory(opts0, mem.ToPointer(), opts.Length * 8); } try { return UU.CreateContext(mem.ToPointer(), opts.Length, cbs.CallbacksPointer); } finally { Marshal.FreeHGlobal(mem); } } finally { foreach (sbyte* opt in opts) Marshal.FreeHGlobal((IntPtr)opt); } }
/// <summary> /// Registers the callbacks. /// </summary> public void RegisterCallbacks(UnmanagedCallbacks cbs) { var id = _callbacks.RegisterHandlers(cbs); cbs.SetContext(id); }