IGLib
1.5
The IGLib base library for development of numerical, technical and business applications.
|
Parallel job server. Waits for job requests and executes them in a parallel thread. More...
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] |
![]() | |
object | Lock [get] |
![]() | |
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 |
Parallel job server. Waits for job requests and executes them in a parallel thread.
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;
JobContainerType | : | ParallelJobContainerBase |
|
inline |
|
inlinestaticprotected |
Returns another ID that is unique for objects of the containing class its and derived classes.
References IG.Num.ParallelJobContainerBase.LockId.
|
inline |
Notifies all interested objects that the job has started.
References IG.Num.ParallelJobDispatcherBase< JobContainerType >.NotifyJobStarted().
|
inline |
Notifies all interested objects that the job has finished.
References IG.Num.ParallelJobDispatcherBase< JobContainerType >.NotifyJobFinished().
|
inline |
Notifies all interested parties that job has been aborted.
References IG.Num.ParallelJobDispatcherBase< JobContainerType >.NotifyJobAborted().
|
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().
|
inline |
Sends to the server thread command that it has to stop.
|
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().
|
inlineprotected |
|
inlineprotected |
|
inline |
|
inline |
Starts job by the server.
|
inline |
Starts a single job in a new therad taht is created for this purpose.
|
protectedpure virtual |
Runs the job.
jobData | Data container for the job to be run. |
Implemented in IG.Num.ParallelJobServerGen< InputType, ResultType, JobContainerType >.
|
inlineprotected |
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).
|
inlineprotected |
Methods that runs the job on the serving thread, for the case when server thread executes multiple jobs (server mode).
|
inline |
|
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().
|
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().
|
private |
|
private |
Output level for objects of this class.
Specifies how much output is printed to console during operation.
|
protected |
|
staticprivate |
|
private |
|
staticprivate |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
private |
|
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().
|
staticgetset |
Default output level for objects of this and derived types.
Just aliases the ParallelJobContainerBase.DefaultOutputLevel.
|
getset |
Output level the current object.
Specifies how much output is printed to console during operation.
Referenced by IG.Num.ParallelJobDispatcherBase< JobContainerType >.SetServersOutputLevel().
|
staticgetset |
Default value of test mode flag.
Just aliases the ParallelJobContainerBase.DefaultOutputLevel.
|
getset |
Whether the current job data conntainer is in test mode. In this mode, delays specified by internal variables are automatically added in job execution.
|
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().
|
staticgetset |
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.
|
getset |
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().
|
getset |
|
getprotected set |
Gets the state of the current job runner.
|
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().
|
get |
|
getsetprivate |
Data for the job that is executed by teh current parallel job runner.
|
getset |
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().
|
getprotected 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).
|
getset |
Priority of the server thread.
Setting priority changes priority of the server thread if it exists.
|
get |
Indicates whether the server is currently running or not.
|
getprotected set |