ARC SDK
JobInformationStorageBDB.h
1 // -*- indent-tabs-mode: nil -*-
2 
3 #ifndef __ARC_JOBINFORMATIONSTORAGEBDB_H__
4 #define __ARC_JOBINFORMATIONSTORAGEBDB_H__
5 
6 #include <db_cxx.h>
7 
8 #include "JobInformationStorage.h"
9 
10 namespace Arc {
11 
13  public:
14  JobInformationStorageBDB(const std::string& name, unsigned nTries = 10, unsigned tryInterval = 500000);
15  virtual ~JobInformationStorageBDB() {}
16 
17  static JobInformationStorage* Instance(const std::string& name) { return new JobInformationStorageBDB(name); }
18 
19  bool ReadAll(std::list<Job>& jobs, const std::list<std::string>& rejectEndpoints = std::list<std::string>());
20  bool Read(std::list<Job>& jobs, std::list<std::string>& jobIdentifiers,
21  const std::list<std::string>& endpoints = std::list<std::string>(),
22  const std::list<std::string>& rejectEndpoints = std::list<std::string>());
23  bool Write(const std::list<Job>& jobs);
24  bool Write(const std::list<Job>& jobs, const std::set<std::string>& prunedServices, std::list<const Job*>& newJobs);
25  bool Clean();
26  bool Remove(const std::list<std::string>& jobids);
27 
28  private:
29  static void logErrorMessage(int err);
30 
31  static Logger logger;
32 
33  class JobDB {
34  public:
35  JobDB(const std::string&, u_int32_t = DB_RDONLY);
36  ~JobDB();
37 
38  void tearDown();
39 
40 #if ((DB_VERSION_MAJOR > 4)||(DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 3))
41  static void handleError(const DbEnv *dbenv, const char *errpfx, const char *msg);
42 #else
43  static void handleError(const char *errpfx, char *msg);
44 #endif
45 
46  Db* operator->() { return jobDB; }
47  Db* viaNameKeys() { return nameSecondaryKeyDB; }
48  Db* viaEndpointKeys() { return endpointSecondaryKeyDB; }
49  Db* viaServiceInfoKeys() { return serviceInfoSecondaryKeyDB; }
50 
51  DbEnv *dbEnv;
52  Db *jobDB;
53  Db *endpointSecondaryKeyDB;
54  Db *nameSecondaryKeyDB;
55  Db *serviceInfoSecondaryKeyDB;
56  };
57 
58  class BDBException {
59  public:
60  BDBException(const std::string& msg, int ret, bool writeLogMessage = true) throw();
61  ~BDBException() throw() {}
62  const std::string& getMessage() const throw() { return message; }
63  int getReturnValue() const throw() { return returnvalue; }
64 
65  private:
66  std::string message;
67  int returnvalue;
68  };
69  };
70 
71 } // namespace Arc
72 
73 #endif // __ARC_JOBINFORMATIONSTORAGEBDB_H__