TeBkUmLpqAsync.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. Copyright 2009-2020, Sumeet Chhetri
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /*
  14. * TeBkUmLpqAsync.h
  15. *
  16. * Created on: 03-Feb-2020
  17. * Author: sumeetc
  18. */
  19. #ifndef WEB_TE_BENCHMARK_UM_INCLUDE_TeBkUmLpqAsync_H_
  20. #define WEB_TE_BENCHMARK_UM_INCLUDE_TeBkUmLpqAsync_H_
  21. #include "TemplateHandler.h"
  22. #include "vector"
  23. #ifndef OS_MINGW
  24. #include <netinet/in.h>
  25. #include <arpa/inet.h>
  26. #endif
  27. #include "DataSourceManager.h"
  28. #include <stdlib.h>
  29. #include <algorithm>
  30. #include "CryptoHandler.h"
  31. #include "vector"
  32. #include "CastUtil.h"
  33. #include "CacheManager.h"
  34. #include <stdlib.h>
  35. #include "HttpRequest.h"
  36. #include "HttpResponse.h"
  37. #include "JSONSerialize.h"
  38. #include "string"
  39. #include "yuarel.h"
  40. #include "Router.h"
  41. typedef void (*TeBkUmLpqAsyncTemplatePtr) (Context*, std::string&);
  42. class TeBkUmLpqAsyncWorld {
  43. int id;
  44. int randomNumber;
  45. public:
  46. TeBkUmLpqAsyncWorld();
  47. virtual ~TeBkUmLpqAsyncWorld();
  48. int getId() const;
  49. void setId(int id);
  50. int getRandomNumber() const;
  51. void setRandomNumber(int randomNumber);
  52. };
  53. class TeBkUmLpqAsyncFortune {
  54. int id;
  55. std::string message;
  56. public:
  57. TeBkUmLpqAsyncFortune();
  58. virtual ~TeBkUmLpqAsyncFortune();
  59. int getId() const;
  60. void setId(int id);
  61. const std::string& getMessage() const;
  62. void setMessage(const std::string& message);
  63. bool operator < (const TeBkUmLpqAsyncFortune& other) const;
  64. };
  65. class TeBkUmLpqAsyncMessage {
  66. std::string message;
  67. public:
  68. virtual ~TeBkUmLpqAsyncMessage();
  69. const std::string& getMessage() const;
  70. void setMessage(const std::string& message);
  71. };
  72. struct AsyncReq {
  73. HttpResponse r;
  74. SocketInterface* sif;
  75. void* d;
  76. void* ddlib;
  77. LibpqDataSourceImpl* sqli;
  78. };
  79. struct CacheReq {
  80. void* d;
  81. CacheInterface* cchi;
  82. };
  83. class TeBkUmLpqAsyncRouter : public Router {
  84. static const std::string HELLO_WORLD;
  85. static std::string WORLD;
  86. static std::string WORLD_ONE_QUERY;
  87. static std::string WORLD_ALL_QUERY;
  88. static std::string FORTUNE_ALL_QUERY;
  89. static std::string APP_NAME;
  90. static std::string TPE_FN_NAME;
  91. static bool strToNum(const char* str, int len, int& ret);
  92. void dbAsync(AsyncReq* req);
  93. static void dbAsyncUtil(void* ctx, int rn, int cn, char * d);
  94. static void dbAsyncCh(void* ctx, bool status, const std::string& q, int counter);
  95. void queriesAsync(const char* q, int ql, AsyncReq* req);
  96. static void queriesAsyncUtil(void* ctx, int rn, int cn, char * d);
  97. static void queriesAsyncCh(void* ctx, bool status, const std::string& q, int counter);
  98. #ifndef HAVE_LIBPQ_BATCH
  99. void queriesMultiAsync(const char*, int, AsyncReq*);
  100. static void queriesMultiAsyncUtil(void* ctx, int, int, char *, int);
  101. static void queriesMultiAsyncCh(void* ctx, bool status, const std::string& q, int counter);
  102. #endif
  103. void updatesAsync(const char* q, int ql, AsyncReq* req);
  104. static void updatesAsyncChQ(void* ctx, bool status, const std::string& q, int counter);
  105. static void updatesAsyncChU(void* ctx, bool status, const std::string& q, int counter);
  106. static std::string& getUpdQuery(int count);
  107. void updatesAsyncb(const char* q, int ql, AsyncReq* req);
  108. static void updatesAsyncbChQ(void* ctx, bool status, const std::string& q, int counter);
  109. static void updatesAsyncbChU(void* ctx, bool status, const std::string& q, int counter);
  110. void cachedWorlds(const char*, int, std::vector<TeBkUmLpqAsyncWorld>&);
  111. static void updateCacheAsyncUtil(void* ctx, int rn, std::vector<LibpqRes>& data);
  112. static void updateCacheAsyncCh(void* ctx, bool status, const std::string& q, int counter);
  113. void getContextAsync(AsyncReq* req);
  114. static void getContextAsyncUtil(void* ctx, int rn, int cn, char * d, int l);
  115. static void getContextAsyncCh(void* ctx, bool status, const std::string& q, int counter);
  116. static std::map<int, std::string> _qC;
  117. LibpqDataSourceImpl* sqli;
  118. LibpqDataSourceImpl* getDb();
  119. //static Logger logger;
  120. public:
  121. TeBkUmLpqAsyncRouter& operator=(const TeBkUmLpqAsyncRouter& a) {
  122. return *this;
  123. }
  124. TeBkUmLpqAsyncRouter(const TeBkUmLpqAsyncRouter& a) {
  125. sqli = NULL;
  126. }
  127. TeBkUmLpqAsyncRouter();
  128. virtual ~TeBkUmLpqAsyncRouter();
  129. void updateCache();
  130. bool route(HttpRequest* req, HttpResponse* res, void* dlib, void* ddlib, SocketInterface* sif);
  131. };
  132. #endif /* WEB_TE_BENCHMARK_UM_INCLUDE_TeBkUmLpqAsync_H_ */