Esempio n. 1
0
		private void bgtest(Job j)
		{
			int words = 0;
			byte[] outdata = new byte[1024];
			
			byte completediterations = 0; 
			byte totaliterations = 60;
			
			WorkStatus ws; 
			
			while(completediterations < totaliterations)
			{
				completediterations++;

				ws = new WorkStatus(j.jobhandle, completediterations, totaliterations); 
							
				j.sendWorkUpdate(ws);
			
				Thread.Sleep(500);
			}
			
			words = 10;
			outdata = BitConverter.GetBytes(words);
			Console.WriteLine("Found {0} words", words);
			j.sendResults(outdata);
			
			//return outdata;
		}
Esempio n. 2
0
		private void infinite(Job j)
		{
			// Loop forever
			while(true){
				Thread.Sleep(1000);
			}
		}
Esempio n. 3
0
		private void randomlengthjob(Job j)
		{
			Random r = new Random(); 
			int sleeptime = r.Next(1, 15);
			byte[] result = new byte[1];
			result[0] = 1;
			Log.DebugFormat("Sleeping for {0} seconds", sleeptime);
			Thread.Sleep(sleeptime * 1000);
			j.sendResults(result);
		}
Esempio n. 4
0
		private static void randomlengthjob(Job j)
		{
			Random r = new Random(); 
			int sleeptime = r.Next(1, 15);
			byte[] result = j.data;
		
			LoadTest.Log.DebugFormat("Sleeping for {0} seconds", sleeptime);
			Thread.Sleep(sleeptime * 1000);
			// Give back the same thing...
			j.sendResults(result);
		}
Esempio n. 5
0
		private static void wctest(Job j)
		{
			byte[] outdata = new byte[1024];
			byte[] indata = j.data;
			Console.WriteLine("wc called");
			
			int words = 0; 
			
			for(int i = 0; i < indata.Length; i++) 
			{
				if (indata[i] == 10)
					words++;
			}
			
			outdata = BitConverter.GetBytes(words);
			Console.WriteLine("Found {0} words", words);
			j.sendResults(outdata);
		}
Esempio n. 6
0
		/// <summary>
		/// Checks with the manager for a new job to work on. The manager has a record of all the tasks that the
		/// worker is capable of working on, so most of the real work here is done by the manager to find something
		/// for the worker to work on. If something is assigned, load the data, execute the callback and then return 
		/// the data to the manager so that the worker can move on to something else.
		/// </summary>
		private void checkForJob()
		{
			ASCIIEncoding encoder = new ASCIIEncoding(); 
			// Grab job from server (if available)
			Log.DebugFormat("Checking for job...");
			
			c.sendPacket(new GrabJob());
			
			Packet response = c.getNextPacket();
			
			if (response.Type == PacketType.JOB_ASSIGN)
			{
				Job job = new Job((JobAssign)response, this);
				
				Log.DebugFormat("Assigned job: {0}", job.jobhandle);
				Log.DebugFormat("Payload length: {0}", job.data.Length);
				Log.DebugFormat("Task: {0}", job.taskname);
				
				// Fire event for listeners
				methodMap[job.taskname](job);
						
			} else if (response.Type == PacketType.NO_JOB) {
				Log.DebugFormat("Nothing to do!");
			} 
		}