| 1 | /*
|
|---|
| 2 | * FragmentJob.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Originally taken from my JobMarket project at 1.1.4.
|
|---|
| 5 | *
|
|---|
| 6 | * Created on: Oct 19, 2011
|
|---|
| 7 | * Author: heber
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #ifndef FRAGMENTJOB_HPP_
|
|---|
| 11 | #define FRAGMENTJOB_HPP_
|
|---|
| 12 |
|
|---|
| 13 | // include config.h
|
|---|
| 14 | #ifdef HAVE_CONFIG_H
|
|---|
| 15 | #include <config.h>
|
|---|
| 16 | #endif
|
|---|
| 17 |
|
|---|
| 18 | #include <string>
|
|---|
| 19 |
|
|---|
| 20 | #include "boost/shared_ptr.hpp"
|
|---|
| 21 | #include "boost/serialization/access.hpp"
|
|---|
| 22 | #include "boost/serialization/shared_ptr.hpp"
|
|---|
| 23 |
|
|---|
| 24 | #ifdef HAVE_JOBMARKET
|
|---|
| 25 | #include "JobMarket/Results/FragmentResult.hpp"
|
|---|
| 26 | #include "JobMarket/JobId.hpp"
|
|---|
| 27 | #include "JobMarket/types.hpp"
|
|---|
| 28 | #else
|
|---|
| 29 | #include "Jobs//JobMarket/FragmentResult.hpp"
|
|---|
| 30 | #include "Jobs//JobMarket/JobId.hpp"
|
|---|
| 31 | #include "Jobs//JobMarket/types.hpp"
|
|---|
| 32 | #endif
|
|---|
| 33 |
|
|---|
| 34 | class MPQCCommandFragmentController;
|
|---|
| 35 |
|
|---|
| 36 | /** FragmentJob contains all information for the Worker to start the job and
|
|---|
| 37 | * deliver a FragmentResult.
|
|---|
| 38 | *
|
|---|
| 39 | * Important is that this class is fully serializable such that it can be
|
|---|
| 40 | * transfered to a scheduler (server) and be deserialized by the Worker.
|
|---|
| 41 | */
|
|---|
| 42 | class FragmentJob : public JobId
|
|---|
| 43 | {
|
|---|
| 44 | //!> allow MPQCCommandFragmentController access to setJobId()
|
|---|
| 45 | friend class MPQCCommandFragmentController;
|
|---|
| 46 |
|
|---|
| 47 | public:
|
|---|
| 48 | //!> typedef for priorities of a job
|
|---|
| 49 | typedef size_t priority_t;
|
|---|
| 50 |
|
|---|
| 51 | private:
|
|---|
| 52 | //!> Internal priority of the job
|
|---|
| 53 | priority_t priority;
|
|---|
| 54 |
|
|---|
| 55 | public:
|
|---|
| 56 | typedef boost::shared_ptr<FragmentJob> ptr;
|
|---|
| 57 |
|
|---|
| 58 | FragmentJob(const JobId_t _JobId);
|
|---|
| 59 | virtual ~FragmentJob();
|
|---|
| 60 |
|
|---|
| 61 | virtual FragmentResult::ptr Work() = 0;
|
|---|
| 62 |
|
|---|
| 63 | bool operator==(const FragmentJob &other) const;
|
|---|
| 64 |
|
|---|
| 65 | bool operator!=(const FragmentJob &other) const {
|
|---|
| 66 | return !(*this == other);
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | /** Less-than-operator required for priority queue.
|
|---|
| 70 | *
|
|---|
| 71 | * \param other other instance to compare to
|
|---|
| 72 | * \return true - this instance is less than other (in priority)
|
|---|
| 73 | */
|
|---|
| 74 | bool operator<(const FragmentJob &other) const {
|
|---|
| 75 | return priority < other.priority;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | /** Setter for the job's priority.
|
|---|
| 79 | *
|
|---|
| 80 | * \param _priority priority to set
|
|---|
| 81 | */
|
|---|
| 82 | void setPriority(const priority_t _priority) {
|
|---|
| 83 | priority = _priority;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | protected:
|
|---|
| 87 | /** Passing JobId::setId() on to grant FragmentController' access.
|
|---|
| 88 | *
|
|---|
| 89 | * \param _id new id to set
|
|---|
| 90 | */
|
|---|
| 91 | void setId(const JobId_t _id) { JobId::setId(_id); }
|
|---|
| 92 |
|
|---|
| 93 | private:
|
|---|
| 94 | /** private default cstor for serialization only
|
|---|
| 95 | *
|
|---|
| 96 | * Use normal cstor with JobId::IllegalJob if you want to instantiate
|
|---|
| 97 | * a job without id.
|
|---|
| 98 | */
|
|---|
| 99 | FragmentJob();
|
|---|
| 100 |
|
|---|
| 101 | friend class boost::serialization::access;
|
|---|
| 102 | // serialization
|
|---|
| 103 | template <typename Archive>
|
|---|
| 104 | void serialize(Archive& ar, const unsigned int version)
|
|---|
| 105 | {
|
|---|
| 106 | ar & boost::serialization::base_object<JobId>(*this);
|
|---|
| 107 | ar & priority;
|
|---|
| 108 | }
|
|---|
| 109 | };
|
|---|
| 110 |
|
|---|
| 111 | /** Helper function for allow less on ptr's of FragmentJob.
|
|---|
| 112 | *
|
|---|
| 113 | * \param a first instance
|
|---|
| 114 | * \param b second instance
|
|---|
| 115 | * \return \see FragmentJob::operator<()
|
|---|
| 116 | */
|
|---|
| 117 | inline
|
|---|
| 118 | bool operator<(const FragmentJob::ptr &a, const FragmentJob::ptr &b)
|
|---|
| 119 | { return (*a) < (*b); }
|
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 | #endif /* FRAGMENTJOB_HPP_ */
|
|---|