You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.8 KiB

5 years ago
  1. %% beam cache 模块名
  2. -define(agBeamPool, agBeamPool).
  3. -define(agBeamAgency, agBeamAgency).
  4. %% 默认值定义
  5. -define(DEFAULT_BACKLOG_SIZE, 1024).
  6. -define(DEFAULT_INIT_OPTS, undefined).
  7. -define(DEFAULT_CONNECT_TIMEOUT, 500).
  8. -define(DEFAULT_PORT, 80).
  9. -define(DEFAULT_IP, <<"127.0.0.1">>).
  10. -define(DEFAULT_POOL_SIZE, 16).
  11. -define(DEFAULT_POOL_STRATEGY, random).
  12. -define(DEFAULT_POOL_OPTIONS, []).
  13. -define(DEFAULT_IS_RECONNECT, true).
  14. -define(DEFAULT_RECONNECT_MAX, 120000).
  15. -define(DEFAULT_RECONNECT_MIN, 500).
  16. -define(DEFAULT_SOCKET_OPTS, []).
  17. -define(DEFAULT_TIMEOUT, 1000).
  18. -define(DEFAULT_BODY, undefined).
  19. -define(DEFAULT_HEADERS, []).
  20. -define(DEFAULT_PID, self()).
  21. -define(DEFAULT_PROTOCOL, tcp).
  22. -define(GET_FROM_LIST(Key, List), case lists:keyfind(Key, 1, List) of false -> undefined; {_, Value} -> Value end).
  23. -define(GET_FROM_LIST(Key, List, Default), case lists:keyfind(Key, 1, List) of false -> Default; {_, Value} -> Value end).
  24. -define(WARN(PoolName, Format, Data), agMiscUtils:warnMsg(PoolName, Format, Data)).
  25. -record(dbUrl, {
  26. host :: host(),
  27. path :: path(),
  28. port :: 0..65535,
  29. hostname :: hostname(),
  30. protocol :: httpType()
  31. }).
  32. -record(requestRet, {
  33. state :: body | done,
  34. body :: undefined | binary(),
  35. content_length :: undefined | non_neg_integer() | chunked,
  36. headers :: undefined | [binary()],
  37. reason :: undefined | binary(),
  38. status_code :: undefined | 100..505
  39. }).
  40. -record(request, {
  41. requestId :: requestId(),
  42. pid :: pid() | undefined,
  43. timeout :: timeout(),
  44. timestamp :: erlang:timestamp()
  45. }).
  46. -record(poolOpts, {
  47. poolSize :: poolSize(),
  48. backlogSize :: backlogSize(),
  49. poolStrategy :: poolStrategy()
  50. }).
  51. -record(reconnectState, {
  52. min :: time(),
  53. max :: time() | infinity,
  54. current :: time() | undefined
  55. }).
  56. -type requestRet() :: #requestRet {}.
  57. -type dbUrl() :: #dbUrl {}.
  58. -type error() :: {error, term()}.
  59. -type headers() :: [{iodata(), iodata()}, ...].
  60. -type host() :: binary().
  61. -type hostname() :: binary().
  62. -type path() :: binary().
  63. -type method() :: binary().
  64. -type httpType() :: http | https.
  65. -type body() :: iodata() | undefined.
  66. -type options() :: [option(), ...].
  67. -type option() ::
  68. {backlogSize, pos_integer()} |
  69. {poolSize, pos_integer()} |
  70. {poolStrategy, random | round_robin} |
  71. {reconnect, boolean()} |
  72. {reconnectTimeMin, pos_integer()} |
  73. {reconnectTimeMax, pos_integer() | infinity}.
  74. -type buoy_opts() ::
  75. #{
  76. headers => headers(),
  77. body => body(),
  78. pid => pid(),
  79. timeout => non_neg_integer()
  80. }.
  81. -type backlogSize() :: pos_integer() | infinity.
  82. -type request() :: #request{}.
  83. -type clientOpt() ::
  84. {initOpts, term()} |
  85. {ip, inet:ip_address() | inet:hostname()} |
  86. {port, inet:port_number()} |
  87. {protocol, protocol()} |
  88. {reconnect, boolean()} |
  89. {reconnectTimeMin, time()} |
  90. {reconnectTimeMax, time() | infinity} |
  91. {socketOpts, [gen_tcp:connect_option(), ...]}.
  92. -type clientOpts() :: [clientOpt(), ...].
  93. -type clientState() :: term().
  94. -type externalRequestId() :: term().
  95. -type poolName() :: atom().
  96. -type poolOpt() ::
  97. {poolSize, pool_size()} |
  98. {backlogSize, backlog_size()} |
  99. {poolstrategy, poolStrategy()}.
  100. -type poolOpts() :: [poolOpt()].
  101. -type poolOptsRec() :: #poolOpts{}.
  102. -type poolSize() :: pos_integer().
  103. -type poolStrategy() :: random | round_robin.
  104. -type protocol() :: ssl | tcp.
  105. -type reconnectState() :: #reconnectState{}.
  106. -type requestId() :: {server_name(), reference()}.
  107. -type response() :: {external_request_id(), term()}.
  108. -type server_name() :: atom().
  109. -type socket() :: inet:socket() | ssl:sslsocket().
  110. -type socketType() :: inet | ssl.
  111. -type time() :: pos_integer().