Beispiel #1
0
 /// <summary>
 /// Internal routine for closure-based task execution.
 /// </summary>
 /// <param name="task">Task.</param>
 /// <param name="job">Job.</param>
 /// <param name="jobs">Jobs.</param>
 /// <param name="broadcast">Broadcast flag.</param>
 /// <returns>Future.</returns>
 private Future <TReduceRes> ExecuteClosures0 <TArg, TJobRes, TReduceRes>(
     IComputeTask <TArg, TJobRes, TReduceRes> task, IComputeJob job,
     ICollection <IComputeJob> jobs, bool broadcast)
 {
     return(ExecuteClosures0(task, job, jobs, broadcast ? OpBroadcast : OpUnicast,
                             jobs == null ? 1 : jobs.Count));
 }
Beispiel #2
0
        /// <summary>
        /// Default ctor for marshalling.
        /// </summary>
        /// <param name="reader"></param>
        public ComputeJobHolder(BinaryReader reader)
        {
            Debug.Assert(reader != null);

            _ignite = reader.Marshaller.Ignite;

            _job = reader.ReadObject <IComputeJob>();
        }
Beispiel #3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="grid">Grid.</param>
        /// <param name="job">Job.</param>
        public ComputeJobHolder(Ignite grid, IComputeJob job)
        {
            Debug.Assert(grid != null);
            Debug.Assert(job != null);

            _ignite = grid;
            _job = job;
        }
Beispiel #4
0
        /// <summary>
        /// Default ctor for marshalling.
        /// </summary>
        /// <param name="reader"></param>
        public ComputeJobHolder(BinaryReader reader)
        {
            Debug.Assert(reader != null);

            _ignite = reader.Marshaller.Ignite;

            _job = reader.ReadObject<IComputeJob>();
        }
Beispiel #5
0
        /// <summary>
        /// Default ctor for marshalling.
        /// </summary>
        /// <param name="reader"></param>
        public ComputeJobHolder(IPortableReader reader)
        {
            var reader0 = (PortableReaderImpl) reader.RawReader();

            _ignite = reader0.Marshaller.Ignite;

            _job = PortableUtils.ReadPortableOrSerializable<IComputeJob>(reader0);
        }
Beispiel #6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="grid">Grid.</param>
        /// <param name="job">Job.</param>
        public ComputeJobHolder(IIgniteInternal grid, IComputeJob job)
        {
            Debug.Assert(grid != null);
            Debug.Assert(job != null);

            _ignite = grid;
            _job    = job;
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="data">Data.</param>
 /// <param name="err">Exception.</param>
 /// <param name="job">Backing job.</param>
 /// <param name="nodeId">Node ID.</param>
 /// <param name="cancelled">Cancel flag.</param>
 public ComputeJobResultImpl(object data, Exception err, IComputeJob job, Guid nodeId, bool cancelled)
 {
     _data      = data;
     _err       = err;
     _job       = job;
     _nodeId    = nodeId;
     _cancelled = cancelled;
 }
        /// <summary>
        /// Default ctor for marshalling.
        /// </summary>
        /// <param name="reader"></param>
        public ComputeJobHolder(IPortableReader reader)
        {
            Debug.Assert(reader != null);

            var reader0 = (PortableReaderImpl)reader.RawReader();

            _ignite = reader0.Marshaller.Ignite;

            _job = PortableUtils.ReadPortableOrSerializable <IComputeJob>(reader0);
        }
        /// <summary>
        /// Default ctor for marshalling.
        /// </summary>
        /// <param name="reader"></param>
        public ComputeJobHolder(IBinaryReader reader)
        {
            Debug.Assert(reader != null);

            var reader0 = (BinaryReader) reader.GetRawReader();

            _ignite = reader0.Marshaller.Ignite;

            _job = reader0.ReadObject<IComputeJob>();
        }
Beispiel #10
0
        /// <summary>
        /// Default ctor for marshalling.
        /// </summary>
        /// <param name="reader"></param>
        public ComputeJobHolder(IBinaryReader reader)
        {
            Debug.Assert(reader != null);

            var reader0 = (BinaryReader)reader.GetRawReader();

            _ignite = reader0.Marshaller.Ignite;

            _job = reader0.ReadObject <IComputeJob>();
        }
Beispiel #11
0
        /// <summary>
        /// Writes the job.
        /// </summary>
        /// <param name="job">The job.</param>
        /// <param name="writer">The writer.</param>
        /// <returns>Handle to the job holder</returns>
        private long WriteJob(IComputeJob job, PortableWriterImpl writer)
        {
            var jobHolder = new ComputeJobHolder((Ignite)_prj.Ignite, job);

            var jobHandle = Marshaller.Ignite.HandleRegistry.Allocate(jobHolder);

            writer.WriteLong(jobHandle);
            writer.WriteObject(jobHolder);

            return(jobHandle);
        }
Beispiel #12
0
        /// <summary>
        /// Writes the job.
        /// </summary>
        /// <param name="job">The job.</param>
        /// <param name="writer">The writer.</param>
        /// <returns>Handle to the job holder</returns>
        private long WriteJob(IComputeJob job, BinaryWriter writer)
        {
            var jobHolder = new ComputeJobHolder((Ignite)_prj.Ignite, job);

            var jobHandle = Marshaller.Ignite.HandleRegistry.Allocate(jobHolder);

            writer.WriteLong(jobHandle);

            try
            {
                writer.WriteObjectDetached(jobHolder);
            }
            catch (Exception)
            {
                Marshaller.Ignite.HandleRegistry.Release(jobHandle);

                throw;
            }

            return(jobHandle);
        }
Beispiel #13
0
 /// <summary>
 /// Internal routine for closure-based task execution.
 /// </summary>
 /// <param name="task">Task.</param>
 /// <param name="job">Job.</param>
 /// <param name="jobs">Jobs.</param>
 /// <param name="broadcast">Broadcast flag.</param>
 /// <returns>Future.</returns>
 private IFuture <TR> ExecuteClosures0 <TA, T, TR>(IComputeTask <TA, T, TR> task, IComputeJob job,
                                                   ICollection <IComputeJob> jobs, bool broadcast)
 {
     return(ExecuteClosures0(task, job, jobs, broadcast ? OpBroadcast : OpUnicast,
                             jobs == null ? 1 : jobs.Count));
 }
Beispiel #14
0
        private Future <TReduceRes> ExecuteClosures0 <TArg, TJobRes, TReduceRes>(
            IComputeTask <TArg, TJobRes, TReduceRes> task, IComputeJob job = null,
            IEnumerable <IComputeJob> jobs    = null, int opId = OpUnicast, int jobsCount = 0,
            Action <BinaryWriter> writeAction = null)
        {
            Debug.Assert(job != null || jobs != null);

            var holder = new ComputeTaskHolder <TArg, TJobRes, TReduceRes>((Ignite)_prj.Ignite, this, task, default(TArg));

            var taskHandle = Marshaller.Ignite.HandleRegistry.Allocate(holder);

            var jobHandles = new List <long>(job != null ? 1 : jobsCount);

            try
            {
                Exception err = null;

                try
                {
                    var futTarget = DoOutOpObject(opId, writer =>
                    {
                        writer.WriteLong(taskHandle);

                        if (job != null)
                        {
                            writer.WriteInt(1);

                            jobHandles.Add(WriteJob(job, writer));
                        }
                        else
                        {
                            writer.WriteInt(jobsCount);

                            Debug.Assert(jobs != null, "jobs != null");

                            jobHandles.AddRange(jobs.Select(jobEntry => WriteJob(jobEntry, writer)));
                        }

                        holder.JobHandles(jobHandles);

                        if (writeAction != null)
                        {
                            writeAction(writer);
                        }
                    });

                    holder.Future.SetTarget(new Listenable(futTarget));
                }
                catch (Exception e)
                {
                    err = e;
                }

                if (err != null)
                {
                    // Manual job handles release because they were not assigned to the task yet.
                    foreach (var hnd in jobHandles)
                    {
                        Marshaller.Ignite.HandleRegistry.Release(hnd);
                    }

                    holder.CompleteWithError(taskHandle, err);
                }
            }
            catch (Exception e)
            {
                // This exception means that out-op failed.
                holder.CompleteWithError(taskHandle, e);
            }

            return(holder.Future);
        }
Beispiel #15
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="grid">Grid.</param>
 /// <param name="job">Job.</param>
 public ComputeJobHolder(Ignite grid, IComputeJob job)
 {
     _ignite = grid;
     _job = job;
 }
Beispiel #16
0
        /// <summary>
        /// Unwraps job of one type into job of another type.
        /// </summary>
        public static object Unwrap(this IComputeJob <object> job)
        {
            var wrapper = job as ComputeJobWrapper;

            return(wrapper != null ? wrapper.Job : job);
        }
Beispiel #17
0
        /// <summary>
        /// Unwraps job of one type into job of another type.
        /// </summary>
        public static IComputeJob <TR> Unwrap <T, TR>(this IComputeJob <T> job)
        {
            var wrapper = job as ComputeJobWrapper;

            return(wrapper != null ? (IComputeJob <TR>)wrapper.Job : (IComputeJob <TR>)job);
        }
Beispiel #18
0
 /// <summary>
 /// Convert to non-generic wrapper.
 /// </summary>
 public static IComputeJob ToNonGeneric <T>(this IComputeJob <T> job)
 {
     return(new ComputeJobWrapper(job, x => job.Execute(), x => job.Cancel()));
 }