Back to index

nordugrid-arc-nox  1.1.0~rc6
job_queue.h
Go to the documentation of this file.
00001 #ifndef __ARC__JOB_QUEUE_H__
00002 #define __ARC__JOB_QUEUE_H__ 
00003 
00004 #include <string>
00005 #include <db_cxx.h>
00006 #include <arc/Logger.h>
00007 #include "job.h"
00008 
00009 namespace Arc {
00010 
00011 class JobNotFoundException: public std::exception
00012 {
00013     virtual const char* what() const throw()
00014     {
00015         return "JobNotFound ";
00016     }
00017 };
00018 
00019 class JobSelector
00020 {
00021     public:
00022         JobSelector() {};
00023         virtual ~JobSelector() {};
00024         virtual bool match(Job *job) { return true; };
00025 };
00026 
00027 class JobQueueIterator
00028 {
00029     friend class JobQueue;
00030     private:
00031         DbTxn *tid_;
00032         Dbc *cursor_;
00033         bool has_more_;
00034         Job *job_;
00035         bool have_status_;
00036         JobSelector *selector_;
00037     protected:
00038         JobQueueIterator(DbTxn *tid_, Dbc *cursor);
00039         JobQueueIterator(DbTxn *tid_, Dbc *cursor, JobSelector *selector_);
00040         void next(void);
00041     public:
00042         JobQueueIterator();
00043         ~JobQueueIterator();
00044         bool hasMore(void) const { return has_more_; };
00045         Job *operator*() const { return job_; };
00046         const JobQueueIterator &operator++();
00047         const JobQueueIterator &operator++(int);
00048         bool refresh(void);
00049         void remove(void);
00050         void finish(void);
00051 };
00052 
00053 class JobQueue 
00054 {
00055     private:
00056         DbEnv *env_;
00057         Db *db_;
00058         Arc::Logger logger_;
00059     public:
00060         JobQueue():logger_(Arc::Logger::rootLogger, "JobQ") { env_ = NULL; db_ = NULL; };
00061         ~JobQueue();
00062         void init(const std::string &dbroot, const std::string &store_name);
00063         void refresh(Job &j);
00064         Job *operator[](const std::string &id);
00065         void remove(Job &job);
00066         void remove(const std::string &id);
00067         JobQueueIterator getAll(void);
00068         JobQueueIterator getAll(JobSelector *selector_);
00069         void sync(void);
00070         void checkpoint(void);
00071 };
00072 
00073 } // namespace Arc
00074 
00075 #endif //  __ARC__JOB_QUEUE_H__
00076