Global.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /**
  2. * Tencent is pleased to support the open source community by making Tars available.
  3. *
  4. * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
  5. *
  6. * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  7. * in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * https://opensource.org/licenses/BSD-3-Clause
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. */
  16. #ifndef __TARS_GLOBAL_H_
  17. #define __TARS_GLOBAL_H_
  18. #include <inttypes.h>
  19. #include <iostream>
  20. #include <sstream>
  21. #include <map>
  22. #include <list>
  23. #include <deque>
  24. #include <vector>
  25. #include <memory>
  26. #include "util/tc_platform.h"
  27. #include "util/tc_clientsocket.h"
  28. #include "util/tc_autoptr.h"
  29. #include "util/tc_common.h"
  30. #include "util/tc_logger.h"
  31. #include "util/tc_thread_mutex.h"
  32. #include "tup/RequestF.h"
  33. #include "servant/BaseF.h"
  34. using namespace std;
  35. namespace tars
  36. {
  37. //////////////////////////////////////////////////////////////
  38. const size_t MAX_CLIENT_THREAD_NUM = 64; //客户端最大网络线程数
  39. const size_t MAX_CLIENT_ASYNCTHREAD_NUM = 1024; //客户端每个网络线程拥有的最大异步线程数
  40. const size_t MAX_CLIENT_NOTIFYEVENT_NUM = 2048; //客户端每个网络线程拥有的最大通知事件的数目
  41. //////////////////////////////////////////////////////////////
  42. class Communicator;
  43. class AdapterProxy;
  44. class ServantProxy;
  45. class ServantProxyCallback;
  46. class ObjectProxy;
  47. class Current;
  48. class FDReactor;
  49. class Transceiver;
  50. class StatFProxy;
  51. class StatReport;
  52. class ServantProxyFactory;
  53. class ObjectProxyFactory;
  54. class AsyncProcThread;
  55. class LocalRollLogger;
  56. class RemoteConfig;
  57. class RemoteTimeLogger;
  58. class RemoteNotify;
  59. typedef TC_AutoPtr<Communicator> CommunicatorPtr;
  60. typedef TC_AutoPtr<ServantProxy> ServantPrx;
  61. typedef TC_AutoPtr<ServantProxyCallback> ServantProxyCallbackPtr;
  62. typedef TC_AutoPtr<ObjectProxy> ObjectPrx;
  63. typedef TC_AutoPtr<Current> CurrentPtr;
  64. typedef TC_AutoPtr<StatFProxy> StatFPrx;
  65. typedef TC_AutoPtr<StatReport> StatReportPtr;
  66. typedef TC_AutoPtr<FDReactor> FDReactorPtr;
  67. typedef TC_AutoPtr<AsyncProcThread> AsyncProcThreadPtr;
  68. typedef CurrentPtr TarsCurrentPtr;
  69. typedef RemoteConfig TarsRemoteConfig;
  70. typedef RemoteNotify TarsRemoteNotify;
  71. typedef LocalRollLogger TarsRollLogger;
  72. typedef RemoteTimeLogger TarsTimeLogger;
  73. //////////////////////////////////////////////////////////////
  74. /**
  75. * 定义TARS网络调用的异常基类
  76. */
  77. struct TarsException : public TC_Exception
  78. {
  79. TarsException(const string &buffer) : TC_Exception(buffer){};
  80. TarsException(const string &buffer, int err) : TC_Exception(buffer, err){};
  81. ~TarsException() throw(){};
  82. /**
  83. * 根据返回值抛出异常
  84. * @param ret
  85. * @param desc
  86. */
  87. static void throwException(int ret, const string& desc = "");
  88. };
  89. ////////////////////////////////////////////////////////////////
  90. // 定义网络异常
  91. /**
  92. * 建立连接异常
  93. */
  94. struct TarsNetConnectException : public TarsException
  95. {
  96. TarsNetConnectException(const string &buffer) : TarsException(buffer){};
  97. TarsNetConnectException(const string &buffer, int err) : TarsException(buffer, err){};
  98. ~TarsNetConnectException() throw(){};
  99. };
  100. /**
  101. * 链接丢失
  102. */
  103. struct TarsNetConnectLostException : public TarsException
  104. {
  105. TarsNetConnectLostException(const string &buffer) : TarsException(buffer){};
  106. TarsNetConnectLostException(const string &buffer, int err) : TarsException(buffer, err){};
  107. ~TarsNetConnectLostException() throw(){};
  108. };
  109. /**
  110. * Socket异常
  111. */
  112. struct TarsNetSocketException : public TarsException
  113. {
  114. TarsNetSocketException(const string &buffer) : TarsException(buffer){};
  115. TarsNetSocketException(const string &buffer, int err) : TarsException(buffer, err){};
  116. ~TarsNetSocketException() throw(){};
  117. };
  118. /**
  119. * Proxy解码异常
  120. */
  121. struct TarsProxyDecodeException : public TarsException
  122. {
  123. TarsProxyDecodeException(const string &buffer) : TarsException(buffer){};
  124. TarsProxyDecodeException(const string &buffer, int err) : TarsException(buffer, err){};
  125. ~TarsProxyDecodeException() throw(){};
  126. };
  127. /**
  128. * Proxy编码异常
  129. */
  130. struct TarsProxyEncodeException : public TarsException
  131. {
  132. TarsProxyEncodeException(const string &buffer) : TarsException(buffer){};
  133. TarsProxyEncodeException(const string &buffer, int err) : TarsException(buffer, err){};
  134. ~TarsProxyEncodeException() throw(){};
  135. };
  136. /**
  137. * Server编码异常
  138. */
  139. struct TarsServerEncodeException : public TarsException
  140. {
  141. TarsServerEncodeException(const string &buffer) : TarsException(buffer){};
  142. TarsServerEncodeException(const string &buffer, int err) : TarsException(buffer, err){};
  143. ~TarsServerEncodeException() throw(){};
  144. };
  145. /**
  146. * Server解码异常
  147. */
  148. struct TarsServerDecodeException : public TarsException
  149. {
  150. TarsServerDecodeException(const string &buffer) : TarsException(buffer){};
  151. TarsServerDecodeException(const string &buffer, int err) : TarsException(buffer, err){};
  152. ~TarsServerDecodeException() throw(){};
  153. };
  154. /**
  155. * Server无函数异常
  156. */
  157. struct TarsServerNoFuncException : public TarsException
  158. {
  159. TarsServerNoFuncException(const string &buffer) : TarsException(buffer){};
  160. TarsServerNoFuncException(const string &buffer, int err) : TarsException(buffer, err){};
  161. ~TarsServerNoFuncException() throw(){};
  162. };
  163. /**
  164. * Server无对象异常
  165. */
  166. struct TarsServerNoServantException : public TarsException
  167. {
  168. TarsServerNoServantException(const string &buffer) : TarsException(buffer){};
  169. TarsServerNoServantException(const string &buffer, int err) : TarsException(buffer, err){};
  170. ~TarsServerNoServantException() throw(){};
  171. };
  172. /**
  173. * 消息在服务端队列超时
  174. */
  175. struct TarsServerQueueTimeoutException : public TarsException
  176. {
  177. TarsServerQueueTimeoutException(const string &buffer) : TarsException(buffer){};
  178. TarsServerQueueTimeoutException(const string &buffer, int err) : TarsException(buffer, err){};
  179. ~TarsServerQueueTimeoutException() throw(){};
  180. };
  181. /**
  182. * 服务端返回的未知值
  183. */
  184. struct TarsServerUnknownException : public TarsException
  185. {
  186. TarsServerUnknownException(const string &buffer) : TarsException(buffer){};
  187. TarsServerUnknownException(const string &buffer, int err) : TarsException(buffer, err){};
  188. ~TarsServerUnknownException() throw(){};
  189. };
  190. /**
  191. * 同步调用超时异常
  192. */
  193. struct TarsSyncCallTimeoutException : public TarsException
  194. {
  195. TarsSyncCallTimeoutException (const string &buffer) : TarsException(buffer){};
  196. TarsSyncCallTimeoutException (const string &buffer, int err) : TarsException(buffer, err){};
  197. ~TarsSyncCallTimeoutException () throw(){};
  198. };
  199. /**
  200. * 访问 Registry 错误
  201. */
  202. struct TarsRegistryException : public TarsException
  203. {
  204. TarsRegistryException(const string &buffer) : TarsException(buffer){};
  205. TarsRegistryException(const string &buffer, int err) : TarsException(buffer, err){};
  206. ~TarsRegistryException() throw(){};
  207. };
  208. /**
  209. * 客户端队列满了
  210. */
  211. struct TarsClientQueueException : public TarsException
  212. {
  213. TarsClientQueueException(const string &buffer) : TarsException(buffer){};
  214. TarsClientQueueException(const string &buffer, int err) : TarsException(buffer, err){};
  215. ~TarsClientQueueException() throw(){};
  216. };
  217. /**
  218. * 业务线程调用协程并行请求接口时,抛出的异常
  219. */
  220. struct TarsUseCoroException : public TarsException
  221. {
  222. TarsUseCoroException(const string &buffer) : TarsException(buffer){};
  223. TarsUseCoroException(const string &buffer, int err) : TarsException(buffer, err){};
  224. ~TarsUseCoroException() throw(){};
  225. };
  226. ///////////////////////////////////////////////////////////////////
  227. }
  228. #endif