1 | /*
|
---|
2 | * FragmentController.hpp
|
---|
3 | *
|
---|
4 | * Created on: Nov 27, 2011
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef FRAGMENTCONTROLLER_HPP_
|
---|
9 | #define FRAGMENTCONTROLLER_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include <boost/asio.hpp>
|
---|
17 | #include <string>
|
---|
18 | #include <vector>
|
---|
19 |
|
---|
20 | #include "JobMarket/Connection.hpp"
|
---|
21 | #include "JobMarket/ExitflagContainer.hpp"
|
---|
22 | #include "JobMarket/JobId.hpp"
|
---|
23 | #include "JobMarket/Jobs/FragmentJob.hpp"
|
---|
24 | #include "JobMarket/Results/FragmentResult.hpp"
|
---|
25 |
|
---|
26 | #include "JobMarket/Operations/OperationRegistry.hpp"
|
---|
27 |
|
---|
28 | class FragmentController_JobIdProxy;
|
---|
29 |
|
---|
30 | /** The FragmentController sends bunches of jobs to a FragmentScheduler,
|
---|
31 | * waits for their calculation and is called when they are done. Then,
|
---|
32 | * he loads the bunch of results from the Scheduler.
|
---|
33 | *
|
---|
34 | * While the FragmentScheduler and FragmentWorker rather act on their own
|
---|
35 | * this is the piece to implant into the user software to allow for
|
---|
36 | * communication with the Server/Worker duo to perform the calculation
|
---|
37 | * of the fragments on distant computers.
|
---|
38 | */
|
---|
39 | class FragmentController : public ExitflagContainer
|
---|
40 | {
|
---|
41 | public:
|
---|
42 | FragmentController(boost::asio::io_service& io_service);
|
---|
43 | ~FragmentController();
|
---|
44 |
|
---|
45 | void requestIds(const std::string &host, const std::string &service, const size_t NumberIds);
|
---|
46 | JobId_t getAvailableId();
|
---|
47 | void addJobs(std::vector<FragmentJob::ptr> &jobs);
|
---|
48 | void sendJobs(const std::string &host, const std::string &service);
|
---|
49 | void checkResults(const std::string &host, const std::string &service);
|
---|
50 | std::pair<size_t, size_t> getJobStatus() const;
|
---|
51 | void removeWaitingResults(const std::string &host, const std::string &service);
|
---|
52 | void removeWaitingJobs(const std::string &host, const std::string &service);
|
---|
53 | void removeall(const std::string &host, const std::string &service);
|
---|
54 | void receiveResults(const std::string &host, const std::string &service);
|
---|
55 | std::vector<FragmentResult::ptr> getReceivedResults();
|
---|
56 | void shutdown(const std::string &host, const std::string &service);
|
---|
57 |
|
---|
58 | protected:
|
---|
59 | void changeJobId(FragmentJob::ptr &job, const JobId_t _newid) const;
|
---|
60 |
|
---|
61 | protected:
|
---|
62 | /// The Connection to the server.
|
---|
63 | Connection connection_;
|
---|
64 |
|
---|
65 | public:
|
---|
66 | //!> registry with all operations of this controller
|
---|
67 | OperationRegistry Commands;
|
---|
68 |
|
---|
69 | private:
|
---|
70 | //!> internally bound function that sets the Exitflag to ErrorFlag
|
---|
71 | boost::function<void ()> failed;
|
---|
72 |
|
---|
73 | private:
|
---|
74 | //!> grant this specifically made proxy access to jobids
|
---|
75 | friend class FragmentController_JobIdProxy;
|
---|
76 |
|
---|
77 | //!> list of all job ids that the server currently has
|
---|
78 | std::set<JobId_t> jobids;
|
---|
79 | };
|
---|
80 |
|
---|
81 | #endif /* FRAGMENTCONTROLLER_HPP_ */
|
---|