alaCarte Maps
Renderer for OpenStreetMap tiles
request_manager.hpp
Go to the documentation of this file.
1 
21 #ifndef REQUEST_MANAGER_HPP
22 #define REQUEST_MANAGER_HPP
23 
24 
25 #include <chrono>
26 #include <boost/asio.hpp>
27 #include <boost/thread/thread.hpp>
28 
29 #include "server/job.hpp"
30 
31 #include "settings.hpp"
32 
33 class Configuration;
34 class Cache;
35 class Renderer;
36 class Geodata;
37 class StylesheetManager;
38 class HttpRequest;
39 class TileIdentifier;
41 
42 class RequestManager : public boost::enable_shared_from_this<RequestManager>
43 {
44 public:
45  RequestManager( const shared_ptr<Configuration>& config, const shared_ptr<Geodata>& data, const shared_ptr<Renderer>& renderer, const shared_ptr<Cache>& cache, const shared_ptr<StylesheetManager>& ssm);
47 
48  void stop();
49 
50  TESTABLE void enqueue(const shared_ptr<HttpRequest>& r);
51  TESTABLE void enqueue(const shared_ptr<MetaIdentifier>& ti);
52  TESTABLE shared_ptr<Geodata> getGeodata() const;
53  TESTABLE shared_ptr<StylesheetManager> getStylesheetManager() const;
54  TESTABLE shared_ptr<Cache> getCache() const;
55  TESTABLE shared_ptr<Renderer> getRenderer() const;
56 
57 private:
58  void processNextRequest();
59  bool nextUserRequest();
60  bool nextPreRenderRequest();
61 
62 private:
63  shared_ptr<Geodata> data;
64  shared_ptr<Renderer> renderer;
65  shared_ptr<Cache> cache;
66  shared_ptr<StylesheetManager> ssm;
67  shared_ptr<Configuration> config;
68 
69  boost::asio::io_service jobPool;
70  boost::asio::io_service::work preventStop;
71  std::vector< shared_ptr<boost::thread> > workers;
72 
73  std::queue<shared_ptr<RenderCanvasFactory>> factories;
74  boost::mutex factoriesMutex;
75 
76  boost::mutex userRJMutex;
77  boost::mutex preRJMutex;
78  std::queue< shared_ptr<HttpRequest> > userRequests;
79  std::queue< shared_ptr<MetaIdentifier> > preRenderRequests;
80 
82  class RunningQueue;
83  scoped_ptr<RunningQueue> running;
84 
86 
87  std::chrono::system_clock::time_point prerender_start, prerender_stop;
88 };
89 
90 
91 #endif
shared_ptr< Geodata > data
TESTABLE shared_ptr< StylesheetManager > getStylesheetManager() const
Returns the StylesheetManager.
std::vector< shared_ptr< boost::thread > > workers
bool nextUserRequest()
Selects the next Job and runs it process Method.
boost::mutex factoriesMutex
void stop()
stops all jobs
The StylesheetManager provides an interface to get arbitrary Stylesheets from the stylesheet director...
void processNextRequest()
Selects the next Job and runs it process Method.
std::queue< shared_ptr< HttpRequest > > userRequests
TESTABLE void enqueue(const shared_ptr< HttpRequest > &r)
Enqueues the HttpRequest.
This file is part of alaCarte.
A TileIdentifier identifies a Tile.
std::queue< shared_ptr< RenderCanvasFactory > > factories
std::chrono::system_clock::time_point prerender_stop
RequestManager(const shared_ptr< Configuration > &config, const shared_ptr< Geodata > &data, const shared_ptr< Renderer > &renderer, const shared_ptr< Cache > &cache, const shared_ptr< StylesheetManager > &ssm)
Constructs a new RequestManager with the given parameters.
boost::mutex preRJMutex
shared_ptr< Cache > cache
TESTABLE shared_ptr< Geodata > getGeodata() const
Returns the Geodata.
shared_ptr< Configuration > config
std::queue< shared_ptr< MetaIdentifier > > preRenderRequests
shared_ptr< Renderer > renderer
boost::asio::io_service::work preventStop
TESTABLE shared_ptr< Renderer > getRenderer() const
Returns the Renderer.
TESTABLE shared_ptr< Cache > getCache() const
Returns the Cache.
Represents a set of options accessible via strings.
boost::asio::io_service jobPool
std::chrono::system_clock::time_point prerender_start
#define TESTABLE
Definition: settings.hpp:85
shared_ptr< StylesheetManager > ssm
~RequestManager()
Stops the io_service, joins all Threads and destructs the RequestManager.
scoped_ptr< RunningQueue > running
unsigned int currentPrerenderingThreads
boost::mutex userRJMutex
Definition: cache.hpp:38