CernVM-FS  2.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
reactor.h
Go to the documentation of this file.
1 
5 #ifndef CVMFS_RECEIVER_REACTOR_H_
6 #define CVMFS_RECEIVER_REACTOR_H_
7 
8 #include <cstdlib>
9 #include <map>
10 #include <string>
11 
12 #include "json_document.h"
13 #include "statistics.h"
14 
15 namespace receiver {
16 
17 class CommitProcessor;
18 class PayloadProcessor;
19 
28 class Reactor {
29  public:
30  enum Request {
31  kQuit = 0,
39  kTestCrash // use to test the gateway
40  };
41 
42  static Request ReadRequest(int fd, std::string* data);
43  static bool WriteRequest(int fd, Request req, const std::string& data);
44 
45  static bool ReadReply(int fd, std::string* data);
46  static bool WriteReply(int fd, const std::string& data);
47 
48  static bool ExtractStatsFromReq(JsonDocument *req,
49  perf::Statistics *stats,
50  std::string *start_time);
51 
52  Reactor(int fdin, int fdout);
53  virtual ~Reactor();
54 
55  bool Run();
56 
57  protected:
58  // NOTE: These methods are virtual such that they can be mocked for the
59  // purpose of unit testing
60  virtual bool HandleGenerateToken(const std::string& req, std::string* reply);
61  virtual bool HandleGetTokenId(const std::string& req, std::string* reply);
62  virtual bool HandleCheckToken(const std::string& req, std::string* reply);
63  virtual bool HandleSubmitPayload(int fdin, const std::string& req,
64  std::string* reply);
65  virtual bool HandleCommit(const std::string& req, std::string* reply);
66 
69 
70  private:
71  bool HandleRequest(Request req, const std::string& data);
72 
73  int fdin_;
74  int fdout_;
75 
76  std::map<std::string, perf::Statistics*> statistics_map_;
77 };
78 
79 } // namespace receiver
80 
81 #endif // CVMFS_RECEIVER_REACTOR_H_
virtual bool HandleCommit(const std::string &req, std::string *reply)
Definition: reactor.cc:389
virtual CommitProcessor * MakeCommitProcessor()
Definition: reactor.cc:479
virtual bool HandleCheckToken(const std::string &req, std::string *reply)
Definition: reactor.cc:262
bool HandleRequest(Request req, const std::string &data)
Definition: reactor.cc:483
virtual bool HandleGetTokenId(const std::string &req, std::string *reply)
Definition: reactor.cc:242
static bool ReadReply(int fd, std::string *data)
Definition: reactor.cc:87
virtual ~Reactor()
Definition: reactor.cc:178
virtual bool HandleGenerateToken(const std::string &req, std::string *reply)
Definition: reactor.cc:196
static bool ExtractStatsFromReq(JsonDocument *req, perf::Statistics *stats, std::string *start_time)
Definition: reactor.cc:122
static Request ReadRequest(int fd, std::string *data)
Definition: reactor.cc:37
static bool WriteReply(int fd, const std::string &data)
Definition: reactor.cc:107
virtual PayloadProcessor * MakePayloadProcessor()
Definition: reactor.cc:475
virtual bool HandleSubmitPayload(int fdin, const std::string &req, std::string *reply)
Definition: reactor.cc:319
static bool WriteRequest(int fd, Request req, const std::string &data)
Definition: reactor.cc:71
Reactor(int fdin, int fdout)
Definition: reactor.cc:176
std::map< std::string, perf::Statistics * > statistics_map_
Definition: reactor.h:76