| IGLib 1.5 The IGLib base library for development of numerical, technical and business applications.

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Properties | Private Attributes | Static Private Attributes | List of all members
IG.Num.ParallelJobServerBase< JobContainerType > Class Template Referenceabstract

Parallel job server. Waits for job requests and executes them in a parallel thread. More...

Inheritance diagram for IG.Num.ParallelJobServerBase< JobContainerType >:
[legend]
Collaboration diagram for IG.Num.ParallelJobServerBase< JobContainerType >:
[legend]

## Public Member Functions
| ParallelJobServerBase ()
void | NotifyJobStarted ()
| Notifies all interested objects that the job has started. More...
void | NotifyJobFinished ()
| Notifies all interested objects that the job has finished. More...
void | NotifyJobAborted ()
| Notifies all interested parties that job has been aborted. More...
void | NotifyServerIdle (ParallelJobDispatcherBase< JobContainerType > dispatcher)
| Sets the Idle flag to true and notifies the containing dispatcher that the current server object has became idle. More...
void | StopServerThread ()
| Sends to the server thread command that it has to stop. More...
void | KillServerThread ()
| Forces the working to stop, even if it is in the middle of eecution of a job, by aborting the thread. To let the working thread finish its current jobs and then stop, call StopServerThread More...
void | StartServer ()
void | StartJobByServer ()
| Starts job by the server. More...
void | StartSingleJob ()
| Starts a single job in a new therad taht is created for this purpose. More...
void | RunJobSynchronous (JobContainerType jobData)
void | StartJob (JobContainerType jobData)
| Starts the current job in the way specified by internal flags. More...
override string | ToString ()
| Returns a string representation of the current job server, which contains relevent data about the server state. More...

## Protected Member Functions
void | NotifyServerAboutJob ()
void | Serve ()
abstract void | RunJobDefined (JobContainerType jobData)
| Runs the job. More...
void | RunSingleJobInThread ()
| Methods that runs the job on the serving thread, for the case when a new thread is allocated for each job (single job per thread). More...
void | RunJobInThread ()
| Methods that runs the job on the serving thread, for the case when server thread executes multiple jobs (server mode). More...

## Static Protected Member Functions
static int | GetNextId ()
| Returns another ID that is unique for objects of the containing class its and derived classes. More...

## Protected Attributes
volatile bool | _isTestMode = ParallelJobContainerBase.DefaultIsTestMode
int | _sleepTimeMs = DefaultSleepTimeMs
ParallelJobDispatcherBase < JobContainerType > | _dispatcher
ParallelServerState | _state = ParallelServerState.Idle
JobContainerType | _jobData
bool | _isServer = false
bool | _commandStopServing = false
ThreadPriority | _threadPriority = UtilSystem.ThreadPriority
Thread | _workingThread
bool | _isServerRunning = false

## Properties
object | Lock`[get]`
| This object's central lock object to be used by other object. Do not use this object for locking in class' methods, for this you should use InternalLock. More...
static int | DefaultOutputLevel`[get, set]`
| Default output level for objects of this and derived types. More...
int | OutputLevel`[get, set]`
| Output level the current object. More...
static bool | DefaultIsTestMode`[get, set]`
| Default value of test mode flag. More...
bool | IsTestMode`[get, set]`
| Whether the current job data conntainer is in test mode. In this mode, delays specified by internal variables are automatically added in job execution. More...
int | Id`[get]`
| Unique ID for objects of the currnet and derived classes. More...
static int | DefaultSleepTimeMs`[get, set]`
| Default sleeping time, in milliseconds, used by parallel job data objects when waiting for fulfillment of some condition in a loop that includes sleeping when condition is not met. More...
int | SleepTimeMs`[get, set]`
| Sleeping time, in milliseconds, used by the current object when waiting for fulfillment of some condition in a loop that includes sleeping when condition is not met. More...
ParallelJobDispatcherBase < JobContainerType > | Dispatcher`[get, set]`
ParallelServerState | State`[get, protected set]`
| Gets the state of the current job runner. More...
bool | IsIdle`[get]`
| Gets a flag indicating whether the current job runner is idle. More...
bool | IsActive`[get]`
JobContainerType | JobData`[get, set]`
| Data for the job that is executed by teh current parallel job runner. More...
bool | IsServer`[get, set]`
| Indicating whether the current job runner work as server. <par>If true then a server is started in a parallel thread that continuously for signals to start jobs.</par> More...
bool | CommandStopServing`[get, protected set]`
| Flag indicating whether the server should be stopped. If set to true and server thread is runing, then the server thread stops when the currently run job completes (or stops immediately if there is no job running). More...
ThreadPriority | ThreadPriority`[get, set]`
| Priority of the server thread. More...
bool | IsServerRunning`[get]`
| Indicates whether the server is currently running or not. More...
bool | DoRunJobByServer`[get, protected set]`
Properties inherited from IG.Lib.ILockable
object | Lock`[get]`
Properties inherited from IG.Lib.IIdentifiable
int | Id`[get]`
| Returns unique ID (in the scope of a given type) of the current object. More...

## Private Attributes
object | _mainLock = new object()
volatile int | _outputLevel = ParallelJobContainerBase.DefaultOutputLevel
| Output level for objects of this class. More...
int | _id = GetNextId()
bool | _doRunJobByServer = false

## Static Private Attributes
static int | _nextId = 0
static int | _defaultSleepTimeMs = 2

## Detailed Description

Parallel job server. Waits for job requests and executes them in a parallel thread.

Template Parameters

  JobContainerType | Type of the container that holds data for the job (input and output).

///

The server executes jobs on a separate thread that is spawned by the server and is used just for this purpose.

The server object can operate in two modes. In the server mode, a server threas is started that continuously waits for job requests and executes them as soon as they arrive. In single job state, a new thread is started for each job request and is terminated when the job is completed.

Job request is sent by the

$A Igor Aug08;

Type Constraints

  JobContainerType | : | ParallelJobContainerBase |

## Constructor & Destructor Documentation

IG.Num.ParallelJobServerBase< JobContainerType >.ParallelJobServerBase | ( |  | ) |
| inline

## Member Function Documentation

static int IG.Num.ParallelJobServerBase< JobContainerType >.GetNextId | ( |  | ) |
| inline static protected

Returns another ID that is unique for objects of the containing class its and derived classes.

References IG.Num.ParallelJobContainerBase.LockId.

void IG.Num.ParallelJobServerBase< JobContainerType >.NotifyJobStarted | ( |  | ) |
| inline

Notifies all interested objects that the job has started.

References IG.Num.ParallelJobDispatcherBase< JobContainerType >.NotifyJobStarted().

void IG.Num.ParallelJobServerBase< JobContainerType >.NotifyJobFinished | ( |  | ) |
| inline

Notifies all interested objects that the job has finished.

References IG.Num.ParallelJobDispatcherBase< JobContainerType >.NotifyJobFinished().

void IG.Num.ParallelJobServerBase< JobContainerType >.NotifyJobAborted | ( |  | ) |
| inline

Notifies all interested parties that job has been aborted.

References IG.Num.ParallelJobDispatcherBase< JobContainerType >.NotifyJobAborted().

void IG.Num.ParallelJobServerBase< JobContainerType >.NotifyServerIdle | ( | ParallelJobDispatcherBase< JobContainerType > | dispatcher | ) |
| inline

Sets the Idle flag to true and notifies the containing dispatcher that the current server object has became idle.

References IG.Num.ParallelJobDispatcherBase< JobContainerType >.NotifyServerIdle().

void IG.Num.ParallelJobServerBase< JobContainerType >.StopServerThread | ( |  | ) |
| inline

Sends to the server thread command that it has to stop.

void IG.Num.ParallelJobServerBase< JobContainerType >.KillServerThread | ( |  | ) |
| inline

Forces the working to stop, even if it is in the middle of eecution of a job, by aborting the thread. To let the working thread finish its current jobs and then stop, call StopServerThread

Referenced by IG.Num.ParallelJobDispatcherBase< JobContainerType >.KillServerThreads().

void IG.Num.ParallelJobServerBase< JobContainerType >.NotifyServerAboutJob | ( |  | ) |
| inline protected

void IG.Num.ParallelJobServerBase< JobContainerType >.Serve | ( |  | ) |
| inline protected

void IG.Num.ParallelJobServerBase< JobContainerType >.StartServer | ( |  | ) |
| inline

void IG.Num.ParallelJobServerBase< JobContainerType >.StartJobByServer | ( |  | ) |
| inline

Starts job by the server.

void IG.Num.ParallelJobServerBase< JobContainerType >.StartSingleJob | ( |  | ) |
| inline

Starts a single job in a new therad taht is created for this purpose.

abstract void IG.Num.ParallelJobServerBase< JobContainerType >.RunJobDefined | ( | JobContainerType | jobData | ) |
| protected pure virtual

Runs the job.

Parameters

  jobData | Data container for the job to be run.

Implemented in IG.Num.ParallelJobServerGen< InputType, ResultType, JobContainerType >.

void IG.Num.ParallelJobServerBase< JobContainerType >.RunSingleJobInThread | ( |  | ) |
| inline protected

Methods that runs the job on the serving thread, for the case when a new thread is allocated for each job (single job per thread).

void IG.Num.ParallelJobServerBase< JobContainerType >.RunJobInThread | ( |  | ) |
| inline protected

Methods that runs the job on the serving thread, for the case when server thread executes multiple jobs (server mode).

void IG.Num.ParallelJobServerBase< JobContainerType >.RunJobSynchronous | ( | JobContainerType | jobData | ) |
| inline

void IG.Num.ParallelJobServerBase< JobContainerType >.StartJob | ( | JobContainerType | jobData | ) |
| inline

Starts the current job in the way specified by internal flags.

If the IsServer flag is true then job is started by notifying the continuously running server thread to run the job. Server thread is created and started if necessary. If the flag is false then a new thread is started to run the job and the thread exits when the job is run.

Referenced by IG.Num.ParallelJobDispatcherBase< JobContainerType >.Serve().

override string IG.Num.ParallelJobServerBase< JobContainerType >.ToString | ( |  | ) |
| inline

Returns a string representation of the current job server, which contains relevent data about the server state.

Referenced by IG.Num.ParallelJobDispatcherBase< JobContainerType >.ToString().

## Member Data Documentation

object IG.Num.ParallelJobServerBase< JobContainerType >._mainLock = new object()
| private

volatile int IG.Num.ParallelJobServerBase< JobContainerType >._outputLevel = ParallelJobContainerBase.DefaultOutputLevel
| private

Output level for objects of this class.

Specifies how much output is printed to console during operation.

volatile bool IG.Num.ParallelJobServerBase< JobContainerType >._isTestMode = ParallelJobContainerBase.DefaultIsTestMode
| protected

int IG.Num.ParallelJobServerBase< JobContainerType >._nextId = 0
| static private

int IG.Num.ParallelJobServerBase< JobContainerType >._id = GetNextId()
| private

int IG.Num.ParallelJobServerBase< JobContainerType >._defaultSleepTimeMs = 2
| static private

int IG.Num.ParallelJobServerBase< JobContainerType >._sleepTimeMs = DefaultSleepTimeMs
| protected

ParallelJobDispatcherBase<JobContainerType> IG.Num.ParallelJobServerBase< JobContainerType >._dispatcher
| protected

ParallelServerState IG.Num.ParallelJobServerBase< JobContainerType >._state = ParallelServerState.Idle
| protected

JobContainerType IG.Num.ParallelJobServerBase< JobContainerType >._jobData
| protected

bool IG.Num.ParallelJobServerBase< JobContainerType >._isServer = false
| protected

bool IG.Num.ParallelJobServerBase< JobContainerType >._commandStopServing = false
| protected

ThreadPriority IG.Num.ParallelJobServerBase< JobContainerType >._threadPriority = UtilSystem.ThreadPriority
| protected

Thread IG.Num.ParallelJobServerBase< JobContainerType >._workingThread
| protected

bool IG.Num.ParallelJobServerBase< JobContainerType >._isServerRunning = false
| protected

bool IG.Num.ParallelJobServerBase< JobContainerType >._doRunJobByServer = false
| private

## Property Documentation

object IG.Num.ParallelJobServerBase< JobContainerType >.Lock
| get

This object's central lock object to be used by other object. Do not use this object for locking in class' methods, for this you should use InternalLock.

Referenced by IG.Num.ParallelJobDispatcherBase< JobContainerType >.RemoveServer().

int IG.Num.ParallelJobServerBase< JobContainerType >.DefaultOutputLevel
| static get set

Default output level for objects of this and derived types.

Just aliases the ParallelJobContainerBase.DefaultOutputLevel.

int IG.Num.ParallelJobServerBase< JobContainerType >.OutputLevel
| get set

Output level the current object.

Specifies how much output is printed to console during operation.

Referenced by IG.Num.ParallelJobDispatcherBase< JobContainerType >.SetServersOutputLevel().

bool IG.Num.ParallelJobServerBase< JobContainerType >.DefaultIsTestMode
| static get set

Default value of test mode flag.

Just aliases the ParallelJobContainerBase.DefaultOutputLevel.

bool IG.Num.ParallelJobServerBase< JobContainerType >.IsTestMode
| get set

Whether the current job data conntainer is in test mode. In this mode, delays specified by internal variables are automatically added in job execution.

int IG.Num.ParallelJobServerBase< JobContainerType >.Id
| get

Unique ID for objects of the currnet and derived classes.

Referenced by IG.Num.ParallelJobDispatcherBase< JobContainerType >.AddServer(), IG.Num.ParallelJobDispatcherBase< JobContainerType >.GetFirstIdleServer(), IG.Num.ParallelJobDispatcherBase< JobContainerType >.NotifyServerIdle(), IG.Num.ParallelJobDispatcherBase< JobContainerType >.RemoveServer(), IG.Num.ParallelJobDispatcherBase< JobContainerType >.Serve(), and IG.Num.ParallelJobDispatcherBase< JobContainerType >.ToString().

int IG.Num.ParallelJobServerBase< JobContainerType >.DefaultSleepTimeMs
| static get set

Default sleeping time, in milliseconds, used by parallel job data objects when waiting for fulfillment of some condition in a loop that includes sleeping when condition is not met.

int IG.Num.ParallelJobServerBase< JobContainerType >.SleepTimeMs
| get set

Sleeping time, in milliseconds, used by the current object when waiting for fulfillment of some condition in a loop that includes sleeping when condition is not met.

DefaultSleepTimeMs specifies the default value that is set when object is created.

Referenced by IG.Num.ParallelJobContainerGen< InputType, ResultType >.CreateServer(), and IG.Num.ParallelJobDispatcherBase< JobContainerType >.SetServersSleepTimeMs().

ParallelJobDispatcherBase<JobContainerType> IG.Num.ParallelJobServerBase< JobContainerType >.Dispatcher
| get set

Referenced by IG.Num.ParallelJobDispatcherBase< JobContainerType >.AddServer(), and IG.Num.ParallelJobDispatcherBase< JobContainerType >.RemoveServer().

ParallelServerState IG.Num.ParallelJobServerBase< JobContainerType >.State
| get protected set

Gets the state of the current job runner.

bool IG.Num.ParallelJobServerBase< JobContainerType >.IsIdle
| get

Gets a flag indicating whether the current job runner is idle.

Referenced by IG.Num.ParallelJobDispatcherBase< JobContainerType >.AddServer(), and IG.Num.ParallelJobDispatcherBase< JobContainerType >.GetFirstIdleServer().

bool IG.Num.ParallelJobServerBase< JobContainerType >.IsActive
| get

JobContainerType IG.Num.ParallelJobServerBase< JobContainerType >.JobData
| get set private

Data for the job that is executed by teh current parallel job runner.

bool IG.Num.ParallelJobServerBase< JobContainerType >.IsServer
| get set

Indicating whether the current job runner work as server. <par>If true then a server is started in a parallel thread that continuously for signals to start jobs.</par>

If false then a new thread is started each time a job is run, and is deleted when a job finishes.

Referenced by IG.Num.ParallelJobDispatcherBase< JobContainerType >.SetServersIsServer().

bool IG.Num.ParallelJobServerBase< JobContainerType >.CommandStopServing
| get protected set

Flag indicating whether the server should be stopped. If set to true and server thread is runing, then the server thread stops when the currently run job completes (or stops immediately if there is no job running).

ThreadPriority IG.Num.ParallelJobServerBase< JobContainerType >.ThreadPriority
| get set

Priority of the server thread.

Setting priority changes priority of the server thread if it exists.

bool IG.Num.ParallelJobServerBase< JobContainerType >.IsServerRunning
| get

Indicates whether the server is currently running or not.

bool IG.Num.ParallelJobServerBase< JobContainerType >.DoRunJobByServer
| get protected set

The documentation for this class was generated from the following file:

- igbase/numeric/parallel/ParallelJobServerBase.cs