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  static void handleError(const DbEnv *dbenv, const char *errpfx, const char *msg);
41 
42  Db* operator->() { return jobDB; }
43  Db* viaNameKeys() { return nameSecondaryKeyDB; }
44  Db* viaEndpointKeys() { return endpointSecondaryKeyDB; }
45  Db* viaServiceInfoKeys() { return serviceInfoSecondaryKeyDB; }
46 
47  DbEnv *dbEnv;
48  Db *jobDB;
49  Db *endpointSecondaryKeyDB;
50  Db *nameSecondaryKeyDB;
51  Db *serviceInfoSecondaryKeyDB;
52  };
53 
54  class BDBException {
55  public:
56  BDBException(const std::string& msg, int ret, bool writeLogMessage = true) throw();
57  ~BDBException() throw() {}
58  const std::string& getMessage() const throw() { return message; }
59  int getReturnValue() const throw() { return returnvalue; }
60 
61  private:
62  std::string message;
63  int returnvalue;
64  };
65  };
66 
67 } // namespace Arc
68 
69 #endif // __ARC_JOBINFORMATIONSTORAGEBDB_H__