XrdCmsJob.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                          X r d C m s J o b . c c                           */
00004 /*                                                                            */
00005 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*                            All Rights Reserved                             */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010 
00011 //       $Id: XrdCmsJob.cc 24468 2008-06-22 16:47:03Z ganis $
00012 
00013 const char *XrdCmsJobCVSID = "$Id: XrdCmsJob.cc 24468 2008-06-22 16:47:03Z ganis $";
00014  
00015 #include <unistd.h>
00016 #include <ctype.h>
00017 #include <errno.h>
00018 #include <stdlib.h>
00019 
00020 #include "Xrd/XrdLink.hh"
00021 #include "Xrd/XrdScheduler.hh"
00022 
00023 #include "XrdSys/XrdSysHeaders.hh"
00024 
00025 #include "XrdCms/XrdCmsJob.hh"
00026 #include "XrdCms/XrdCmsProtocol.hh"
00027 #include "XrdCms/XrdCmsRRData.hh"
00028 #include "XrdCms/XrdCmsTrace.hh"
00029 
00030 using namespace XrdCms;
00031 
00032 /******************************************************************************/
00033 /*                        G l o b a l   O b j e c t s                         */
00034 /******************************************************************************/
00035 
00036 namespace XrdCms
00037 {
00038 extern XrdScheduler               *Sched;
00039 };
00040 
00041        XrdSysMutex      XrdCmsJob::JobMutex;
00042        XrdCmsJob       *XrdCmsJob::JobStack = 0;
00043 
00044 /******************************************************************************/
00045 /*                                 A l l o c                                  */
00046 /******************************************************************************/
00047 
00048 XrdCmsJob *XrdCmsJob::Alloc(XrdCmsProtocol *Proto, XrdCmsRRData *Data)
00049 {
00050    XrdCmsJob *jp;
00051 
00052 // Grab a protocol object and, if none, return a new one
00053 //
00054    JobMutex.Lock();
00055    if ((jp = JobStack)) JobStack = jp->JobLink;
00056       else jp = new XrdCmsJob();
00057    JobMutex.UnLock();
00058 
00059 // Copy relevant sections to the newly allocated protocol object
00060 //
00061    if (jp)
00062       {jp->theProto = Proto;
00063        jp->theData  = Data;
00064        jp->Comment  = Proto->myRole;
00065        Proto->Link->setRef(1);
00066       } else Say.Emsg("Job","No more job objects to serve",Proto->Link->Name());
00067 
00068 // All done
00069 //
00070    return jp;
00071 }
00072 
00073 /******************************************************************************/
00074 /*                                  D o I t                                   */
00075 /******************************************************************************/
00076   
00077 void XrdCmsJob::DoIt()
00078 {
00079    int rc;
00080 
00081 // Simply execute the method on the data. If operation started and we have to
00082 // wait foir it, simply reschedule ourselves for a later time.
00083 //
00084    if ((rc = theProto->Execute(*theData)))
00085       if (rc == -EINPROGRESS)
00086          {Sched->Schedule((XrdJob *)this, theData->waitVal+time(0)); return;}
00087    Recycle();
00088 }
00089 
00090 /******************************************************************************/
00091 /*                               R e c y c l e                                */
00092 /******************************************************************************/
00093   
00094 void XrdCmsJob::Recycle()
00095 {
00096 
00097 // Dereference the link at this point
00098 //
00099    theProto->Link->setRef(-1);
00100 
00101 // Release the data buffer
00102 //
00103    if (theData) {XrdCmsRRData::Objectify(theData); theData = 0;}
00104 
00105 // Push ourselves on the stack
00106 //
00107    JobMutex.Lock();
00108    JobLink  = JobStack;
00109    JobStack = this;
00110    JobMutex.UnLock();
00111 }

Generated on Tue Jul 5 14:46:24 2011 for ROOT_528-00b_version by  doxygen 1.5.1