Пример #1
0
        /// <summary>
        /// Broadcasts given job to all nodes in grid projection. Every participating node will return a job result.
        /// </summary>
        /// <param name="clo">Job to broadcast to all projection nodes.</param>
        /// <returns>Collection of results for this execution.</returns>
        public IFuture <ICollection <TR> > Broadcast <TR>(IComputeFunc <TR> clo)
        {
            IgniteArgumentCheck.NotNull(clo, "clo");

            return(ExecuteClosures0(new ComputeMultiClosureTask <object, TR, ICollection <TR> >(1),
                                    new ComputeOutFuncJob(clo.ToNonGeneric()), null, true));
        }
Пример #2
0
        /// <summary>
        /// Broadcasts given closure job with passed in argument to all nodes in grid projection.
        /// Every participating node will return a job result.
        /// </summary>
        /// <param name="clo">Job to broadcast to all projection nodes.</param>
        /// <param name="arg">Job closure argument.</param>
        /// <returns>Collection of results for this execution.</returns>
        public Future <ICollection <TJobRes> > Broadcast <TArg, TJobRes>(IComputeFunc <TArg, TJobRes> clo, TArg arg)
        {
            IgniteArgumentCheck.NotNull(clo, "clo");

            return(ExecuteClosures0(new ComputeMultiClosureTask <object, TJobRes, ICollection <TJobRes> >(1),
                                    new ComputeFuncJob(clo.ToNonGeneric(), arg), null, true));
        }
Пример #3
0
        /// <summary>
        /// Executes provided closure job on a node in this grid projection.
        /// </summary>
        /// <param name="clo">Job to run.</param>
        /// <param name="arg">Job argument.</param>
        /// <returns>Job result for this execution.</returns>
        public Future <TJobRes> Apply <TArg, TJobRes>(IComputeFunc <TArg, TJobRes> clo, TArg arg)
        {
            IgniteArgumentCheck.NotNull(clo, "clo");

            return(ExecuteClosures0(new ComputeSingleClosureTask <TArg, TJobRes, TJobRes>(),
                                    new ComputeFuncJob(clo.ToNonGeneric(), arg), null, false));
        }
Пример #4
0
 public ConfigSection(string key, string value, bool isStringHeader, IComputeFunc computeFuncs, IEnumerationFunc enumerationFuncs)
 {
     ComputeFuncs     = computeFuncs;
     EnumerationFuncs = enumerationFuncs;
     Key      = key;
     Value    = value;
     RawValue = value;
     if (isStringHeader)
     {
         ReplaceVariables     = new List <ConfigReplaceSet>();
         ComputeVariables     = new List <ConfigComputeSet>();
         EnumerationVariables = new List <ConfigEnumerationSet>();
         foreach (var item in RetrieveAllVariables('@'))
         {
             ReplaceVariables.Add(new ConfigReplaceSet(item.key, item.token));
         }
         foreach (var item in RetrieveAllVariables('$'))
         {
             ComputeVariables.Add(new ConfigComputeSet(item.key, item.token, RetrieveFunc(item.key.TrimStart('$'))));
         }
         foreach (var item in RetrieveAllVariables('&'))
         {
             EnumerationVariables.Add(new ConfigEnumerationSet(item.key, item.token, GetEnumeration(item.key.TrimStart('&'))));
         }
         ReplaceAllVariables();
         IsString = isStringHeader;
     }
     else
     {
         bool.Parse(value);
         IsString = isStringHeader;
     }
 }
Пример #5
0
        /// <summary>
        /// Executes provided job on a node in this grid projection. The result of the
        /// job execution is returned from the result closure.
        /// </summary>
        /// <param name="clo">Job to execute.</param>
        /// <returns>Job result for this execution.</returns>
        public Future <TJobRes> Execute <TJobRes>(IComputeFunc <TJobRes> clo)
        {
            IgniteArgumentCheck.NotNull(clo, "clo");

            return(ExecuteClosures0(new ComputeSingleClosureTask <object, TJobRes, TJobRes>(),
                                    new ComputeOutFuncJob(clo.ToNonGeneric()), null, false));
        }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComputeFuncJob"/> class.
 /// </summary>
 /// <param name="reader">The reader.</param>
 public ComputeFuncJob(IPortableReader reader)
 {
     var reader0 = (PortableReaderImpl) reader.RawReader();
     
     _clo = PortableUtils.ReadPortableOrSerializable<IComputeFunc>(reader0);
     _arg = PortableUtils.ReadPortableOrSerializable<object>(reader0);
 }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComputeFuncJob"/> class.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public ComputeFuncJob(IPortableReader reader)
        {
            var reader0 = (PortableReaderImpl)reader.RawReader();

            _clo = PortableUtils.ReadPortableOrSerializable <IComputeFunc>(reader0);
            _arg = PortableUtils.ReadPortableOrSerializable <object>(reader0);
        }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComputeFuncJob"/> class.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public ComputeFuncJob(IBinaryReader reader)
        {
            var reader0 = (BinaryReader) reader.GetRawReader();

            _clo = reader0.ReadObject<IComputeFunc>();
            _arg = reader0.ReadObject<object>();
        }
Пример #9
0
 public ConfigFileHandler(IComputeFunc computeFuncs, IEnumerationFunc enumerationFuncs, IFileSystem fileSystem, string fileName = "ConfigFile.ocff")
 {
     FileSystem       = fileSystem;
     ComputeFuncs     = computeFuncs;
     EnumerationFuncs = enumerationFuncs;
     ConfigData       = new ConfigData();
     FileName         = fileName;
 }
Пример #10
0
        /// <summary>
        /// Executes given job on the node where data for provided affinity key is located
        /// (a.k.a. affinity co-location).
        /// </summary>
        /// <param name="cacheName">Name of the cache to use for affinity co-location.</param>
        /// <param name="affinityKey">Affinity key.</param>
        /// <param name="clo">Job to execute.</param>
        /// <returns>Job result for this execution.</returns>
        /// <typeparam name="TR">Type of job result.</typeparam>
        public IFuture <TR> AffinityCall <TR>(string cacheName, object affinityKey, IComputeFunc <TR> clo)
        {
            IgniteArgumentCheck.NotNull(clo, "clo");

            return(ExecuteClosures0(new ComputeSingleClosureTask <object, TR, TR>(),
                                    new ComputeOutFuncJob(clo.ToNonGeneric()), opId: OpAffinity,
                                    writeAction: w => WriteAffinity(w, cacheName, affinityKey)));
        }
Пример #11
0
        public ConfigParsedData ComputeAndReplace(IArguments arguments, IComputeFunc computeFuncs, IEnumerationFunc enumerationFuncs)
        {
            var newConfigData = new ConfigParsedData();
            var dictionary    = new Dictionary <string, List <string> >();
            List <(string header, string value, List <IConfigSet> variables)> list = new List <(string, string, List <IConfigSet>)>();
            var allKeys = TurnListConfigSectionIntoDict();

            DataStore.Where(y => y.IsString).ToList().ForEach(x => { var keyValue = allKeys[x.Key]; list.Add((x.Key, keyValue, x.ReturnAllVariables())); });
            foreach (var item in list)
            {
                StringBuilder        stringBuilder     = new StringBuilder(item.value);
                List <StringBuilder> stringBuilderList = new List <StringBuilder>()
                {
                    stringBuilder
                };
                foreach (var innerItem in item.variables)
                {
                    if (innerItem is ConfigComputeSet)
                    {
                        var innerComputeItem = innerItem as ConfigComputeSet;
                        stringBuilderList = stringBuilderList.SelectMany(y => GetParameter(innerComputeItem.Name, arguments, dictionary).Select(x => new StringBuilder(y.ToString().Replace(innerComputeItem.Token, innerComputeItem.Compute(x))))).ToList();
                    }
                    else if (innerItem is ConfigEnumerationSet)
                    {
                        var innerEnumerationItem = innerItem as ConfigEnumerationSet;
                        var enumeration          = GetParameter(innerEnumerationItem.Name, arguments, dictionary).SelectMany(y => innerEnumerationItem.GetEnumerable(y));
                        stringBuilderList = stringBuilderList.SelectMany(y => enumeration.Select(x => new StringBuilder(y.ToString().Replace(innerEnumerationItem.Token, x)))).ToList();
                    }
                    else
                    {
                        stringBuilderList = stringBuilderList.SelectMany(y => GetParameter(innerItem.Name, arguments, dictionary).Select(x => new StringBuilder(y.ToString().Replace(innerItem.Token, x)))).ToList();
                    }
                }
                AddConfigSections(item, stringBuilderList);
                dictionary.Add(item.header, stringBuilderList.Select(x => x.ToString()).ToList());
            }
            newConfigData.AddRange(DataStore.Where(x => !x.IsString));
            return(newConfigData);

            void AddConfigSections((string header, string value, List <IConfigSet> variables) item, List <StringBuilder> listOfStringBuilders)
            {
                foreach (var itemForEach in listOfStringBuilders)
                {
                    var stringBuilderValue = itemForEach.ToString();
                    newConfigData.Add(new ConfigSection(item.header, stringBuilderValue, isStringHeader: true, computeFuncs: computeFuncs, enumerationFuncs: enumerationFuncs));
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Executes provided closure job on nodes within this grid projection. A new job is executed for
        /// every argument in the passed in collection. The number of actual job executions will be
        /// equal to size of the job arguments collection.
        /// </summary>
        /// <param name="clo">Job to run.</param>
        /// <param name="args">Job arguments.</param>
        /// <returns>Collection of job results.</returns>
        public IFuture <ICollection <TR> > Apply <T, TR>(IComputeFunc <T, TR> clo, IEnumerable <T> args)
        {
            IgniteArgumentCheck.NotNull(clo, "clo");

            IgniteArgumentCheck.NotNull(clo, "clo");

            var jobs = new List <IComputeJob>(GetCountOrZero(args));

            var func = clo.ToNonGeneric();

            foreach (T arg in args)
            {
                jobs.Add(new ComputeFuncJob(func, arg));
            }

            return(ExecuteClosures0(new ComputeMultiClosureTask <T, TR, ICollection <TR> >(jobs.Count),
                                    null, jobs, false));
        }
Пример #13
0
        /// <summary>
        /// Executes provided closure job on nodes within this grid projection. A new job is executed for
        /// every argument in the passed in collection. The number of actual job executions will be
        /// equal to size of the job arguments collection. The returned job results will be reduced
        /// into an individual result by provided reducer.
        /// </summary>
        /// <param name="clo">Job to run.</param>
        /// <param name="args">Job arguments.</param>
        /// <param name="rdc">Reducer to reduce all job results into one individual return value.</param>
        /// <returns>Reduced job result for this execution.</returns>
        public Future <TReduceRes> Apply <TArg, TJobRes, TReduceRes>(IComputeFunc <TArg, TJobRes> clo,
                                                                     IEnumerable <TArg> args, IComputeReducer <TJobRes, TReduceRes> rdc)
        {
            IgniteArgumentCheck.NotNull(clo, "clo");

            IgniteArgumentCheck.NotNull(clo, "clo");

            IgniteArgumentCheck.NotNull(clo, "clo");

            ICollection <IComputeJob> jobs = new List <IComputeJob>(GetCountOrZero(args));

            var func = clo.ToNonGeneric();

            foreach (TArg arg in args)
            {
                jobs.Add(new ComputeFuncJob(func, arg));
            }

            return(ExecuteClosures0(new ComputeReducingClosureTask <TArg, TJobRes, TReduceRes>(rdc),
                                    null, jobs, false));
        }
Пример #14
0
 /** <inheritDoc /> */
 public ICollection <TJobRes> Apply <TArg, TJobRes>(IComputeFunc <TArg, TJobRes> clo, IEnumerable <TArg> args)
 {
     return(_compute.Apply(clo, args).Get());
 }
Пример #15
0
 /** <inheritDoc /> */
 public Task <TRes> ApplyAsync <TArg, TRes>(IComputeFunc <TArg, TRes> clo, TArg arg)
 {
     return(_compute.Apply(clo, arg).Task);
 }
Пример #16
0
 /** <inheritDoc /> */
 public Task <TRes> ApplyAsync <TArg, TRes>(IComputeFunc <TArg, TRes> clo, TArg arg,
                                            CancellationToken cancellationToken)
 {
     return(GetTaskIfAlreadyCancelled <TRes>(cancellationToken) ??
            _compute.Apply(clo, arg).GetTask(cancellationToken));
 }
Пример #17
0
 /** <inheritDoc /> */
 public Task <ICollection <TRes> > BroadcastAsync <TArg, TRes>(IComputeFunc <TArg, TRes> clo, TArg arg,
                                                               CancellationToken cancellationToken)
 {
     return(GetTaskIfAlreadyCancelled <ICollection <TRes> >(cancellationToken) ??
            _compute.Broadcast(clo, arg).GetTask(cancellationToken));
 }
Пример #18
0
 /** <inheritDoc /> */
 public TJobRes Apply <TArg, TJobRes>(IComputeFunc <TArg, TJobRes> clo, TArg arg)
 {
     return(_compute.Apply(clo, arg).Get());
 }
Пример #19
0
 /** <inheritDoc /> */
 public ICollection <TJobRes> Broadcast <T, TJobRes>(IComputeFunc <T, TJobRes> clo, T arg)
 {
     return(_compute.Broadcast(clo, arg).Get());
 }
Пример #20
0
 /** <inheritDoc /> */
 public Task <ICollection <TRes> > BroadcastAsync <TArg, TRes>(IComputeFunc <TArg, TRes> clo, TArg arg)
 {
     return(_compute.Broadcast(clo, arg).Task);
 }
Пример #21
0
        /** <inheritDoc /> */
        public Task <TRes> AffinityCallAsync <TRes>(string cacheName, object affinityKey, IComputeFunc <TRes> clo)
        {
            IgniteArgumentCheck.NotNull(cacheName, "cacheName");

            return(_compute.AffinityCall(cacheName, affinityKey, clo).Task);
        }
Пример #22
0
        /** <inheritDoc /> */
        public Task <TRes> AffinityCallAsync <TRes>(string cacheName, object affinityKey, IComputeFunc <TRes> clo,
                                                    CancellationToken cancellationToken)
        {
            IgniteArgumentCheck.NotNull(cacheName, "cacheName");

            return(GetTaskIfAlreadyCancelled <TRes>(cancellationToken) ??
                   _compute.AffinityCall(cacheName, affinityKey, clo).GetTask(cancellationToken));
        }
Пример #23
0
        /** <inheritDoc /> */
        public TJobRes AffinityCall <TJobRes>(string cacheName, object affinityKey, IComputeFunc <TJobRes> clo)
        {
            IgniteArgumentCheck.NotNull(cacheName, "cacheName");

            return(_compute.AffinityCall(cacheName, affinityKey, clo).Get());
        }
Пример #24
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="clo">Closure.</param>
 /// <param name="arg">Argument.</param>
 public ComputeFuncJob(IComputeFunc clo, object arg)
 {
     _clo = clo;
     _arg = arg;
 }
Пример #25
0
 /** <inheritDoc /> */
 public Task <TRes> ApplyAsync <TArg, TFuncRes, TRes>(IComputeFunc <TArg, TFuncRes> clo, IEnumerable <TArg> args,
                                                      IComputeReducer <TFuncRes, TRes> rdc, CancellationToken cancellationToken)
 {
     return(GetTaskIfAlreadyCancelled <TRes>(cancellationToken) ??
            _compute.Apply(clo, args, rdc).GetTask(cancellationToken));
 }
Пример #26
0
 /** <inheritDoc /> */
 public TReduceRes Apply <TArg, TJobRes, TReduceRes>(IComputeFunc <TArg, TJobRes> clo,
                                                     IEnumerable <TArg> args, IComputeReducer <TJobRes, TReduceRes> rdc)
 {
     return(_compute.Apply(clo, args, rdc).Get());
 }
Пример #27
0
 /** <inheritDoc /> */
 public Task <ICollection <TRes> > ApplyAsync <TArg, TRes>(IComputeFunc <TArg, TRes> clo, IEnumerable <TArg> args)
 {
     return(_compute.Apply(clo, args).Task);
 }
Пример #28
0
 /** <inheritDoc /> */
 public Task <ICollection <TRes> > ApplyAsync <TArg, TRes>(IComputeFunc <TArg, TRes> clo, IEnumerable <TArg> args,
                                                           CancellationToken cancellationToken)
 {
     return(GetTaskIfAlreadyCancelled <ICollection <TRes> >(cancellationToken) ??
            _compute.Apply(clo, args).GetTask(cancellationToken));
 }
Пример #29
0
 /** <inheritDoc /> */
 public TJobRes Call <TJobRes>(IComputeFunc <TJobRes> clo)
 {
     return(_compute.Execute(clo).Get());
 }
Пример #30
0
 /** <inheritDoc /> */
 public Task <TRes> ApplyAsync <TArg, TFuncRes, TRes>(IComputeFunc <TArg, TFuncRes> clo, IEnumerable <TArg> args,
                                                      IComputeReducer <TFuncRes, TRes> rdc)
 {
     return(_compute.Apply(clo, args, rdc).Task);
 }
Пример #31
0
 /** <inheritDoc /> */
 public Task <TRes> CallAsync <TRes>(IComputeFunc <TRes> clo)
 {
     return(_compute.Execute(clo).Task);
 }
Пример #32
0
 /// <summary>
 /// Convert to non-generic wrapper.
 /// </summary>
 public static IComputeFunc ToNonGeneric <T, TR>(this IComputeFunc <T, TR> func)
 {
     return(new ComputeFuncWrapper(func, x => func.Invoke((T)x)));
 }
Пример #33
0
 /** <inheritDoc /> */
 public Task <TRes> CallAsync <TRes>(IComputeFunc <TRes> clo, CancellationToken cancellationToken)
 {
     return(GetTaskIfAlreadyCancelled <TRes>(cancellationToken) ??
            _compute.Execute(clo).GetTask(cancellationToken));
 }