示例#1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="target">Target.</param>
        /// <param name="prj">Projection.</param>
        /// <param name="keepBinary">Binary flag.</param>
        public ComputeImpl(IPlatformTargetInternal target, ClusterGroupImpl prj, bool keepBinary)
            : base(target)
        {
            _prj = prj;

            _keepBinary.Value = keepBinary;
        }
示例#2
0
        /// <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);
        }
示例#3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="target">Target.</param>
        /// <param name="marsh">Marshaller.</param>
        /// <param name="prj">Projection.</param>
        /// <param name="keepBinary">Binary flag.</param>
        public ComputeImpl(IUnmanagedTarget target, Marshaller marsh, ClusterGroupImpl prj, bool keepBinary)
            : base(target, marsh)
        {
            _prj = prj;

            _keepBinary.Value = keepBinary;
        }
示例#4
0
        internal bool Serialize(IPortableStream stream)
        {
            ClusterGroupImpl prj = _ignite.ClusterGroup;

            PortableWriterImpl writer = prj.Marshaller.StartMarshal(stream);

            try
            {
                writer.Write(this);

                return(true);
            }
            catch (Exception e)
            {
                writer.WriteString("Failed to marshal job [job=" + _job + ", errType=" + e.GetType().Name +
                                   ", errMsg=" + e.Message + ']');

                return(false);
            }
            finally
            {
                // 4. Process metadata.
                prj.FinishMarshal(writer);
            }
        }
示例#5
0
        /// <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));
        }
示例#6
0
        /// <summary>
        /// Execute job serializing result to the stream.
        /// </summary>
        /// <param name="cancel">Whether the job must be cancelled.</param>
        /// <param name="stream">Stream.</param>
        public void ExecuteRemote(PlatformMemoryStream stream, bool cancel)
        {
            // 1. Execute job.
            object res;
            bool   success;

            using (PeerAssemblyResolver.GetInstance(_ignite, Guid.Empty))
            {
                Execute0(cancel, out res, out success);
            }

            // 2. Try writing result to the stream.
            ClusterGroupImpl prj = _ignite.ClusterGroup;

            BinaryWriter writer = prj.Marshaller.StartMarshal(stream);

            try
            {
                // 3. Marshal results.
                BinaryUtils.WriteInvocationResult(writer, success, res);
            }
            finally
            {
                // 4. Process metadata.
                prj.FinishMarshal(writer);
            }
        }
示例#7
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="target">Target.</param>
        /// <param name="marsh">Marshaller.</param>
        /// <param name="prj">Projection.</param>
        /// <param name="keepPortable">"keepPortable" flag.</param>
        public ComputeImpl(IUnmanagedTarget target, PortableMarshaller marsh, ClusterGroupImpl prj, bool keepPortable)
            : base(target, marsh)
        {
            _prj = prj;

            _keepPortable.Value = keepPortable;
        }
示例#8
0
        public void TestCachingWasDisabledByPassingRightType()
        {
            var target           = GetTarget();
            var clusterGroupImpl = new ClusterGroupImpl(target.Object, null);
            var sut = new ComputeImpl(target.Object, clusterGroupImpl, true);

            sut.WithNoResultCache();

            target.Verify(x => x.InLongOutLong(OpWithNoResultCacheType, It.IsAny <long>()), Times.Once());
        }
示例#9
0
        /// <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);
        }
示例#10
0
        /// <summary>
        /// Execute job serializing result to the stream.
        /// </summary>
        /// <param name="cancel">Whether the job must be cancelled.</param>
        /// <param name="stream">Stream.</param>
        public void ExecuteRemote(PlatformMemoryStream stream, bool cancel)
        {
            // 1. Execute job.
            object res;
            bool   success;

            Execute0(cancel, out res, out success);

            // 2. Try writing result to the stream.
            ClusterGroupImpl prj = _ignite.ClusterGroup;

            PortableWriterImpl writer = prj.Marshaller.StartMarshal(stream);

            try
            {
                // 3. Marshal results.
                PortableUtils.WriteWrappedInvocationResult(writer, success, res);
            }
            finally
            {
                // 4. Process metadata.
                prj.FinishMarshal(writer);
            }
        }
示例#11
0
        public void Map(PlatformMemoryStream stream)
        {
            IList <IClusterNode> subgrid;

            ClusterGroupImpl prj = (ClusterGroupImpl)_compute.ClusterGroup;

            var ignite = (Ignite)prj.Ignite;

            // 1. Unmarshal topology info if topology changed.
            var reader = prj.Marshaller.StartUnmarshal(stream);

            if (reader.ReadBoolean())
            {
                long topVer = reader.ReadLong();

                List <IClusterNode> nodes = new List <IClusterNode>(reader.ReadInt());

                int nodesCnt = reader.ReadInt();

                subgrid = new List <IClusterNode>(nodesCnt);

                for (int i = 0; i < nodesCnt; i++)
                {
                    IClusterNode node = ignite.GetNode(reader.ReadGuid());

                    nodes.Add(node);

                    if (reader.ReadBoolean())
                    {
                        subgrid.Add(node);
                    }
                }

                // Update parent projection to help other task callers avoid this overhead.
                // Note that there is a chance that topology changed even further and this update fails.
                // It means that some of subgrid nodes could have left the Grid. This is not critical
                // for us, because Java will handle it gracefully.
                prj.UpdateTopology(topVer, nodes);
            }
            else
            {
                IList <IClusterNode> nodes = prj.NodesNoRefresh();

                Debug.Assert(nodes != null, "At least one topology update should have occurred.");

                subgrid = IgniteUtils.Shuffle(nodes);
            }

            // 2. Perform map.
            IDictionary <IComputeJob <T>, IClusterNode> map;
            Exception err;

            try
            {
                map = _task.Map(subgrid, _arg);

                err = null;
            }
            catch (Exception e)
            {
                map = null;

                err = e;

                // Java can receive another exception in case of marshalling failure but it is not important.
                Finish(default(TR), e);
            }

            // 3. Write map result to the output stream.
            stream.Reset();
            BinaryWriter writer = prj.Marshaller.StartMarshal(stream);

            try
            {
                if (err == null)
                {
                    writer.WriteBoolean(true); // Success flag.

                    if (map == null)
                    {
                        writer.WriteBoolean(false); // Map produced no result.
                    }
                    else
                    {
                        writer.WriteBoolean(true); // Map produced result.

                        _jobHandles = WriteJobs(writer, map);
                    }
                }
                else
                {
                    writer.WriteBoolean(false); // Map failed.

                    // Write error as string because it is not important for Java, we need only to print
                    // a message in the log.
                    writer.WriteString("Map step failed [errType=" + err.GetType().Name +
                                       ", errMsg=" + err.Message + ']');
                }
            }
            catch (Exception e)
            {
                // Something went wrong during marshaling.
                Finish(default(TR), e);

                stream.Reset();

                writer.WriteBoolean(false);    // Map failed.
                writer.WriteString(e.Message); // Write error message.
            }
            finally
            {
                prj.Marshaller.FinishMarshal(writer);
            }
        }