コード例 #1
0
    /**
     * Reads a queue string into and builds a transformation queue from it.
     */

    public TransformationQueue Read(string _s, bool fromHash = false)
    {
        MatchCollection queueExist = TransformationQueue.queueExistParse.Matches(_s);

        if (queueExist.Count == 0)
        {
            throw new Exception("Cannot read queue string " + _s);
        }

        TransformationQueue tQueue   = new TransformationQueue();
        MatchCollection     jobExist = TransformationQueue.queueEntryParse.Matches(_s);

        if (jobExist.Count == 0)
        {
            Log.Out("No jobs found.");
            return(tQueue);
        }

        foreach (Match matchJob in jobExist)
        {
            Log.Out("Matched: " + matchJob.ToString());
            tQueue.Add(TransformationJob.Read(matchJob.ToString(), fromHash));
        }

        return(tQueue);
    }
コード例 #2
0
        private static IQueue <long> CreateQueue1(string dir)
        {
            DiskQueue <int>                 disk      = new DiskQueue <int>(dir, new NonPersistentDiskQueueSegmentFactory <int>(10000, "prefix", new ItemSerializer()), 100, true);
            MemoryQueue <int>               preDisk   = new MemoryQueue <int>(5000);
            LevelingQueue <int>             diskWrap  = new LevelingQueue <int>(preDisk, disk, LevelingQueueAddingMode.PreserveOrder, true);
            TransformationQueue <long, int> transform = new TransformationQueue <long, int>(diskWrap, new TypeConverter());
            MemoryQueue <long>              topMem    = new MemoryQueue <long>(1000);
            LevelingQueue <long>            topQ      = new LevelingQueue <long>(topMem, transform, LevelingQueueAddingMode.PreserveOrder, true);

            return(topQ);
        }
コード例 #3
0
    /**
     * Adds a TransformationData object to the queue. Returns true, if the items were added successfully.
     */

    public bool Add(TransformationData tData, out ulong transformTime, out TransformationJob job)
    {
        this.CreateQueueIfUndefined();
        job = null;

        transformTime = TransformationQueue.CalculateTransformationTimeAsWorldTime(tData);
        if (this.QueueAlreadyHas(tData))
        {
            return(false);
        }

        job = new TransformationJob(transformTime, tData);
        this.queue.Add(job);
        return(true);
    }
コード例 #4
0
        public void AddTakeSequentialTest()
        {
            const int ItemsCount = 50000;

            var memQueue  = new MemoryQueue <long>();
            var converter = new TypeConverter();

            using (var queue = new TransformationQueue <int, long>(memQueue, converter))
                using (var barrier = new Barrier(2))
                {
                    List <int> bag = new List <int>();

                    var task1 = Task.Run(() =>
                    {
                        barrier.SignalAndWait();
                        for (int val = 0; val < ItemsCount; val++)
                        {
                            if (val % 10 == 0)
                            {
                                queue.Add(val);
                            }
                            else if (val % 10 == 1)
                            {
                                Assert.IsTrue(queue.TryAdd(val));
                            }
                            else if (val % 10 == 2)
                            {
                                Assert.IsTrue(queue.TryAdd(val, 1000));
                            }
                            else if (val % 10 == 3)
                            {
                                Assert.IsTrue(queue.TryAdd(val, TimeSpan.FromSeconds(1)));
                            }
                            else if (val % 10 == 4)
                            {
                                Assert.IsTrue(queue.TryAdd(val, 1000, new CancellationToken()));
                            }
                            else if (val % 10 == 5)
                            {
                                queue.AddForced(val);
                            }
                            else
                            {
                                queue.Add(val, new CancellationToken());
                            }

                            SpinWaitHelper.SpinWait(val % 16);
                        }
                    });

                    var task2 = Task.Run(() =>
                    {
                        barrier.SignalAndWait();
                        for (int val = 0; val < ItemsCount; val++)
                        {
                            int res = 0;
                            if (val % 10 == 0)
                            {
                                Assert.IsTrue(queue.TryTake(out res, 10000), "Value was expected 1");
                            }
                            else if (val % 10 == 1)
                            {
                                Assert.IsTrue(queue.TryTake(out res, 10000, new CancellationToken()), "Value was expected 2");
                            }
                            else
                            {
                                Assert.IsTrue(queue.TryTake(out res, TimeSpan.FromSeconds(10)), "Value was expected 3");
                            }

                            bag.Add(res);
                            SpinWaitHelper.SpinWait((val + 5) % 16);
                        }
                    });

                    Task.WaitAll(task1, task2);

                    Assert.AreEqual(0, queue.Count);
                    Assert.AreEqual(ItemsCount, bag.Count);

                    for (int i = 0; i < bag.Count; i++)
                    {
                        Assert.AreEqual(i, bag[i], "i != bag[i]");
                    }

                    Assert.AreEqual(0, memQueue.Count);
                    Assert.AreEqual(ItemsCount, converter.ConvertNum);
                    Assert.AreEqual(ItemsCount, converter.ConvertBackNum);
                }
        }