xrootd
Loading...
Searching...
No Matches
XrdSutPFCache.hh
Go to the documentation of this file.
1#ifndef __SUT_CACHE_H__
2#define __SUT_CACHE_H__
3/******************************************************************************/
4/* */
5/* X r d S u t C a c h e . h h */
6/* */
7/* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University */
8/* Produced by Gerri Ganis for CERN */
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 "XProtocol/XPtypes.hh"
33#include "XrdOuc/XrdOucHash.hh"
36
37/******************************************************************************/
38/* */
39/* For caching temporary information during the authentication handshake */
40/* */
41/******************************************************************************/
42
44{
45public:
46
47inline void Lock(XrdSysMutex *Mutex)
48 {if (mtx) {if (mtx != Mutex) mtx->UnLock();
49 else return;
50 }
51 Mutex->Lock();
52 mtx = Mutex;
53 };
54
55inline void Set(XrdSysMutex *Mutex)
56 {if (mtx) {if (mtx != Mutex) mtx->UnLock();
57 else return;
58 }
59 mtx = Mutex;
60 };
61
62inline void UnLock() {if (mtx) {mtx->UnLock(); mtx = 0;}}
63
65
67protected:
69};
70
72{
73private:
74 XrdSysRWLock rwlock; // Access synchronizator
75 int cachesz; // Number of entries allocated
76 int cachemx; // Largest Index of allocated entries
77 XrdSutPFEntry **cachent; // Pointers to filled entries
78 kXR_int32 utime; // time at which was last updated
79 int lifetime; // lifetime (in secs) of the cache info
80 XrdOucHash<kXR_int32> hashtable; // Reflects the file index structure
81 kXR_int32 htmtime; // time at which hash table was last rebuild
82 XrdOucString pfile; // file name (if loaded from file)
83 bool isinit; // true if already initialized
84
85 XrdSutPFEntry *Get(const char *ID, bool *wild);
86 bool Delete(XrdSutPFEntry *pfEnt);
87
88 static const int maxTries = 100; // Max time to try getting a lock
89 static const int retryMSW = 300; // Milliseconds to wait to get lock
90
91public:
92 XrdSutPFCache() { cachemx = -1; cachesz = 0; cachent = 0; lifetime = 300;
93 utime = -1; htmtime = -1; pfile = ""; isinit = 0; }
94 virtual ~XrdSutPFCache();
95
96 // Status
97 int Entries() const { return (cachemx+1); }
98 bool Empty() const { return (cachemx == -1); }
99
100 // Initialization methods
101 int Init(int capacity = 100, bool lock = 1);
102 int Reset(int newsz = -1, bool lock = 1);
103 int Load(const char *pfname); // build cache of a pwd file
104 int Flush(const char *pfname = 0); // flush content to pwd file
105 int Refresh(); // refresh content from source file
106 int Rehash(bool force = 0, bool lock = 1); // (re)build hash table
107 void SetLifetime(int lifet = 300) { lifetime = lifet; }
108
109 // Cache management
110 XrdSutPFEntry *Get(int i) const { return (i<=cachemx) ? cachent[i] :
111 (XrdSutPFEntry *)0; }
112 XrdSutPFEntry *Get(XrdSutPFCacheRef &urRef, const char *ID, bool *wild = 0);
113 XrdSutPFEntry *Add(XrdSutPFCacheRef &urRef, const char *ID, bool force = 0);
114 bool Remove(const char *ID, int opt = 1);
115 int Trim(int lifet = 0);
116
117 // For debug purposes
118 void Dump(const char *msg= 0);
119};
120
121#endif
122
int kXR_int32
Definition XPtypes.hh:89
Definition XrdOucHash.hh:128
Definition XrdOucString.hh:254
Definition XrdSutPFCache.hh:44
void Lock(XrdSysMutex *Mutex)
Definition XrdSutPFCache.hh:47
~XrdSutPFCacheRef()
Definition XrdSutPFCache.hh:66
XrdSysMutex * mtx
Definition XrdSutPFCache.hh:68
void Set(XrdSysMutex *Mutex)
Definition XrdSutPFCache.hh:55
void UnLock()
Definition XrdSutPFCache.hh:62
XrdSutPFCacheRef()
Definition XrdSutPFCache.hh:64
Definition XrdSutPFCache.hh:72
int lifetime
Definition XrdSutPFCache.hh:79
bool Remove(const char *ID, int opt=1)
static const int retryMSW
Definition XrdSutPFCache.hh:89
int cachemx
Definition XrdSutPFCache.hh:76
bool isinit
Definition XrdSutPFCache.hh:83
bool Empty() const
Definition XrdSutPFCache.hh:98
XrdSutPFCache()
Definition XrdSutPFCache.hh:92
XrdSysRWLock rwlock
Definition XrdSutPFCache.hh:74
XrdOucString pfile
Definition XrdSutPFCache.hh:82
int Entries() const
Definition XrdSutPFCache.hh:97
static const int maxTries
Definition XrdSutPFCache.hh:88
int Flush(const char *pfname=0)
virtual ~XrdSutPFCache()
XrdSutPFEntry * Add(XrdSutPFCacheRef &urRef, const char *ID, bool force=0)
XrdSutPFEntry * Get(int i) const
Definition XrdSutPFCache.hh:110
void SetLifetime(int lifet=300)
Definition XrdSutPFCache.hh:107
int Reset(int newsz=-1, bool lock=1)
XrdSutPFEntry * Get(const char *ID, bool *wild)
int Init(int capacity=100, bool lock=1)
XrdSutPFEntry ** cachent
Definition XrdSutPFCache.hh:77
void Dump(const char *msg=0)
int Load(const char *pfname)
int Rehash(bool force=0, bool lock=1)
kXR_int32 htmtime
Definition XrdSutPFCache.hh:81
XrdSutPFEntry * Get(XrdSutPFCacheRef &urRef, const char *ID, bool *wild=0)
XrdOucHash< kXR_int32 > hashtable
Definition XrdSutPFCache.hh:80
int Trim(int lifet=0)
int cachesz
Definition XrdSutPFCache.hh:75
bool Delete(XrdSutPFEntry *pfEnt)
kXR_int32 utime
Definition XrdSutPFCache.hh:78
Definition XrdSutPFEntry.hh:78
Definition XrdSysPthread.hh:165
void Lock()
Definition XrdSysPthread.hh:222
void UnLock()
Definition XrdSysPthread.hh:224
Definition XrdSysPthread.hh:330