XRootD
XrdXrootdJob Class Reference

#include <XrdXrootdJob.hh>

+ Inheritance diagram for XrdXrootdJob:
+ Collaboration diagram for XrdXrootdJob:

Public Member Functions

 XrdXrootdJob (XrdScheduler *schp, XrdOucProg *pgm, const char *jname, int maxjobs=4)
 
 ~XrdXrootdJob ()
 
int Cancel (const char *jkey=0, XrdXrootdResponse *resp=0)
 
void DoIt ()
 
XrdOucTListList (void)
 
int Schedule (const char *jkey, const char **args, XrdXrootdResponse *resp, int Opts=0)
 
- Public Member Functions inherited from XrdJob
 XrdJob (const char *desc="")
 
virtual ~XrdJob ()
 

Friends

class XrdXrootdJob2Do
 

Additional Inherited Members

- Public Attributes inherited from XrdJob
const char * Comment
 
XrdJobNextJob
 

Detailed Description

Definition at line 51 of file XrdXrootdJob.hh.

Constructor & Destructor Documentation

◆ XrdXrootdJob()

XrdXrootdJob::XrdXrootdJob ( XrdScheduler schp,
XrdOucProg pgm,
const char *  jname,
int  maxjobs = 4 
)

Definition at line 454 of file XrdXrootdJob.cc.

458  : XrdJob("Job Scheduler"),
459  JobTable(maxjobs*3)
460 {
461 // Initialize the base member here
462 //
463  Sched = schp;
464  theProg = pgm;
465  JobName = strdup(jname);
466  maxJobs = maxjobs;
467  numJobs = 0;
468 
469 // Schedule ourselves to run 15 minutes from now
470 //
471  schp->Schedule((XrdJob *)this, time(0) + (reScan));
472 }
Definition: XrdJob.hh:43
XrdJob(const char *desc="")
Definition: XrdJob.hh:51
void Schedule(XrdJob *jp)

References XrdGlobal::Sched, and XrdScheduler::Schedule().

+ Here is the call graph for this function:

◆ ~XrdXrootdJob()

XrdXrootdJob::~XrdXrootdJob ( )

Definition at line 482 of file XrdXrootdJob.cc.

483 {
484  if (JobName) free(JobName);
485  myMutex.Lock();
486  Sched->Cancel((XrdJob *)this);
487  myMutex.UnLock();
488 }
void Cancel(XrdJob *jp)

References XrdScheduler::Cancel(), XrdSysMutex::Lock(), XrdGlobal::Sched, and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

Member Function Documentation

◆ Cancel()

int XrdXrootdJob::Cancel ( const char *  jkey = 0,
XrdXrootdResponse resp = 0 
)

Definition at line 494 of file XrdXrootdJob.cc.

495 {
496  XrdXrootdJob2Do *jp = 0;
497  int i, jNum, jNext = 0, numcaned = 0;
498 
499 // Lock our data
500 //
501  myMutex.Lock();
502 
503 // Cancel a specific job if a key was passed
504 //
505  if (jkey)
506  {if ((jp = JobTable.Find(jkey)))
507  {numcaned = 1;
508  if (resp) {jp->delClient(resp);
509  if (!jp->numClients) CleanUp(jp);
510  }
511  else CleanUp(jp);
512  }
513  myMutex.UnLock();
514  return numcaned;
515  }
516 
517 // Delete multiple jobs
518 //
519  while((jNum = JobTable.Next(jNext)) >= 0)
520  {jp = JobTable.Item(jNum);
521  if (resp)
522  {i = jp->numClients;
523  jp->delClient(resp);
524  if (i != jp->numClients) numcaned++;
525  if (!jp->numClients) CleanUp(jp);
526  } else {
527  CleanUp(jp);
528  numcaned++;
529  }
530  }
531 
532 // All done
533 //
534  myMutex.UnLock();
535  return numcaned;
536 }
T * Find(const char *key, int *Tnum=0)
Definition: XrdOucTable.hh:93
T * Item(int Tnum, char **ikey=0)
Definition: XrdOucTable.hh:114
int Next(int &Tnum)
Definition: XrdOucTable.hh:123

References XrdOucTable< T >::Find(), XrdOucTable< T >::Item(), XrdSysMutex::Lock(), XrdOucTable< T >::Next(), and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ DoIt()

void XrdXrootdJob::DoIt ( )
virtual

Implements XrdJob.

Definition at line 542 of file XrdXrootdJob.cc.

543 {
544  int jNum, jNext = 0;
545  XrdXrootdJob2Do *jp;
546 
547 // Scan through all of the jobs looking for disconnected clients
548 //
549  while((jNum = JobTable.Next(jNext)) >= 0)
550  {myMutex.Lock();
551  if ((jp = JobTable.Item(jNum)))
552  {if (jp->JobMark) {if (!jp->verClient()) CleanUp(jp);}
553  else jp->JobMark = 1;
554  }
555  myMutex.UnLock();
556  }
557 
558 // Schedule ourselves to run 15 minutes from now
559 //
560  Sched->Schedule((XrdJob *)this, time(0) + (reScan));
561 }

References XrdOucTable< T >::Item(), XrdSysMutex::Lock(), XrdOucTable< T >::Next(), XrdGlobal::Sched, XrdScheduler::Schedule(), and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ List()

XrdOucTList * XrdXrootdJob::List ( void  )

Definition at line 569 of file XrdXrootdJob.cc.

570 {
571  char *jkey, buff[1024];
572  int tlen, jNum, jNext = 0;
573  XrdXrootdJob2Do *jp;
574  XrdOucTList *tF = 0, *tL = 0, *tp;
575 
576 // Scan through all of the jobs listing each, in turn
577 //
578  while((jNum = JobTable.Next(jNext)) >= 0)
579  {myMutex.Lock();
580  if ((jp = JobTable.Item(jNum, &jkey)) && (tp = jp->lstClient()))
581  {tlen = sprintf(buff, "<job id=\"%s\">%s", JobName, jkey);
582  if (tL) tL->next = new XrdOucTList(buff, tlen, tp);
583  else tF = new XrdOucTList(buff, tlen, tp);
584  tL = tp->next = new XrdOucTList("</job>", 6);
585  }
586  myMutex.UnLock();
587  }
588 
589 // Return the whole schmear
590 //
591  return tF;
592 }

References XrdOucTable< T >::Item(), XrdSysMutex::Lock(), XrdOucTable< T >::Next(), and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ Schedule()

int XrdXrootdJob::Schedule ( const char *  jkey,
const char **  args,
XrdXrootdResponse resp,
int  Opts = 0 
)

Definition at line 598 of file XrdXrootdJob.cc.

602 {
603  XrdXrootdJob2Do *jp;
604  const char *msg = "Job resources currently not available.";
605  int jobNum, rc, isSync = Opts & JOB_Sync;
606 
607 // Make sure we have a target
608 //
609  if (!jkey || !(*jkey))
610  return resp->Send(kXR_ArgMissing, "Job target not specified.");
611 
612 // First find if this is a duplicate or create a new one
613 //
614  myMutex.Lock();
615  if (!(Opts & JOB_Unique) && (jp = JobTable.Find(jkey)))
616  {if (jp->Status == XrdXrootdJob2Do::Job_Done)
617  {rc = sendResult(resp, args[0], jp);
618  myMutex.UnLock();
619  return rc;
620  }
621  if (jp->addClient(resp, Opts) < 0) isSync = 1;
622  else msg = "Job scheduled.";
623  } else {
624  if ((jobNum = JobTable.Alloc()) < 0) isSync = 1;
625  else {if ((jp = new XrdXrootdJob2Do(this, jobNum, args, resp, Opts)))
626  {JobTable.Insert(jp, jkey, jobNum);
627  if (numJobs < maxJobs)
628  {Sched->Schedule((XrdJob *)jp);
629  jp->Status = XrdXrootdJob2Do::Job_Active;
630  jp->doRedrive = 1;
631  }
632  numJobs++; msg = "Job Scheduled";
633  }
634  }
635  }
636 
637 // Tell the client to wait
638 //
639  if (isSync) rc = resp->Send(kXR_wait, 30, msg);
640  else rc = resp->Send(kXR_waitresp, 600, "Job scheduled.");
641  myMutex.UnLock();
642  return rc;
643 }
@ kXR_ArgMissing
Definition: XProtocol.hh:991
@ kXR_waitresp
Definition: XProtocol.hh:906
@ kXR_wait
Definition: XProtocol.hh:905
#define JOB_Unique
Definition: XrdXrootdJob.hh:49
#define JOB_Sync
Definition: XrdXrootdJob.hh:48
int Insert(T *Item, const char *key=0, int Tnum=-1)
Definition: XrdOucTable.hh:105
XrdSys::RAtomic< JobStatus > Status
Definition: XrdXrootdJob.cc:62
friend class XrdXrootdJob2Do
Definition: XrdXrootdJob.hh:53
int Opts
Definition: XrdMpxStats.cc:58

References XrdOucTable< T >::Alloc(), XrdOucTable< T >::Find(), XrdOucTable< T >::Insert(), XrdXrootdJob2Do::Job_Active, XrdXrootdJob2Do::Job_Done, JOB_Sync, JOB_Unique, kXR_ArgMissing, kXR_wait, kXR_waitresp, XrdSysMutex::Lock(), XrdMpx::Opts, XrdGlobal::Sched, XrdScheduler::Schedule(), XrdXrootdResponse::Send(), XrdXrootdJob2Do::Status, XrdSysMutex::UnLock(), and XrdXrootdJob2Do.

+ Here is the call graph for this function:

Friends And Related Function Documentation

◆ XrdXrootdJob2Do

friend class XrdXrootdJob2Do
friend

Definition at line 53 of file XrdXrootdJob.hh.

Referenced by Schedule().


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