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 FragmentController;
|
---|
35 | class FragmentJobTest;
|
---|
36 | class FragmentQueueTest;
|
---|
37 | class FragmentWorker;
|
---|
38 |
|
---|
39 | /** FragmentJob contains all information for the Worker to start the job and
|
---|
40 | * deliver a FragmentResult.
|
---|
41 | *
|
---|
42 | * Important is that this class is fully serializable such that it can be
|
---|
43 | * transfered to a scheduler (server) and be deserialized by the Worker.
|
---|
44 | */
|
---|
45 | class FragmentJob : public JobId
|
---|
46 | {
|
---|
47 | //!> allow FragmentQueue unit test access
|
---|
48 | friend class FragmentQueueTest;
|
---|
49 | //!> allow own unit test access
|
---|
50 | friend class FragmentJobTest;
|
---|
51 | //!> allow FragmentController access to setJobId()
|
---|
52 | friend class FragmentController;
|
---|
53 |
|
---|
54 | public:
|
---|
55 | //!> typedef for priorities of a job
|
---|
56 | typedef size_t priority_t;
|
---|
57 |
|
---|
58 | private:
|
---|
59 | //!> Internal priority of the job
|
---|
60 | priority_t priority;
|
---|
61 |
|
---|
62 | public:
|
---|
63 | typedef boost::shared_ptr<FragmentJob> ptr;
|
---|
64 |
|
---|
65 | FragmentJob(const JobId_t _JobId);
|
---|
66 | virtual ~FragmentJob();
|
---|
67 |
|
---|
68 | virtual FragmentResult::ptr Work() = 0;
|
---|
69 |
|
---|
70 | bool operator==(const FragmentJob &other) const;
|
---|
71 |
|
---|
72 | bool operator!=(const FragmentJob &other) const {
|
---|
73 | return !(*this == other);
|
---|
74 | }
|
---|
75 |
|
---|
76 | /** Less-than-operator required for priority queue.
|
---|
77 | *
|
---|
78 | * \param other other instance to compare to
|
---|
79 | * \return true - this instance is less than other (in priority)
|
---|
80 | */
|
---|
81 | bool operator<(const FragmentJob &other) const {
|
---|
82 | return priority < other.priority;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /** Setter for the job's priority.
|
---|
86 | *
|
---|
87 | * \param _priority priority to set
|
---|
88 | */
|
---|
89 | void setPriority(const priority_t _priority) {
|
---|
90 | priority = _priority;
|
---|
91 | }
|
---|
92 |
|
---|
93 | protected:
|
---|
94 | /** Passing JobId::setId() on to grant FragmentController' access.
|
---|
95 | *
|
---|
96 | * \param _id new id to set
|
---|
97 | */
|
---|
98 | void setId(const JobId_t _id) { JobId::setId(_id); }
|
---|
99 |
|
---|
100 | private:
|
---|
101 | /** private default cstor for serialization only
|
---|
102 | *
|
---|
103 | * Use normal cstor with JobId::IllegalJob if you want to instantiate
|
---|
104 | * a job without id.
|
---|
105 | */
|
---|
106 | FragmentJob();
|
---|
107 |
|
---|
108 | friend class boost::serialization::access;
|
---|
109 | // serialization
|
---|
110 | template <typename Archive>
|
---|
111 | void serialize(Archive& ar, const unsigned int version)
|
---|
112 | {
|
---|
113 | ar & boost::serialization::base_object<JobId>(*this);
|
---|
114 | ar & priority;
|
---|
115 | }
|
---|
116 | };
|
---|
117 |
|
---|
118 | /** Helper function for allow less on ptr's of FragmentJob.
|
---|
119 | *
|
---|
120 | * \param a first instance
|
---|
121 | * \param b second instance
|
---|
122 | * \return \see FragmentJob::operator<()
|
---|
123 | */
|
---|
124 | inline
|
---|
125 | bool operator<(const FragmentJob::ptr &a, const FragmentJob::ptr &b)
|
---|
126 | { return (*a) < (*b); }
|
---|
127 |
|
---|
128 |
|
---|
129 | #endif /* FRAGMENTJOB_HPP_ */
|
---|