#include <ArtSpooler.h>
Public Member Functions | |
| ArtSpooler (const string &spoolDir) | |
| ~ArtSpooler () | |
| void | spoolArt (Article &a) |
| Article * | getSpooledArt (void) |
| void | storeBadArt (Article &a) |
Private Member Functions | |
| string | createID (void) |
| string | extractID (Article &a) |
| int | storeArticle (const string &path, Article &a) |
Private Attributes | |
| string | spoolDir |
| string | artSpool |
| string | badArticles |
| ObjLock * | pLock |
Definition at line 39 of file ArtSpooler.h.
|
|
If the spool directory doesn't exists, the contstructor creates it. It uses ObjLock to manage the access to the Spool.
Definition at line 39 of file ArtSpooler.cc. References artSpool, badArticles, ERROR_LOCATION, mkpdir(), Logger::p(), pLock, slog, and VERB.
00040 {
00041 VERB(slog.p(Logger::Debug) << "ArtSpooler::ArtSpooler ("
00042 << spoolDir << ")\n");
00043
00044 string tmp;
00045
00046 this->spoolDir = spoolDir;
00047 if (mkpdir(spoolDir.c_str(), 0700) == -1) {
00048 string errtxt("Error creating spoolDirectory");
00049 errtxt += spoolDir;
00050 throw(Error(errtxt.c_str(), ERROR_LOCATION));
00051 }
00052 artSpool = spoolDir + "/.artSpool";
00053 if (mkpdir(artSpool.c_str(), 0700) == -1) {
00054 string errtxt("Error creating spoolDirectory");
00055 errtxt += artSpool;
00056 throw(Error(errtxt.c_str(), ERROR_LOCATION));
00057 }
00058 badArticles = spoolDir + "/.badArticles";
00059 if (mkpdir(badArticles.c_str(), 0700) == -1) {
00060 string errtxt("Error creating spoolDirectory");
00061 errtxt += artSpool;
00062 throw(Error(errtxt.c_str(), ERROR_LOCATION));
00063 }
00064 tmp = spoolDir + "/.resourceSpooler.lock";
00065 pLock = new ObjLock(tmp);
00066 }
|
|
|
Definition at line 68 of file ArtSpooler.cc. References Logger::p(), pLock, slog, and VERB.
|
|
|
Create a unique ID
Definition at line 156 of file ArtSpooler.cc. Referenced by storeArticle().
00157 {
00158 #ifdef HAVE_SSTREAM
00159 stringstream sb;
00160 #else
00161 strstream sb;
00162 #endif
00163 pid_t pid;
00164 struct timeval t;
00165
00166 pid = getpid();
00167 gettimeofday(&t, NULL);
00168 sb << (int) pid << (int) t.tv_sec << (int) t.tv_usec;
00169 return sb.rdbuf()->str();
00170 }
|
|
|
Extract ID from article message id
Definition at line 172 of file ArtSpooler.cc. References Article::getfield().
00173 {
00174 string ID = a.getfield("message-id");
00175 ID.replace(0, 3, "");
00176 ID.replace(ID.length() - 1, 1, "");
00177 return ID;
00178 }
|
|
|
Get one article from the Spool (don't forget delete). It returns NULL, if no article is available. A exclusive lock is used.
Definition at line 126 of file ArtSpooler.cc. References artSpool, ObjLock::lockExBlk(), Logger::p(), pLock, Article::read(), slog, ObjLock::unlock(), and VERB. Referenced by main(), and CServer::postspooled().
00127 {
00128 VERB(slog.p(Logger::Debug) << "ArtSpooler::getSpooledArt ()\n");
00129 string an;
00130 Article *pa = NULL;
00131 ifstream is;
00132 struct dirent *d;
00133 DIR *dir;
00134
00135 pLock->lockExBlk();
00136 dir = opendir(artSpool.c_str());
00137 for (d = readdir(dir); d != NULL; d = readdir(dir)) {
00138 if (strncmp("art_", d->d_name, 4) == 0) {
00139 an = artSpool + "/" + d->d_name;
00140 pa = new Article();
00141 is.open(an.c_str());
00142 // FIXME: check status
00143 pa->read(is);
00144 is.close();
00145 unlink(an.c_str());
00146 // FIXME: check status
00147 break;
00148 }
00149 }
00150 closedir(dir);
00151 pLock->unlock();
00152
00153 return pa;
00154 }
|
|
|
Add this article to the spool. The naming convention for articles in the spool: art_nr.txt. nr is a number. A shared Lock is used.
Definition at line 75 of file ArtSpooler.cc. References artSpool, ERROR_LOCATION, ObjLock::lockExBlk(), pLock, slog, storeArticle(), ObjLock::unlock(), and VERB. Referenced by main(), and CServer::spoolarticle().
00076 {
00077 VERB(slog.
00078 p(Logger::Debug) << "ArtSpooler::spoolArt (Article &)\n");
00079 int s;
00080
00081 pLock->lockExBlk();
00082 s = storeArticle(artSpool, a);
00083 pLock->unlock();
00084
00085 if (s != 0) {
00086 throw(Error("spoolArt: duplicateArt", ERROR_LOCATION));
00087 }
00088
00089 }
|
|
||||||||||||
|
store Article in path return 0 success, 1 duplicated Definition at line 105 of file ArtSpooler.cc. References createID(). Referenced by spoolArt(), and storeBadArt().
00106 {
00107 ofstream os;
00108 string fn, id;
00109 struct stat st;
00110 int s;
00111
00112 id = createID();;
00113 fn = path + "/art_" + id;
00114 s = lstat(fn.c_str(), &st);
00115 if (s == -1) {
00116 os.open(fn.c_str());
00117 os << a;
00118 os.close();
00119 s = 0;
00120 } else {
00121 s = 1;
00122 }
00123 return (s);
00124 }
|
|
|
Store the article in the "Bad Article Store". Bad articles (ex. POST error) can be stored with this method. A operator intervention is required to manage this store.
Definition at line 91 of file ArtSpooler.cc. References badArticles, ERROR_LOCATION, ObjLock::lockExBlk(), pLock, slog, storeArticle(), ObjLock::unlock(), and VERB. Referenced by main(), and CServer::postspooled().
00092 {
00093 VERB(slog.
00094 p(Logger::Debug) << "ArtSpooler::storeBadArt (Article &)\n");
00095 int s;
00096
00097 pLock->lockExBlk();
00098 s = storeArticle(badArticles, a);
00099 pLock->unlock();
00100 if (s != 0) {
00101 throw(Error("storeBadArt: duplicateArt", ERROR_LOCATION));
00102 }
00103 }
|
|
|
Definition at line 100 of file ArtSpooler.h. Referenced by ArtSpooler(), getSpooledArt(), and spoolArt(). |
|
|
Definition at line 101 of file ArtSpooler.h. Referenced by ArtSpooler(), and storeBadArt(). |
|
|
Definition at line 102 of file ArtSpooler.h. Referenced by ArtSpooler(), getSpooledArt(), spoolArt(), storeBadArt(), and ~ArtSpooler(). |
|
|
Definition at line 99 of file ArtSpooler.h. |
1.3.6-20040222