private T SafeCall <T>(Func <T> func, bool allowUnitialized = false)
        {
            if (!allowUnitialized)
            {
                _initEvent.Wait();
            }

            try
            {
                return(func());
            }
            catch (Exception e)
            {
                UU.ThrowToJava(_ctx.NativeContext, e);

                return(default(T));
            }
        }
        private long AffinityFunctionInit(long memPtr, long unused, long unused1, void *baseFunc)
        {
            using (var stream = IgniteManager.Memory.Get(memPtr).GetStream())
            {
                var reader = BinaryUtils.Marshaller.StartUnmarshal(stream);

                var func = reader.ReadObjectEx <IAffinityFunction>();

                ResourceProcessor.Inject(func, _ignite);

                var affBase = func as AffinityFunctionBase;

                if (affBase != null)
                {
                    var baseFunc0 = new PlatformJniTarget(UU.Acquire(_ctx, baseFunc), _ignite.Marshaller);

                    affBase.SetBaseFunction(new PlatformAffinityFunction(baseFunc0));
                }

                return(_handleRegistry.Allocate(func));
            }
        }
Exemple #3
0
        /// <summary>
        /// Internal stop routine.
        /// </summary>
        /// <param name="cancel">Cancel flag.</param>
        internal unsafe void Stop(bool cancel)
        {
            UU.IgnitionStop(_proc.Context, Name, cancel);

            _cbs.Cleanup();
        }
        /// <summary>
        /// Starts Ignite with given configuration.
        /// </summary>
        /// <returns>Started Ignite.</returns>
        public static IIgnite Start(IgniteConfiguration cfg)
        {
            IgniteArgumentCheck.NotNull(cfg, "cfg");

            cfg = new IgniteConfiguration(cfg);  // Create a copy so that config can be modified and reused.

            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.
                JvmDll.Load(cfg.JvmDllPath, log);

                var cbs = IgniteManager.CreateJvmContext(cfg, log);
                var env = cbs.Jvm.AttachCurrentThread();
                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(env, cfg.SpringConfigUrl, gridName, ClientMode, cfg.Logger != null, cbs.IgniteId,
                                     cfg.RedirectJavaConsoleOutput);

                    // 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 ex)
                {
                    // 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(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);
                    }

                    var jex = ex as JavaException;

                    if (jex == null)
                    {
                        throw;
                    }

                    throw ExceptionUtils.GetException(null, jex);
                }
                finally
                {
                    var ignite = _startup.Ignite;

                    _startup = null;

                    if (ignite != null)
                    {
                        ignite.ProcessorReleaseStart();
                    }
                }
            }
        }
Exemple #5
0
 /** <inheritDoc /> */
 public IClusterGroup ForYoungest()
 {
     return(GetClusterGroup(UU.ProjectionForYoungest(Target)));
 }
Exemple #6
0
 /** <inheritdoc /> */
 public void Clear()
 {
     UU.CacheClear(Target);
 }
Exemple #7
0
        /// <summary>
        /// Internal size routine.
        /// </summary>
        /// <param name="loc">Local flag.</param>
        /// <param name="modes">peek modes</param>
        /// <returns>Size.</returns>
        private int Size0(bool loc, params CachePeekMode[] modes)
        {
            int modes0 = EncodePeekModes(modes);

            return(UU.CacheSize(Target, modes0, loc));
        }
Exemple #8
0
 /** <inheritdoc /> */
 public IDataStreamer <TK, TV> GetDataStreamer <TK, TV>(string cacheName)
 {
     return(new DataStreamerImpl <TK, TV>(UU.ProcessorDataStreamer(_proc, cacheName, false),
                                          _marsh, cacheName, false));
 }
Exemple #9
0
 /// <summary>
 /// Perform out operation.
 /// </summary>
 /// <param name="type">Operation type.</param>
 /// <returns>Resulting object.</returns>
 protected IUnmanagedTarget DoOutOpObject(int type)
 {
     return(UU.TargetOutObject(_target, type));
 }
Exemple #10
0
 /// <summary>
 /// Rollback transaction.
 /// </summary>
 /// <param name="tx">Transaction.</param>
 /// <returns>Final transaction state.</returns>
 internal TransactionState TxRollback(TransactionImpl tx)
 {
     return((TransactionState)UU.TransactionsRollback(Target, tx.Id));
 }
Exemple #11
0
 /// <summary>
 /// Close transaction.
 /// </summary>
 /// <param name="tx">Transaction.</param>
 /// <returns>Final transaction state.</returns>
 internal int TxClose(TransactionImpl tx)
 {
     return(UU.TransactionsClose(Target, tx.Id));
 }
Exemple #12
0
 /** <inheritDoc /> */
 public void ResetMetrics()
 {
     UU.TransactionsResetMetrics(Target);
 }
Exemple #13
0
 /// <summary>
 /// Commit transaction.
 /// </summary>
 /// <param name="tx">Transaction.</param>
 /// <returns>Final transaction state.</returns>
 internal TransactionState TxCommit(TransactionImpl tx)
 {
     return((TransactionState)UU.TransactionsCommit(Target, tx.Id));
 }
Exemple #14
0
 /** <inheritdoc /> */
 public void ResetMetrics()
 {
     UU.ProjectionResetMetrics(_prj.Target);
 }
Exemple #15
0
 /// <summary>
 /// Commits tx in async mode.
 /// </summary>
 internal IFuture CommitAsync(TransactionImpl tx)
 {
     return(GetFuture <object>((futId, futTyp) => UU.TransactionsCommitAsync(Target, tx.Id, futId)));
 }
Exemple #16
0
 /** <inheritDoc /> */
 public IClusterGroup ForServers()
 {
     return(GetClusterGroup(UU.ProjectionForServers(Target)));
 }
Exemple #17
0
 /** <inheritdoc /> */
 public ICache <TK, TV> CreateCache <TK, TV>(string name)
 {
     return(Cache <TK, TV>(UU.ProcessorCreateCache(_proc, name)));
 }
Exemple #18
0
 /// <summary>
 /// Get transaction current state.
 /// </summary>
 /// <param name="tx">Transaction.</param>
 /// <returns>Transaction current state.</returns>
 internal TransactionState TxState(TransactionImpl tx)
 {
     return(GetTransactionState(UU.TransactionsState(Target, tx.Id)));
 }
Exemple #19
0
 /** <inheritdoc /> */
 public void DestroyCache(string name)
 {
     UU.ProcessorDestroyCache(_proc, name);
 }
Exemple #20
0
 /// <summary>
 /// Set transaction rollback-only flag.
 /// </summary>
 /// <param name="tx">Transaction.</param>
 /// <returns><c>true</c> if the flag was set.</returns>
 internal bool TxSetRollbackOnly(TransactionImpl tx)
 {
     return(UU.TransactionsSetRollbackOnly(Target, tx.Id));
 }
Exemple #21
0
 /** <inheritdoc /> */
 public ICacheAffinity GetAffinity(string cacheName)
 {
     return(new CacheAffinityImpl(UU.ProcessorAffinity(_proc, cacheName), _marsh, false, this));
 }
Exemple #22
0
 /// <summary>
 /// Rolls tx back in async mode.
 /// </summary>
 internal Task RollbackAsync(TransactionImpl tx)
 {
     return(GetFuture <object>((futId, futTyp) => UU.TransactionsRollbackAsync(Target, tx.Id, futId)).Task);
 }
Exemple #23
0
 /// <summary>
 /// Perform simple out-in operation accepting two arguments.
 /// </summary>
 /// <param name="type">Operation type.</param>
 /// <param name="val">Value.</param>
 /// <returns>Result.</returns>
 protected long DoOutInOp(int type, long val = 0)
 {
     return(UU.TargetInLongOutLong(_target, type, val));
 }
Exemple #24
0
 /** <inheritdoc /> */
 public override IFuture <T> GetFuture <T>()
 {
     return(GetFuture <T>((futId, futTyp) => UU.TargetListenFuture(Target, futId, futTyp)));
 }
Exemple #25
0
 /** <inheritDoc /> */
 public void RemoveAll()
 {
     UU.CacheRemoveAll(Target);
 }
Exemple #26
0
 /** <inheritDoc /> */
 public IClusterGroup ForDaemons()
 {
     return(GetClusterGroup(UU.ProjectionForDaemons(Target)));
 }
Exemple #27
0
 /** <inheritDoc /> */
 public Task Rebalance()
 {
     return(GetFuture <object>((futId, futTyp) => UU.CacheRebalance(Target, futId)).Task);
 }
Exemple #28
0
        /// <summary>
        /// Starts Ignite with given configuration.
        /// </summary>
        /// <returns>Started Ignite.</returns>
        public unsafe static 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);
                    }
                }
            }
        }
Exemple #29
0
        /// <summary>
        /// constructor.
        /// </summary>
        public UnmanagedCallbacks()
        {
            var cbs = new UnmanagedCallbackHandlers
            {
                target = IntPtr.Zero.ToPointer(), // Target is not used in .Net as we rely on dynamic FP creation.

                cacheStoreCreate  = CreateFunctionPointer((CacheStoreCreateCallbackDelegate)CacheStoreCreate),
                cacheStoreInvoke  = CreateFunctionPointer((CacheStoreInvokeCallbackDelegate)CacheStoreInvoke),
                cacheStoreDestroy = CreateFunctionPointer((CacheStoreDestroyCallbackDelegate)CacheStoreDestroy),

                cacheStoreSessionCreate = CreateFunctionPointer((CacheStoreSessionCreateCallbackDelegate)CacheStoreSessionCreate),

                cacheEntryFilterCreate  = CreateFunctionPointer((CacheEntryFilterCreateCallbackDelegate)CacheEntryFilterCreate),
                cacheEntryFilterApply   = CreateFunctionPointer((CacheEntryFilterApplyCallbackDelegate)CacheEntryFilterApply),
                cacheEntryFilterDestroy = CreateFunctionPointer((CacheEntryFilterDestroyCallbackDelegate)CacheEntryFilterDestroy),

                cacheInvoke = CreateFunctionPointer((CacheInvokeCallbackDelegate)CacheInvoke),

                computeTaskMap       = CreateFunctionPointer((ComputeTaskMapCallbackDelegate)ComputeTaskMap),
                computeTaskJobResult =
                    CreateFunctionPointer((ComputeTaskJobResultCallbackDelegate)ComputeTaskJobResult),
                computeTaskReduce            = CreateFunctionPointer((ComputeTaskReduceCallbackDelegate)ComputeTaskReduce),
                computeTaskComplete          = CreateFunctionPointer((ComputeTaskCompleteCallbackDelegate)ComputeTaskComplete),
                computeJobSerialize          = CreateFunctionPointer((ComputeJobSerializeCallbackDelegate)ComputeJobSerialize),
                computeJobCreate             = CreateFunctionPointer((ComputeJobCreateCallbackDelegate)ComputeJobCreate),
                computeJobExecute            = CreateFunctionPointer((ComputeJobExecuteCallbackDelegate)ComputeJobExecute),
                computeJobCancel             = CreateFunctionPointer((ComputeJobCancelCallbackDelegate)ComputeJobCancel),
                computeJobDestroy            = CreateFunctionPointer((ComputeJobDestroyCallbackDelegate)ComputeJobDestroy),
                continuousQueryListenerApply =
                    CreateFunctionPointer((ContinuousQueryListenerApplyCallbackDelegate)ContinuousQueryListenerApply),
                continuousQueryFilterCreate =
                    CreateFunctionPointer((ContinuousQueryFilterCreateCallbackDelegate)ContinuousQueryFilterCreate),
                continuousQueryFilterApply =
                    CreateFunctionPointer((ContinuousQueryFilterApplyCallbackDelegate)ContinuousQueryFilterApply),
                continuousQueryFilterRelease =
                    CreateFunctionPointer((ContinuousQueryFilterReleaseCallbackDelegate)ContinuousQueryFilterRelease),
                dataStreamerTopologyUpdate =
                    CreateFunctionPointer((DataStreamerTopologyUpdateCallbackDelegate)DataStreamerTopologyUpdate),
                dataStreamerStreamReceiverInvoke =
                    CreateFunctionPointer((DataStreamerStreamReceiverInvokeCallbackDelegate)DataStreamerStreamReceiverInvoke),

                futureByteResult   = CreateFunctionPointer((FutureByteResultCallbackDelegate)FutureByteResult),
                futureBoolResult   = CreateFunctionPointer((FutureBoolResultCallbackDelegate)FutureBoolResult),
                futureShortResult  = CreateFunctionPointer((FutureShortResultCallbackDelegate)FutureShortResult),
                futureCharResult   = CreateFunctionPointer((FutureCharResultCallbackDelegate)FutureCharResult),
                futureIntResult    = CreateFunctionPointer((FutureIntResultCallbackDelegate)FutureIntResult),
                futureFloatResult  = CreateFunctionPointer((FutureFloatResultCallbackDelegate)FutureFloatResult),
                futureLongResult   = CreateFunctionPointer((FutureLongResultCallbackDelegate)FutureLongResult),
                futureDoubleResult = CreateFunctionPointer((FutureDoubleResultCallbackDelegate)FutureDoubleResult),
                futureObjectResult = CreateFunctionPointer((FutureObjectResultCallbackDelegate)FutureObjectResult),
                futureNullResult   = CreateFunctionPointer((FutureNullResultCallbackDelegate)FutureNullResult),
                futureError        = CreateFunctionPointer((FutureErrorCallbackDelegate)FutureError),
                lifecycleOnEvent   = CreateFunctionPointer((LifecycleOnEventCallbackDelegate)LifecycleOnEvent),
                memoryReallocate   = CreateFunctionPointer((MemoryReallocateCallbackDelegate)MemoryReallocate),
                nodeInfo           = CreateFunctionPointer((NodeInfoCallbackDelegate)NodeInfo),

                messagingFilterCreate  = CreateFunctionPointer((MessagingFilterCreateCallbackDelegate)MessagingFilterCreate),
                messagingFilterApply   = CreateFunctionPointer((MessagingFilterApplyCallbackDelegate)MessagingFilterApply),
                messagingFilterDestroy = CreateFunctionPointer((MessagingFilterDestroyCallbackDelegate)MessagingFilterDestroy),

                eventFilterCreate  = CreateFunctionPointer((EventFilterCreateCallbackDelegate)EventFilterCreate),
                eventFilterApply   = CreateFunctionPointer((EventFilterApplyCallbackDelegate)EventFilterApply),
                eventFilterDestroy = CreateFunctionPointer((EventFilterDestroyCallbackDelegate)EventFilterDestroy),

                serviceInit         = CreateFunctionPointer((ServiceInitCallbackDelegate)ServiceInit),
                serviceExecute      = CreateFunctionPointer((ServiceExecuteCallbackDelegate)ServiceExecute),
                serviceCancel       = CreateFunctionPointer((ServiceCancelCallbackDelegate)ServiceCancel),
                serviceInvokeMethod = CreateFunctionPointer((ServiceInvokeMethodCallbackDelegate)ServiceInvokeMethod),

                clusterNodeFilterApply = CreateFunctionPointer((СlusterNodeFilterApplyCallbackDelegate)СlusterNodeFilterApply),

                onStart = CreateFunctionPointer((OnStartCallbackDelegate)OnStart),
                onStop  = CreateFunctionPointer((OnStopCallbackDelegate)OnStop),
                error   = CreateFunctionPointer((ErrorCallbackDelegate)Error),

                extensionCbInLongOutLong     = CreateFunctionPointer((ExtensionCallbackInLongOutLongDelegate)ExtensionCallbackInLongOutLong),
                extensionCbInLongLongOutLong = CreateFunctionPointer((ExtensionCallbackInLongLongOutLongDelegate)ExtensionCallbackInLongLongOutLong),

                onClientDisconnected = CreateFunctionPointer((OnClientDisconnectedDelegate)OnClientDisconnected),
                ocClientReconnected  = CreateFunctionPointer((OnClientReconnectedDelegate)OnClientReconnected),
            };

            _cbsPtr = Marshal.AllocHGlobal(UU.HandlersSize());

            Marshal.StructureToPtr(cbs, _cbsPtr, false);

            _thisHnd = GCHandle.Alloc(this);
        }
Exemple #30
0
 /** <inheritDoc /> */
 public IClusterGroup ForRandom()
 {
     return(GetClusterGroup(UU.ProjectionForRandom(Target)));
 }