C# Class Gearman.Worker

Show file Open project: johnewart/gearman.net Class Usage Examples

Public Methods

Method Description
Worker ( ) : System

Default constructor, initialize empty method map of strings -> delegates

Worker ( string host ) : System

Constructor requiring only the host name; the default port of 4730 is used

Worker ( string host, int port ) : System

Constructor requiring both the host and the port number to connect to

registerFunction ( string taskname, taskdelegate function ) : void

Add a task <--> delegate mapping to this worker. A task name is a short string that the worker registers with the manager, for example "reverse". The delegate is a callback that the worker calls when it receives a packet of work to do that has a task name matching the registered name.

run ( ) : void

Obligatory run method for the Thread. Runs indefinitely, checking for a job every 2 seconds TODO: make this time adjustable if needed

stopWorkLoop ( ) : void

Terminate the work thread.

workLoop ( ) : void

Get this thing going.

Private Methods

Method Description
checkForJob ( ) : void

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.

Method Details

Worker() public method

Default constructor, initialize empty method map of strings -> delegates
public Worker ( ) : System
return System

Worker() public method

Constructor requiring only the host name; the default port of 4730 is used
public Worker ( string host ) : System
host string /// A representing the host to connect to ///
return System

Worker() public method

Constructor requiring both the host and the port number to connect to
public Worker ( string host, int port ) : System
host string /// A representing the host to connect to ///
port int /// A port to connect to (if other than the default of 4730) ///
return System

registerFunction() public method

Add a task <--> delegate mapping to this worker. A task name is a short string that the worker registers with the manager, for example "reverse". The delegate is a callback that the worker calls when it receives a packet of work to do that has a task name matching the registered name.
public registerFunction ( string taskname, taskdelegate function ) : void
taskname string /// A that is the 'name' of the task being registered with the server ///
function taskdelegate /// A that is the actual callback function /// (must match the specification) ///
return void

run() public method

Obligatory run method for the Thread. Runs indefinitely, checking for a job every 2 seconds TODO: make this time adjustable if needed
public run ( ) : void
return void

stopWorkLoop() public method

Terminate the work thread.
public stopWorkLoop ( ) : void
return void

workLoop() public method

Get this thing going.
public workLoop ( ) : void
return void