KSquare Utilities
KKJobManagment::KKJob Class Reference

#include <KKJob.h>

+ Inheritance diagram for KKJobManagment::KKJob:

Public Types

typedef map< KKStr, ConstructorPtrConstructorIndex
 
typedef KKJobPtr(* ConstructorPtr) (JobManagerPtr _manager)
 
enum  JobStatus {
  jsNULL, jsOpen, jsStarted, jsDone,
  jsExpanded
}
 
enum  JobTypes { jtNULL, jtBinaryCombo, jtMultiClass, jtRandomSplit }
 
typedef KKJobKKJobPtr
 

Public Member Functions

 KKJob (const KKJob &j)
 
 KKJob (JobManagerPtr _manager, kkint32 _jobId, kkint32 _parentId, kkint32 _numPorcessesAllowed, RunLog &_log)
 
 KKJob (JobManagerPtr _manager)
 
 ~KKJob ()
 
void AddPrerequisites (kkint32 _prerequisite)
 
void AddPrerequisites (VectorInt _prerequisites)
 
virtual void CompletedJobDataRead (istream &i)
 Works with 'WriteCompletedJobData'; You use this to load in data written by 'WriteCompletedJobData'. More...
 
virtual void CompletedJobDataWrite (ostream &o)
 Write out completed job results to status file. More...
 
virtual KKJobPtr Duplicate () const
 
bool InPrerequisites (kkint32 _jobId)
 
kkint32 JobId () const
 
void JobId (kkint32 _jobId)
 
virtual const char * JobType () const
 
RunLog & Log ()
 
JobManagerPtr Manager () const
 
kkint32 ParentId () const
 
const VectorInt & Prerequisites () const
 
virtual void ProcessNode ()
 
virtual void ProcessStatusField (const KKStr &fieldName, const KKStr &fieldValue)
 Imjpelmentation specific field processing. More...
 
virtual void ReFresh (KKJob &j)
 
JobStatus Status () const
 
void Status (JobStatus _status)
 
KKStr StatusStr () const
 
virtual KKStr ToStatusStr ()
 

Static Public Member Functions

static KKJobPtr CallAppropriateConstructor (JobManagerPtr _manager, const KKStr &_jobTypeName, const KKStr &_statusStr)
 
static JobStatus JobStatusFromStr (const KKStr &statusStr)
 
static KKStr JobStatusToStr (JobStatus status)
 
static void JobTypeFromStr (const KKStr &s)
 
static KKStr JobTypeToStr (JobTypes jt)
 
static void RegisterConstructor (const KKStr &_name, ConstructorPtr _constructor)
 

Public Attributes

RunLog & log
 

Static Public Attributes

static ConstructorIndex registeredConstructors
 

Protected Member Functions

void PrerequisitesFromStr (const KKStr &s)
 
KKStr PrerequisitesToStr () const
 
void ProcessStatusStr (const KKStr &statusStr)
 

Protected Attributes

kkint32 jobId
 
JobManagerPtr manager
 
kkint32 numPorcessesAllowed
 
kkint32 numProcessors
 
kkint32 parentId
 
VectorInt prerequisites
 
JobStatus status
 

Detailed Description

Definition at line 68 of file KKJob.h.

Member Typedef Documentation

Definition at line 98 of file KKJob.h.

typedef KKJobPtr(* KKJobManagment::KKJob::ConstructorPtr) (JobManagerPtr _manager)

Definition at line 96 of file KKJob.h.

Definition at line 75 of file KKJob.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

KKJob::KKJob ( const KKJob j)

Definition at line 42 of file KKJob.cpp.

References jobId, log, manager, numPorcessesAllowed, numProcessors, parentId, prerequisites, and status.

Referenced by Duplicate(), and KKJobManagment::KKJobManager::KKJobManager().

42  :
43 
44  log (j.log),
45  manager (j.manager),
46  jobId (j.jobId),
47  parentId (j.parentId),
51  status (j.status)
52 
53 {
54 }
JobManagerPtr manager
Definition: KKJob.h:211
kkint32 numPorcessesAllowed
Definition: KKJob.h:216
JobStatus status
Definition: KKJob.h:224
kkint32 parentId
Definition: KKJob.h:210
VectorInt prerequisites
Definition: KKJob.h:220
kkint32 numProcessors
Definition: KKJob.h:212
KKJobManagment::KKJob::KKJob ( JobManagerPtr  _manager,
kkint32  _jobId,
kkint32  _parentId,
kkint32  _numPorcessesAllowed,
RunLog &  _log 
)
KKJob::KKJob ( JobManagerPtr  _manager)

Definition at line 82 of file KKJob.cpp.

References jobId, jsNULL, Log(), log, manager, numPorcessesAllowed, numProcessors, parentId, prerequisites, and status.

82  :
83  manager (_manager),
84  jobId (-1),
85  parentId (-1),
86  numProcessors (0),
88  prerequisites (),
89  status (jsNULL),
90  log (_manager->Log ())
91 {
92 }
JobManagerPtr manager
Definition: KKJob.h:211
kkint32 numPorcessesAllowed
Definition: KKJob.h:216
JobStatus status
Definition: KKJob.h:224
kkint32 parentId
Definition: KKJob.h:210
VectorInt prerequisites
Definition: KKJob.h:220
kkint32 numProcessors
Definition: KKJob.h:212
RunLog & Log()
Definition: KKJob.h:122
KKJob::~KKJob ( )

Definition at line 97 of file KKJob.cpp.

98 {
99 }

Member Function Documentation

void KKJobManagment::KKJob::AddPrerequisites ( kkint32  _prerequisite)
KKJobPtr KKJob::CallAppropriateConstructor ( JobManagerPtr  _manager,
const KKStr _jobTypeName,
const KKStr _statusStr 
)
static

Definition at line 145 of file KKJob.cpp.

References ProcessStatusStr().

Referenced by KKJobManagment::KKJobManager::StatusFileProcessLine().

149 {
150  ConstructorIndex::iterator idx;
151  idx = registeredConstructors.find (_jobTypeName);
152  if (idx == registeredConstructors.end ())
153  return NULL;
154  KKJobPtr j = idx->second (_manager);
155  j->ProcessStatusStr (_statusStr);
156  return j;
157 } /* CallAppropriateConstructor */
void ProcessStatusStr(const KKStr &statusStr)
Definition: KKJob.cpp:278
static ConstructorIndex registeredConstructors
Definition: KKJob.h:100
void KKJob::CompletedJobDataRead ( istream &  i)
virtual

Works with 'WriteCompletedJobData'; You use this to load in data written by 'WriteCompletedJobData'.

@

Definition at line 351 of file KKJob.cpp.

352 {
353 }
void KKJob::CompletedJobDataWrite ( ostream &  o)
virtual

Write out completed job results to status file.

This method will get called right after the "KKJob" status line gets written when a KKJob is completed. See 'KKJobManager::GetNextSetOfJobs'. If a job needs to write more data to the Status file then you want to put on a single status line this is where you would do it. You write all the text in a format that you want to support. 'KKJobManager' will bracket it with <KKJob jobtype="KKJob::JobType," jobid="####"> and </KKJob>

ex:
<RandomSplitJob>
KKJob Data;
KKJob Data,
etc. etc. etc.
</RandomSplitJob>

Definition at line 344 of file KKJob.cpp.

345 {
346 }
KKJobPtr KKJob::Duplicate ( ) const
virtual

Create a duplicate instance.

Reimplemented in KKJobManagment::KKJobManager.

Definition at line 112 of file KKJob.cpp.

References AddPrerequisites(), and KKJob().

Referenced by KKJobManagment::KKJobManager::Run().

113 {
114  return new KKJob (*this);
115 }
KKJob(const KKJob &j)
Definition: KKJob.cpp:42
bool KKJobManagment::KKJob::InPrerequisites ( kkint32  _jobId)
kkint32 KKJobManagment::KKJob::JobId ( ) const
inline

Definition at line 118 of file KKJob.h.

References jobId.

Referenced by KKJobManagment::KKJobManager::StatusFileProcessLine().

118 {return jobId;}
void KKJobManagment::KKJob::JobId ( kkint32  _jobId)
inline

Definition at line 126 of file KKJob.h.

References jobId.

126 {jobId = _jobId;}
KKJob::JobStatus KKJob::JobStatusFromStr ( const KKStr statusStr)
static

Definition at line 198 of file KKJob.cpp.

References KKB::KKStr::CompareIgnoreCase(), jsDone, jsExpanded, jsNULL, jsOpen, and jsStarted.

Referenced by KKJobManagment::KKJobManager::StatusFileProcessLine(), and KKJobManagment::KKJobManager::StatusFileProcessLineJobStatusChange().

199 {
200  if (statusStr.CompareIgnoreCase ("OPEN") == 0)
201  return jsOpen;
202 
203  if (statusStr.CompareIgnoreCase ("STARTED") == 0)
204  return jsStarted;
205 
206  if (statusStr.CompareIgnoreCase ("DONE") == 0)
207  return jsDone;
208 
209  if (statusStr.CompareIgnoreCase ("Expanded") == 0)
210  return jsExpanded;
211 
212  return jsNULL;
213 } /* JobStatusToStr */
kkint32 CompareIgnoreCase(const KKStr &s2) const
Compares with another KKStr, ignoring case.
Definition: KKStr.cpp:919
KKStr KKJob::JobStatusToStr ( JobStatus  status)
static

Definition at line 178 of file KKJob.cpp.

References jsDone, jsExpanded, jsOpen, and jsStarted.

Referenced by StatusStr(), and KKJobManagment::KKJobManager::ToStatusStr().

179 {
180  if (status == jsOpen)
181  return "Open";
182 
183  if (status == jsStarted)
184  return "Started";
185 
186  if (status == jsDone)
187  return "Done";
188 
189  if (status == jsExpanded)
190  return "Expanded";
191 
192  return "";
193 } /* JobStatusToStr */
JobStatus status
Definition: KKJob.h:224
const char * KKJob::JobType ( ) const
virtual

This will allow us to know which specific implementaion of 'KKJob' an instance really is.

Reimplemented in KKJobManagment::KKJobManager.

Definition at line 104 of file KKJob.cpp.

105 {
106  return "KKJob";
107 }
static void KKJobManagment::KKJob::JobTypeFromStr ( const KKStr &  s)
static
static KKStr KKJobManagment::KKJob::JobTypeToStr ( JobTypes  jt)
static
RunLog& KKJobManagment::KKJob::Log ( )
inline

Definition at line 122 of file KKJob.h.

References log.

Referenced by KKJob(), and KKJobManagment::KKJobList::KKJobList().

122 {return log;}
JobManagerPtr KKJobManagment::KKJob::Manager ( ) const
inline

Definition at line 120 of file KKJob.h.

References manager.

120 {return manager;}
JobManagerPtr manager
Definition: KKJob.h:211
kkint32 KKJobManagment::KKJob::ParentId ( ) const
inline

Definition at line 119 of file KKJob.h.

References parentId.

119 {return parentId;}
kkint32 parentId
Definition: KKJob.h:210
const VectorInt& KKJobManagment::KKJob::Prerequisites ( ) const
inline

Definition at line 121 of file KKJob.h.

References prerequisites.

Referenced by KKJobManagment::KKJobList::AllPrequisitesDone().

121 {return prerequisites;}
VectorInt prerequisites
Definition: KKJob.h:220
void KKJob::PrerequisitesFromStr ( const KKStr s)
protected

Definition at line 243 of file KKJob.cpp.

References KKB::KKStr::CompareIgnoreCase(), and KKB::KKStr::Split().

244 {
245  prerequisites.clear ();
246 
247  if (s.CompareIgnoreCase ("None") != 0)
248  {
249  VectorKKStr fields = s.Split (',');
250  for (kkuint32 x = 0; x < fields.size (); ++x)
251  {
252  kkint32 p = fields[x].ToInt ();
253  prerequisites.push_back (p);
254  }
255  }
256 } /* PrerequisitesFromStr */
VectorKKStr Split(const char *delStr="\n\r\t, ") const
Breaks up the contents of the string into tokens where the characters in &#39;delStr&#39; acts as separates e...
Definition: KKStr.cpp:3480
kkint32 CompareIgnoreCase(const KKStr &s2) const
Compares with another KKStr, ignoring case.
Definition: KKStr.cpp:919
__int32 kkint32
Definition: KKBaseTypes.h:88
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
VectorInt prerequisites
Definition: KKJob.h:220
KKStr KKJob::PrerequisitesToStr ( ) const
protected

Definition at line 225 of file KKJob.cpp.

References KKB::KKStr::Concat().

Referenced by ToStatusStr().

226 {
227  if (prerequisites.size () < 1)
228  return "None";
229 
230  KKStr s (5 + prerequisites.size () * 5);
231  for (kkuint32 x = 0; x < prerequisites.size (); ++x)
232  {
233  if (x > 0)
234  s << ",";
235  s << prerequisites[x];
236  }
237  return s;
238 } /* PrerequisitesToStr */
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
VectorInt prerequisites
Definition: KKJob.h:220
void KKJob::ProcessNode ( )
virtual

Definition at line 119 of file KKJob.cpp.

References KKB::KKException::KKException().

Referenced by KKJobManagment::KKJobManager::Run().

120 {
121  // This metjod should have been overridden by a derived class; if we end up here then
122  // no actual work will get done.
123  throw KKException ("KKJob::ProcessNode ***ERROR*** ProcessNode was not defined bydecendent class.");
124 }
void KKJob::ProcessStatusField ( const KKStr fieldName,
const KKStr fieldValue 
)
virtual

Imjpelmentation specific field processing.

Any SubClass of KKJob needs to define this method. Whenever the 'ProcessStatusStr' method can not identify a field it will call this method to let the child Class process the field.

Definition at line 334 of file KKJob.cpp.

337 {
338  log.Level (-1) << "KKJob::ProcessStatusField Invalid Field Name[" << fieldName << "]." << endl;
339 } /* ProcessStatusField */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
void KKJob::ProcessStatusStr ( const KKStr statusStr)
protected

Definition at line 278 of file KKJob.cpp.

References KKB::KKStr::Concat(), and KKB::KKStr::Split().

Referenced by CallAppropriateConstructor().

279 {
280  log.Level (30) << "KKJob::ProcessStatusStr[" << statusStr << "]" << endl;
281  KKStr fieldName;
282  KKStr fieldValue;
283 
284  VectorKKStr fields = statusStr.Split ('\t');
285  kkuint32 fieldNum = 0;
286 
287  while (fieldNum < fields.size ())
288  {
289  fieldName = fields[fieldNum];
290  fieldNum++;
291  if (fieldNum < fields.size ())
292  {
293  fieldValue = fields[fieldNum];
294  fieldNum++;
295  }
296  else
297  {
298  fieldValue = "";
299  }
300 
301  fieldName.Upper ();
302  fieldValue.TrimLeft ("\n\r\t ");
303  fieldValue.TrimRight ("\n\r\t ");
304 
305  if (fieldName.CompareIgnoreCase ("JOBID") == 0)
306  jobId = atoi (fieldValue.Str ());
307 
308  else if (fieldName.CompareIgnoreCase ("PARENTID") == 0)
309  parentId = atoi (fieldValue.Str ());
310 
311  else if (fieldName.CompareIgnoreCase ("STATUS") == 0)
312  status = JobStatusFromStr (fieldValue);
313 
314  else if (fieldName.CompareIgnoreCase ("NumProcessors") == 0)
315  numProcessors = fieldValue.ToInt ();
316 
317  else if (fieldName.CompareIgnoreCase ("NumPorcessesAllowed") == 0)
318  numPorcessesAllowed = fieldValue.ToInt ();
319 
320  else if (fieldName.CompareIgnoreCase ("Prerequisites") == 0)
321  PrerequisitesFromStr (fieldValue);
322 
323  else
324  {
325  ProcessStatusField (fieldName, fieldValue);
326  }
327  }
328 } /* ProcessStatusStr */
HTMLReport &__cdecl endl(HTMLReport &htmlReport)
Definition: HTMLReport.cpp:240
VectorKKStr Split(const char *delStr="\n\r\t, ") const
Breaks up the contents of the string into tokens where the characters in &#39;delStr&#39; acts as separates e...
Definition: KKStr.cpp:3480
kkint32 numPorcessesAllowed
Definition: KKJob.h:216
kkint32 CompareIgnoreCase(const KKStr &s2) const
Compares with another KKStr, ignoring case.
Definition: KKStr.cpp:919
KKStr & TrimRight(const char *whiteSpaceChars="\n\r\t ")
Definition: KKStr.cpp:1695
void PrerequisitesFromStr(const KKStr &s)
Definition: KKJob.cpp:243
kkint32 ToInt() const
Definition: KKStr.cpp:3565
static JobStatus JobStatusFromStr(const KKStr &statusStr)
Definition: KKJob.cpp:198
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
RunLog & Level(kkint32 _level)
Definition: RunLog.cpp:220
JobStatus status
Definition: KKJob.h:224
virtual void ProcessStatusField(const KKStr &fieldName, const KKStr &fieldValue)
Imjpelmentation specific field processing.
Definition: KKJob.cpp:334
void TrimLeft(const char *whiteSpaceChars="\n\r\t ")
Definition: KKStr.cpp:1745
kkint32 parentId
Definition: KKJob.h:210
void Upper()
Converts all characters in string to their Upper case equivalents via &#39;toupper&#39;.
Definition: KKStr.cpp:2461
const char * Str() const
Returns a pointer to a ascii string.
Definition: KKStr.h:422
kkint32 numProcessors
Definition: KKJob.h:212
void KKJob::ReFresh ( KKJob j)
virtual

Definition at line 163 of file KKJob.cpp.

References jobId, manager, numPorcessesAllowed, numProcessors, parentId, prerequisites, and status.

Referenced by KKJobManagment::KKJobManager::StatusFileProcessLine().

164 {
165  jobId = j.jobId;
166  parentId = j.parentId;
167  manager = j.manager;
168  status = j.status;
169 
173  status = j.status;
174 } /* ReFresh */
JobManagerPtr manager
Definition: KKJob.h:211
kkint32 numPorcessesAllowed
Definition: KKJob.h:216
JobStatus status
Definition: KKJob.h:224
kkint32 parentId
Definition: KKJob.h:210
VectorInt prerequisites
Definition: KKJob.h:220
kkint32 numProcessors
Definition: KKJob.h:212
void KKJob::RegisterConstructor ( const KKStr _name,
ConstructorPtr  _constructor 
)
static

Definition at line 135 of file KKJob.cpp.

138 {
139  registeredConstructors.insert (pair<KKStr, ConstructorPtr>(_name, _constructor));
140 }
static ConstructorIndex registeredConstructors
Definition: KKJob.h:100
void KKJobManagment::KKJob::Status ( JobStatus  _status)
inline

Definition at line 127 of file KKJob.h.

References status.

Referenced by KKJobManagment::KKJobManager::StatusFileProcessLineJobStatusChange().

127 {status = _status;}
JobStatus status
Definition: KKJob.h:224
KKStr KKJob::StatusStr ( ) const

Definition at line 218 of file KKJob.cpp.

References JobStatusToStr(), and status.

Referenced by ToStatusStr().

219 {
220  return JobStatusToStr (status);
221 } /* StatusStr */
static KKStr JobStatusToStr(JobStatus status)
Definition: KKJob.cpp:178
JobStatus status
Definition: KKJob.h:224
KKStr KKJob::ToStatusStr ( )
virtual

Any derived classes that implement this method must call its base class version 1st.

Reimplemented in KKJobManagment::KKJobManager.

Definition at line 261 of file KKJob.cpp.

References KKB::KKStr::Concat(), jobId, KKB::KKStr::KKStr(), numPorcessesAllowed, numProcessors, parentId, PrerequisitesToStr(), and StatusStr().

Referenced by KKJobManagment::KKJobManager::ToStatusStr().

262 {
263  KKStr statusStr (200); // Preallocating 200 bytes.
264 
265  statusStr << "JobId" << "\t" << jobId << "\t"
266  << "ParentId" << "\t" << parentId << "\t"
267  << "Status" << "\t" << StatusStr () << "\t"
268  << "NumProcessors" << "\t" << numProcessors << "\t"
269  << "NumPorcessesAllowed" << "\t" << numPorcessesAllowed << "\t"
270  << "Prerequisites" << "\t" << PrerequisitesToStr ();
271 
272  return statusStr;
273 } /* ToStatusStr */
kkint32 numPorcessesAllowed
Definition: KKJob.h:216
KKStr StatusStr() const
Definition: KKJob.cpp:218
kkint32 parentId
Definition: KKJob.h:210
KKStr PrerequisitesToStr() const
Definition: KKJob.cpp:225
kkint32 numProcessors
Definition: KKJob.h:212

Member Data Documentation

kkint32 KKJobManagment::KKJob::jobId
protected

Definition at line 209 of file KKJob.h.

Referenced by JobId(), KKJob(), ReFresh(), and ToStatusStr().

RunLog& KKJobManagment::KKJob::log

Definition at line 200 of file KKJob.h.

Referenced by KKJob(), and Log().

JobManagerPtr KKJobManagment::KKJob::manager
protected

Definition at line 211 of file KKJob.h.

Referenced by KKJob(), Manager(), and ReFresh().

kkint32 KKJobManagment::KKJob::numPorcessesAllowed
protected

The number of Processes that are allowd to process at same time. that is ('numPorcessesAllowed' <= 'numActiveProcessors').

Definition at line 216 of file KKJob.h.

Referenced by KKJob(), ReFresh(), and ToStatusStr().

kkint32 KKJobManagment::KKJob::numProcessors
protected

Number of CPU's that are currently processing this node; That is the number that are currently calling the 'ProcessNode' method.

Definition at line 212 of file KKJob.h.

Referenced by KKJob(), ReFresh(), and ToStatusStr().

kkint32 KKJobManagment::KKJob::parentId
protected

Definition at line 210 of file KKJob.h.

Referenced by KKJob(), ParentId(), ReFresh(), and ToStatusStr().

VectorInt KKJobManagment::KKJob::prerequisites
protected

List of JobId's that must complete (jobStatus == jsDone) before this process may be started.

Definition at line 220 of file KKJob.h.

Referenced by KKJob(), Prerequisites(), and ReFresh().

map< KKStr, KKJob::ConstructorPtr > KKJob::registeredConstructors
static

Track all the different constructors. Will be used to know wich constructor to use when reading the status file.

Definition at line 100 of file KKJob.h.


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