XRootD
XrdCmsJob.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d C m s J o b . c c */
4 /* */
5 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Andrew Hanushevsky for Stanford University under contract */
8 /* DE-AC02-76-SFO0515 with the Department of Energy */
9 /* */
10 /* This file is part of the XRootD software suite. */
11 /* */
12 /* XRootD is free software: you can redistribute it and/or modify it under */
13 /* the terms of the GNU Lesser General Public License as published by the */
14 /* Free Software Foundation, either version 3 of the License, or (at your */
15 /* option) any later version. */
16 /* */
17 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20 /* License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25 /* */
26 /* The copyright holder's institutional names and contributor's names may not */
27 /* be used to endorse or promote products derived from this software without */
28 /* specific prior written permission of the institution or contributor. */
29 /******************************************************************************/
30 
31 #include <unistd.h>
32 #include <cctype>
33 #include <cerrno>
34 #include <cstdlib>
35 
36 #include "Xrd/XrdLink.hh"
37 #include "Xrd/XrdScheduler.hh"
38 
39 #include "XrdSys/XrdSysHeaders.hh"
40 
41 #include "XrdCms/XrdCmsJob.hh"
42 #include "XrdCms/XrdCmsProtocol.hh"
43 #include "XrdCms/XrdCmsRRData.hh"
44 #include "XrdCms/XrdCmsTrace.hh"
45 
46 using namespace XrdCms;
47 
48 /******************************************************************************/
49 /* G l o b a l O b j e c t s */
50 /******************************************************************************/
51 
52 namespace XrdCms
53 {
54 extern XrdScheduler *Sched;
55 };
56 
57  XrdSysMutex XrdCmsJob::JobMutex;
58  XrdCmsJob *XrdCmsJob::JobStack = 0;
59 
60 /******************************************************************************/
61 /* A l l o c */
62 /******************************************************************************/
63 
65 {
66  XrdCmsJob *jp;
67 
68 // Grab a protocol object and, if none, return a new one
69 //
70  JobMutex.Lock();
71  if ((jp = JobStack)) JobStack = jp->JobLink;
72  else jp = new XrdCmsJob();
73  JobMutex.UnLock();
74 
75 // Copy relevant sections to the newly allocated protocol object
76 //
77  if (jp)
78  {jp->theProto = Proto;
79  jp->theData = Data;
80  jp->Comment = Proto->myRole;
81  Proto->Link->setRef(1);
82  } else Say.Emsg("Job","No more job objects to serve",Proto->Link->Name());
83 
84 // All done
85 //
86  return jp;
87 }
88 
89 /******************************************************************************/
90 /* D o I t */
91 /******************************************************************************/
92 
94 {
95  int rc;
96 
97 // Simply execute the method on the data. If operation started and we have to
98 // wait foir it, simply reschedule ourselves for a later time.
99 //
100  if ((rc = theProto->Execute(*theData)))
101  if (rc == -EINPROGRESS)
102  {Sched->Schedule((XrdJob *)this, theData->waitVal+time(0)); return;}
103  theProto->Ref(-1);
104  Recycle();
105 }
106 
107 /******************************************************************************/
108 /* R e c y c l e */
109 /******************************************************************************/
110 
112 {
113 
114 // Dereference the link at this point
115 //
116  theProto->Link->setRef(-1);
117 
118 // Release the data buffer
119 //
120  if (theData) {XrdCmsRRData::Objectify(theData); theData = 0;}
121 
122 // Push ourselves on the stack
123 //
124  JobMutex.Lock();
125  JobLink = JobStack;
126  JobStack = this;
127  JobMutex.UnLock();
128 }
void Recycle()
Definition: XrdCmsJob.cc:111
static XrdCmsJob * Alloc(XrdCmsProtocol *, XrdCmsRRData *)
Definition: XrdCmsJob.cc:64
void DoIt()
Definition: XrdCmsJob.cc:93
static XrdCmsRRData * Objectify(XrdCmsRRData *op=0)
Definition: XrdCmsRRData.cc:68
Definition: XrdJob.hh:43
const char * Comment
Definition: XrdJob.hh:47
void Schedule(XrdJob *jp)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95
XrdScheduler * Sched
XrdSysError Say