IGLib 1.4
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. | |
void | NotifyJobFinished () |
Notifies all interested objects that the job has finished. | |
void | NotifyJobAborted () |
Notifies all interested parties that job has been aborted. | |
void | NotifyServerIdle (ParallelJobDispatcherBase< JobContainerType > dispatcher) |
Sets the Idle flag to true and notifies the containing dispatcher that the current server object has became idle. | |
void | StopServerThread () |
Sends to the server thread command that it has to stop. | |
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 | |
void | StartServer () |
void | StartJobByServer () |
Starts job by the server. | |
void | StartSingleJob () |
Starts a single job in a new therad taht is created for this purpose. | |
void | RunJobSynchronous (JobContainerType jobData) |
void | StartJob (JobContainerType jobData) |
Starts the current job in the way specified by internal flags. | |
override string | ToString () |
Returns a string representation of the current job server, which contains relevent data about the server state. | |
Protected Member Functions | |
void | NotifyServerAboutJob () |
void | Serve () |
abstract void | RunJobDefined (JobContainerType jobData) |
Runs the job. | |
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). | |
void | RunJobInThread () |
Methods that runs the job on the serving thread, for the case when server thread executes multiple jobs (server mode). | |
Static Protected Member Functions | |
static int | GetNextId () |
Returns another ID that is unique for objects of the containing class its and derived classes. | |
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. | |
static int | DefaultOutputLevel [get, set] |
Default output level for objects of this and derived types. Just aliases the ParallelJobContainerBase.DefaultOutputLevel. | |
int | OutputLevel [get, set] |
Output level the current object. Specifies how much output is printed to console during operation. | |
static bool | DefaultIsTestMode [get, set] |
Default value of test mode flag. Just aliases the ParallelJobContainerBase.DefaultOutputLevel. | |
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. | |
int | Id [get] |
Unique ID for objects of the currnet and derived classes. | |
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. | |
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. DefaultSleepTimeMs specifies the default value that is set when object is created. | |
ParallelJobDispatcherBase < JobContainerType > | Dispatcher [get, set] |
ParallelServerState | State [get, set] |
Gets the state of the current job runner. | |
bool | IsIdle [get] |
Gets a flag indicating whether the current job runner is idle. | |
bool | IsActive [get] |
JobContainerType | JobData [get, set] |
Data for the job that is executed by teh current parallel job runner. | |
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> If false then a new thread is started each time a job is run, and is deleted when a job finishes. | |
bool | CommandStopServing [get, 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 | ThreadPriority [get, set] |
Priority of the server thread. Setting priority changes priority of the server thread if it exists. | |
bool | IsServerRunning [get] |
Indicates whether the server is currently running or not. | |
bool | DoRunJobByServer [get, set] |
Private Attributes | |
object | _mainLock = new object() |
volatile int | _outputLevel = ParallelJobContainerBase.DefaultOutputLevel |
Output level for objects of this class. Specifies how much output is printed to console during operation. | |
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 |
IG::Num::ParallelJobServerBase< JobContainerType >::ParallelJobServerBase | ( | ) | [inline] |
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.
void IG::Num::ParallelJobServerBase< JobContainerType >::NotifyJobStarted | ( | ) | [inline] |
Notifies all interested objects that the job has started.
void IG::Num::ParallelJobServerBase< JobContainerType >::NotifyJobFinished | ( | ) | [inline] |
Notifies all interested objects that the job has finished.
void IG::Num::ParallelJobServerBase< JobContainerType >::NotifyJobAborted | ( | ) | [inline] |
Notifies all interested parties that job has been aborted.
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.
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
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.
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.
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.
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] |
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.
Implements IG::Lib::ILockable.
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.
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.
Implements IG::Lib::IIdentifiable.
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.
ParallelJobDispatcherBase<JobContainerType> IG::Num::ParallelJobServerBase< JobContainerType >::Dispatcher [get, set] |
ParallelServerState IG::Num::ParallelJobServerBase< JobContainerType >::State [get, 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.
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.
bool IG::Num::ParallelJobServerBase< JobContainerType >::CommandStopServing [get, 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, set] |