Beispiel #1
0
        /**
         * This method scedules the tasks given to the server queues in order to be processed
         * if there is no tasks so the method will wait until there is something to be processed
         * NOTE: This method never returns
         */
        public override void sceduleTasks()
        {
            int  serverTurn    = 0;
            bool getNewRequest = true;
            Url  request       = null;
            Url  request2      = null;

            while (true)
            {
                try
                {
                    int inserts = 0;
                    SyncAccessor.getSlot(ThreadsDim + 1, 0);
                    while (SyncAccessor.queueSize <Url>(_tasksQueue) != 0 && inserts < MAX_INSERTS_IN_TIME)
                    {
                        request2 = SyncAccessor.getFromQueue <Url>(_tasksQueue, _timer);
                        _rankingTrie.add(request2);
                        inserts++;
                    }

                    if (getNewRequest)
                    {
                        RuntimeStatistics.setFrontierUrls(_rankingTrie.count());
                        if (_rankingTrie.count() == 0)
                        {
                            Thread.Sleep(_timer);
                            continue;
                        }
                        request       = _rankingTrie.pop();
                        getNewRequest = false;
                    }

                    SyncAccessor.getSlot(2, 0);
                    if (SyncAccessor.queueSize <Url>(_serversQueues[serverTurn]) < _limit)
                    {
                        SyncAccessor.getSlot(2, 0);
                        SyncAccessor.putInQueue <Url>(_serversQueues[serverTurn], request);
                        getNewRequest = true;
                    }
                    else
                    {
                        getNewRequest = false;
                    }
                    serverTurn = (serverTurn + 1) % _serversQueues.Count;
                }
                catch (Exception e)
                {
                    RuntimeStatistics.addToErrors(1);
                }
            }
        }
Beispiel #2
0
        public void Test1()
        {
            testTrie.add(new Url("www.ynet.co.il", 0, 45, "www.ynet.co.il", 1));
            testTrie.add(new Url("www.ynet.co.il", 0, 50, "www.ynet.co.il", 1));
            testTrie.add(new Url("www.ynet.co.il", 0, 78, "www.ynet.co.il", 1));
            testTrie.add(new Url("", 0, 45, "www.ynet.co.il", 1));
            //testTrie.add(new Url(null, 0, 60, "www.ynet.co.il", 1));
            testTrie.add(new Url("www.facebook.com", 0, 45, "www.facebook.com", 1));
            testTrie.add(new Url("www.nana10.co.il", 0, 30, "www.ynet.co.il", 1));
            testTrie.add(new Url("www.ynet.co.il", 0, 78, "www.ynet.co.il", 1));
            testTrie.add(new Url("www.nana10.co.il", 0, 80, "www.nana10.co.il", 1));
            testTrie.add(new Url("www.nana10.co.il", 0, 80, "www.nana10.co.il", 1));
            testTrie.add(null);

            Console.WriteLine("The maximum rank is: " + testTrie.getMaxRank());
            Console.WriteLine("The minimum ramk is: " + testTrie.getMinRank());

            Console.WriteLine("The maximum url is : " + testTrie.pop().getUrl());

            Url pop = testTrie.pop();

            while (pop != null)
            {
                Console.WriteLine("The new max is : " + testTrie.getMaxRank());
                Console.WriteLine("The new min is : " + testTrie.getMinRank());
                Console.WriteLine("The new maximum url is :" + pop.getUrl());
                pop = testTrie.pop();
            }

            char c;

            for (int i = 0; i < 93; i++)
            {
                c = Convert.ToChar(i + 33);
                Console.WriteLine(c);
            }
        }