XRootD
Loading...
Searching...
No Matches
XrdSsiServReal Class Reference

#include <XrdSsiServReal.hh>

+ Inheritance diagram for XrdSsiServReal:
+ Collaboration diagram for XrdSsiServReal:

Public Member Functions

 XrdSsiServReal (const char *contact, int hObj)
 
 ~XrdSsiServReal ()
 
void ProcessRequest (XrdSsiRequest &reqRef, XrdSsiResource &resRef)
 Process a request; client-side or server-side.
 
void Recycle (XrdSsiSessReal *sObj, bool reuse)
 
bool Stop (bool immed=false)
 Stop the client-side service. This is never called server-side.
 
void StopReuse (const char *resKey)
 
- Public Member Functions inherited from XrdSsiService
 XrdSsiService ()
 Constructor.
 
virtual bool Attach (XrdSsiErrInfo &eInfo, const std::string &handle, XrdSsiRequest &reqRef, XrdSsiResource *resP=0)
 Attach to a backgrounded request.
 
int GetVersion ()
 
virtual bool Prepare (XrdSsiErrInfo &eInfo, const XrdSsiResource &rDesc)
 Prepare for processing subsequent resource request.
 

Additional Inherited Members

- Static Public Attributes inherited from XrdSsiService
static const int SsiVersion = 0x00020000
 
- Protected Member Functions inherited from XrdSsiService
virtual ~XrdSsiService ()
 Destructor. The service object cannot be explicitly deleted. Use Stop().
 

Detailed Description

Definition at line 41 of file XrdSsiServReal.hh.

Constructor & Destructor Documentation

◆ XrdSsiServReal()

XrdSsiServReal::XrdSsiServReal ( const char * contact,
int hObj )
inline

Definition at line 53 of file XrdSsiServReal.hh.

54 : manNode(strdup(contact)), freeSes(0),
55 freeCnt(0), freeMax(hObj), actvSes(0),
56 doStop(false) {}

◆ ~XrdSsiServReal()

XrdSsiServReal::~XrdSsiServReal ( )

Definition at line 61 of file XrdSsiServReal.cc.

62{
64
65// Free pointer to the manager node
66//
67 if (manNode) {free(manNode); manNode = 0;}
68
69// Delete all free session objects
70//
71 while((sP = freeSes))
72 {freeSes = sP->nextSess;
73 delete sP;
74 }
75}
XrdSsiSessReal * nextSess

References XrdSsiSessReal::nextSess.

Member Function Documentation

◆ ProcessRequest()

void XrdSsiServReal::ProcessRequest ( XrdSsiRequest & reqRef,
XrdSsiResource & resRef )
virtual

Process a request; client-side or server-side.

When a client calls ProcessRequest() the same method is called server-side with the same parameters that the client specified except for timeOut which is always set to zero server-side.

Parameters
reqRefReference to the Request object that describes the request.
resRefReference to the Resource object that describes the resource that the request will be using.

All results are returned via the request object callback methods. For background queries, the XrdSsiRequest::ProcessResponse() is called with a response type of isHandle when the request is handed off to the endpoint for execution (see XrdSsiRequest::SetDetachTTL).

Implements XrdSsiService.

Definition at line 170 of file XrdSsiServReal.cc.

172{
173 static const uint32_t useCache = XrdSsiResource::Reusable
175 XrdSysMutexHelper mHelp;
176 XrdSsiSessReal *sObj;
177 std::string resKey;
178 int uEnt;
179 bool hold = (resRef.rOpts & XrdSsiResource::Reusable) != 0;
180 char epURL[4096];
181
182// Validate the resource name
183//
184 if (resRef.rName.length() == 0)
185 {XrdSsiUtils::RetErr(reqRef, "Resource name missing.", EINVAL);
186 return;
187 }
188
189// Check if this is a reusable resource. Reusable resources are a bit more
190// complicated to pull off. In any case, we need to hold the cache lock.
191//
192 if (resRef.rOpts & useCache)
193 {mHelp.Lock(&rcMutex);
194 if (ResReuse(reqRef, resRef, resKey)) return;
195 }
196
197// Get a sid entry number
198//
199 if ((uEnt = sidScale.getEnt()) < 0)
200 {XrdSsiUtils::RetErr(reqRef, "Out of stream resources.", ENOSR);
201 return;
202 }
203
204// Construct url
205//
206 if (!GenURL(&resRef, epURL, sizeof(epURL), uEnt))
207 {XrdSsiUtils::RetErr(reqRef, "Resource url is too long.", ENAMETOOLONG);
208 sidScale.retEnt(uEnt);
209 return;
210 }
211
212// Obtain a new session object
213//
214 if (!(sObj = Alloc(resRef.rName.c_str(), uEnt, hold)))
215 {XrdSsiUtils::RetErr(reqRef, "Insufficient memory.", ENOMEM);
216 sidScale.retEnt(uEnt);
217 return;
218 }
219
220// Tag the session object with the resource key if it is being held. We need
221// to do this before doing provision as that may fail at any point.
222//
223 if (hold) sObj->SetKey(resKey.c_str());
224
225// Now just provision this resource which will execute the request should it
226// be successful. If Provision() fails, we need to delete the session object
227// because its file object now is in an usable state (funky client interface).
228//
229 if (!(sObj->Provision(&reqRef, epURL))) Recycle(sObj, false);
230
231// If this was started with a reusable resource, put the session in the cache.
232// The resource key was constructed by the call to ResReuse() and the cache
233// mutex is still held at this point (will be released upon return).
234//
235 if (hold) resCache[resKey] = sObj;
236}
#define ENOSR
uint32_t rOpts
Resource options. One or more of he following:
static const uint32_t Reusable
std::string rName
-> Name of the resource to be used
static const uint32_t Discard
void retEnt(int xEnt)
void Recycle(XrdSsiSessReal *sObj, bool reuse)
void SetKey(const char *key)
bool Provision(XrdSsiRequest *reqP, const char *epURL)
static void RetErr(XrdSsiRequest &reqP, const char *eTxt, int eNum)
void Lock(XrdSysMutex *Mutex)
XrdSsiScale sidScale

References XrdSsiResource::Discard, ENOSR, XrdSsiScale::getEnt(), XrdSysMutexHelper::Lock(), XrdSsiSessReal::Provision(), Recycle(), XrdSsiScale::retEnt(), XrdSsiUtils::RetErr(), XrdSsiResource::Reusable, XrdSsiResource::rName, XrdSsiResource::rOpts, XrdSsiSessReal::SetKey(), and XrdSsi::sidScale.

+ Here is the call graph for this function:

◆ Recycle()

void XrdSsiServReal::Recycle ( XrdSsiSessReal * sObj,
bool reuse )

Definition at line 242 of file XrdSsiServReal.cc.

243{
244 EPNAME("Recycle");
245 static const char *tident = 0;
246 const char *resKey;
247 bool doDel;
248
249// Clear all pending events (likely not needed)
250//
251 sObj->ClrEvent();
252
253// Remove entry from the reusable cache if present
254//
255 if ((resKey = sObj->GetKey())) StopReuse(resKey);
256
257// Add to queue unless we have too many of these or caller wants a deletion.
258//
259 myMutex.Lock();
260 actvSes--;
261 DEBUG("Sess " <<sObj->GetSID() <<"# reuse=" <<reuse <<" free=" <<freeCnt
262 <<" active=" <<actvSes);
263
264 doDel = ((actvSes == 0 && doStop) || !reuse || freeCnt >= freeMax);
265
266 DEBUG("reuse=" <<reuse <<" del=" <<doDel
267 <<"; sessions: free=" <<freeCnt <<" active=" <<actvSes);
268
269 if (doDel) {myMutex.UnLock(); delete sObj;}
270 else {sObj->nextSess = freeSes;
271 freeSes = sObj;
272 freeCnt++;
273 myMutex.UnLock();
274 }
275}
#define tident
#define DEBUG(x)
#define EPNAME(x)
void ClrEvent()
void StopReuse(const char *resKey)
uint32_t GetSID()
const char * GetKey()

References XrdSsiEvent::ClrEvent(), DEBUG, EPNAME, XrdSsiSessReal::GetKey(), XrdSsiSessReal::GetSID(), XrdSysMutex::Lock(), XrdSsiSessReal::nextSess, StopReuse(), tident, and XrdSysMutex::UnLock().

Referenced by ProcessRequest().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Stop()

bool XrdSsiServReal::Stop ( bool immed = false)
virtual

Stop the client-side service. This is never called server-side.

Parameters
immedWhen true, the service is only stopped if here are no active requests. Otherwise, after all requests have finished. the service object is deleted.
Returns
true Service has been stopped. Once all requests have been completed, the service object will be deleted.
false Service cannot be stopped because there are still active foreground requests and the immed parameter was true.

Reimplemented from XrdSsiService.

Definition at line 322 of file XrdSsiServReal.cc.

323{
324// Make sure we are clean
325//
326 myMutex.Lock();
327 if (actvSes)
328 {if (immed) {myMutex.UnLock(); return false;}
329 doStop = true;
330 myMutex.UnLock();
331 return true;
332 }
333 myMutex.UnLock();
334 delete this;
335 return true;
336}

References XrdSysMutex::Lock(), and XrdSysMutex::UnLock().

+ Here is the call graph for this function:

◆ StopReuse()

void XrdSsiServReal::StopReuse ( const char * resKey)

Definition at line 342 of file XrdSsiServReal.cc.

343{
344 EPNAME("StopReuse");
345 static const char *tident = "ServReuse";
346 std::map<std::string, XrdSsiSessReal *>::iterator it;
347
348// Remove this entry from the reuse cache
349//
350 rcMutex.Lock();
351 it = resCache.find(resKey);
352 if (it != resCache.end())
353 {resCache.erase(it);
354 DEBUG("resCache " <<resKey <<" removed.");
355 }
356 rcMutex.UnLock();
357}

References DEBUG, EPNAME, XrdSysMutex::Lock(), tident, and XrdSysMutex::UnLock().

Referenced by Recycle(), and XrdSsiSessReal::UnHold().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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