/* * FragmentJob.hpp * * Originally taken from my JobMarket project at 1.1.4. * * Created on: Oct 19, 2011 * Author: heber */ #ifndef FRAGMENTJOB_HPP_ #define FRAGMENTJOB_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include "boost/shared_ptr.hpp" #include "boost/serialization/access.hpp" #include "boost/serialization/shared_ptr.hpp" #ifdef HAVE_JOBMARKET #include "JobMarket/Results/FragmentResult.hpp" #include "JobMarket/JobId.hpp" #include "JobMarket/types.hpp" #else #include "Jobs//JobMarket/FragmentResult.hpp" #include "Jobs//JobMarket/JobId.hpp" #include "Jobs//JobMarket/types.hpp" #endif class MPQCCommandFragmentController; /** FragmentJob contains all information for the Worker to start the job and * deliver a FragmentResult. * * Important is that this class is fully serializable such that it can be * transfered to a scheduler (server) and be deserialized by the Worker. */ class FragmentJob : public JobId { //!> allow MPQCCommandFragmentController access to setJobId() friend class MPQCCommandFragmentController; public: //!> typedef for priorities of a job typedef size_t priority_t; private: //!> Internal priority of the job priority_t priority; public: typedef boost::shared_ptr ptr; FragmentJob(const JobId_t _JobId); virtual ~FragmentJob(); virtual FragmentResult::ptr Work() = 0; bool operator==(const FragmentJob &other) const; bool operator!=(const FragmentJob &other) const { return !(*this == other); } /** Less-than-operator required for priority queue. * * \param other other instance to compare to * \return true - this instance is less than other (in priority) */ bool operator<(const FragmentJob &other) const { return priority < other.priority; } /** Setter for the job's priority. * * \param _priority priority to set */ void setPriority(const priority_t _priority) { priority = _priority; } protected: /** Passing JobId::setId() on to grant FragmentController' access. * * \param _id new id to set */ void setId(const JobId_t _id) { JobId::setId(_id); } private: /** private default cstor for serialization only * * Use normal cstor with JobId::IllegalJob if you want to instantiate * a job without id. */ FragmentJob(); friend class boost::serialization::access; // serialization template void serialize(Archive& ar, const unsigned int version) { ar & boost::serialization::base_object(*this); ar & priority; } }; /** Helper function for allow less on ptr's of FragmentJob. * * \param a first instance * \param b second instance * \return \see FragmentJob::operator<() */ inline bool operator<(const FragmentJob::ptr &a, const FragmentJob::ptr &b) { return (*a) < (*b); } #endif /* FRAGMENTJOB_HPP_ */