예제 #1
0
        /// <summary>
        /// Tries to retrieve a service at the given url.
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="url"></param>
        /// <returns>The service if successful, null otherwise</returns>
        public Service GetService(Type serviceType, string url)
        {
            try {
                // TODO: be sure the url is correct and contains an explicit port
                Regex regex = RegexConstants.PATTERN_PORT;
                var   v     = regex.Match(url);
                int   port  = int.Parse(v.Groups[1].ToString());

                Service res = (Service)Activator.GetObject(serviceType, url + port);
                res.ProbeObject();
                return(res);
            } catch (Exception e) {
                logger.Log("Error retriving service: " + e.Message, false);
            }

            return(null);
        }
예제 #2
0
        public WorkerService(IWorker worker)
        {
            this.worker = worker;
            this.id     = worker.GetId();

            manager = new WorkersManager();
            manager.AddOverseenWorker(new OverseenWorker(this, null)); // Adds himself as an available worker

            logger = new LoggerWrapper("WS" + id);
            logger.Log("Created a new WorkerService");
        }
예제 #3
0
        public WorkerService(IWorker worker)
        {
            this.worker = worker;
            this.id = worker.GetId();

            manager = new WorkersManager();
            manager.AddOverseenWorker(new OverseenWorker(this, null)); // Adds himself as an available worker

            logger = new LoggerWrapper("WS" + id);
            logger.Log("Created a new WorkerService");
        }
예제 #4
0
        /// <summary>
        /// This function is called by the client application to
        /// the master worker/tracker so that the size of each
        /// split can be calculated and the list of jobs be
        /// prepared to give to the other workers.
        /// </summary>
        /// <param name="fileSize"></param>
        /// <param name="nSplits"></param>
        public void CalculateJobList(int fileSize, int nSplits)
        {
            logger.Log("Calculating job list on fileSize: " + fileSize + " with " + nSplits + " splits.");

            checkForFrozenCommunication();

            jobList = new List <split>();

            // Calculate partition size, i.e. number of lines per split
            double partitionSize = 0;

            if (fileSize >= nSplits)
            {
                partitionSize = (1.0 * fileSize) / nSplits;
                partitionSize = Math.Ceiling(partitionSize);
            }
            else                          // if number of splits is bigger than the number of lines...
            {
                partitionSize = 1;        // each worker will process just 1 line
                nSplits       = fileSize; // the number of splits will not exceed the number of lines
            }

            int splitId = 0;

            for (int i = 0; i < fileSize; i += (int)partitionSize)
            {
                split workerJob;
                int   lastLine = i + (int)partitionSize - 1;
                if (lastLine >= fileSize)   // final case when last element cant get as many lines
                {
                    lastLine = fileSize - 1;
                }
                workerJob = new split(splitId, i, lastLine);
                jobList.Add(workerJob);
                //logger.Log("Job " + splitId + " { " + workerJob.from + ", " + workerJob.to + " }");
                splitId++;
            }
        }