Example #1
0
        public bool setState(string state)
        {
            if (state == STATE_IDLE)
            {
                workerRoleInstance.State = STATE_IDLE;
            }
            else if (state == STATE_LOADING)
            {
                workerRoleInstance.State = STATE_LOADING;
            }
            else if (state == STATE_CRAWLING)
            {
                workerRoleInstance.State = STATE_CRAWLING;
            }
            else
            {
                return(false);
            }
            TableOperation updateOperation = TableOperation.Replace(workerRoleInstance);

            workerRoleTable.Execute(updateOperation);

            // refresh references to components
            statsManager = new StatsManager();
            webLoader    = new WebLoader();
            webCrawler   = new WebCrawler(statsManager);
            return(true);
        }
Example #2
0
        public WorkerStateMachine(string workerID)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                ConfigurationManager.AppSettings["StorageConnectionString"]
                );
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            workerRoleTable = tableClient.GetTableReference(WorkerRoleEntity.TABLE_WORKER_ROLES);

            TableOperation retrieveOperation = TableOperation.Retrieve <WorkerRoleEntity>(WorkerRoleEntity.TABLE_WORKER_ROLES, workerID);
            TableResult    retrievedResult   = workerRoleTable.Execute(retrieveOperation);

            if (retrievedResult.Result == null)
            {
                workerRoleInstance = new WorkerRoleEntity(workerID, STATE_IDLE);
                TableOperation insertOperation = TableOperation.Insert(workerRoleInstance);
                workerRoleTable.Execute(insertOperation);
            }
            else
            {
                workerRoleInstance = (WorkerRoleEntity)retrievedResult.Result;
                this.setState(workerRoleInstance.State);
            }
            statsManager = new StatsManager();
            webLoader    = new WebLoader();
            webCrawler   = new WebCrawler(statsManager);
        }