neo4j-ruby-driver 1.7.6 → 4.4.0.alpha.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (339) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -43
  3. data/lib/loader.rb +5 -3
  4. data/lib/neo4j/driver/auto_closable.rb +2 -2
  5. data/lib/neo4j/driver/exceptions/authentication_exception.rb +6 -1
  6. data/lib/neo4j/driver/exceptions/authorization_expired_exception.rb +14 -0
  7. data/lib/neo4j/driver/{types/bytes.rb → exceptions/certificate_exception.rb} +2 -2
  8. data/lib/neo4j/driver/exceptions/client_exception.rb +3 -0
  9. data/lib/neo4j/driver/exceptions/connection_read_timeout_exception.rb +14 -0
  10. data/lib/neo4j/driver/exceptions/database_exception.rb +3 -0
  11. data/lib/neo4j/driver/exceptions/discovery_exception.rb +16 -0
  12. data/lib/neo4j/driver/exceptions/fatal_discovery_exception.rb +13 -0
  13. data/lib/neo4j/driver/exceptions/protocol_exception.rb +7 -0
  14. data/lib/neo4j/driver/exceptions/result_consumed_exception.rb +13 -0
  15. data/lib/neo4j/driver/exceptions/security_exception.rb +5 -1
  16. data/lib/neo4j/driver/exceptions/service_unavailable_exception.rb +2 -0
  17. data/lib/neo4j/driver/exceptions/session_expired_exception.rb +4 -0
  18. data/lib/neo4j/driver/exceptions/token_expired_exception.rb +15 -0
  19. data/lib/neo4j/driver/exceptions/transaction_nesting_exception.rb +11 -0
  20. data/lib/neo4j/driver/exceptions/transient_exception.rb +3 -0
  21. data/lib/neo4j/driver/exceptions/untrusted_server_exception.rb +1 -0
  22. data/lib/neo4j/driver/exceptions/value/lossy_coercion.rb +15 -0
  23. data/lib/neo4j/driver/exceptions/value/not_multi_valued.rb +13 -0
  24. data/lib/neo4j/driver/exceptions/value/uncoercible.rb +15 -0
  25. data/lib/neo4j/driver/exceptions/value/unsizable.rb +12 -0
  26. data/lib/neo4j/driver/exceptions/value/value_exception.rb +12 -0
  27. data/lib/neo4j/driver/internal/bolt_server_address.rb +97 -0
  28. data/lib/neo4j/driver/internal/duration_normalizer.rb +1 -1
  29. data/lib/neo4j/driver/internal/validator.rb +5 -4
  30. data/{ffi/neo4j/driver/summary/statement_type.rb → lib/neo4j/driver/summary/query_type.rb} +1 -3
  31. data/lib/neo4j/driver/synchronizable.rb +23 -0
  32. data/lib/neo4j_ruby_driver.rb +5 -11
  33. data/{ffi → ruby}/neo4j/driver/access_mode.rb +2 -2
  34. data/ruby/neo4j/driver/auth_tokens.rb +34 -0
  35. data/ruby/neo4j/driver/bookmark.rb +21 -0
  36. data/ruby/neo4j/driver/config.rb +89 -0
  37. data/ruby/neo4j/driver/graph_database.rb +80 -0
  38. data/ruby/neo4j/driver/internal/async/connection/bolt_protocol_util.rb +51 -0
  39. data/ruby/neo4j/driver/internal/async/connection/bootstrap_factory.rb +22 -0
  40. data/ruby/neo4j/driver/internal/async/connection/channel_attributes.rb +31 -0
  41. data/ruby/neo4j/driver/internal/async/connection/channel_connected_listener.rb +32 -0
  42. data/ruby/neo4j/driver/internal/async/connection/channel_connector_impl.rb +83 -0
  43. data/ruby/neo4j/driver/internal/async/connection/channel_pipeline_builder_impl.rb +22 -0
  44. data/ruby/neo4j/driver/internal/async/connection/direct_connection.rb +30 -0
  45. data/ruby/neo4j/driver/internal/async/connection/event_loop_group_factory.rb +83 -0
  46. data/ruby/neo4j/driver/internal/async/connection/handshake_completed_listener.rb +27 -0
  47. data/ruby/neo4j/driver/internal/async/connection/handshake_handler.rb +113 -0
  48. data/ruby/neo4j/driver/internal/async/connection/netty_channel_initializer.rb +57 -0
  49. data/ruby/neo4j/driver/internal/async/connection/netty_domain_name_resolver.rb +26 -0
  50. data/ruby/neo4j/driver/internal/async/connection/netty_domain_name_resolver_group.rb +19 -0
  51. data/ruby/neo4j/driver/internal/async/connection/routing_connection.rb +36 -0
  52. data/ruby/neo4j/driver/internal/async/connection/stream.rb +12 -0
  53. data/ruby/neo4j/driver/internal/async/connection/stream_reader.rb +16 -0
  54. data/ruby/neo4j/driver/internal/async/connection_context.rb +10 -0
  55. data/ruby/neo4j/driver/internal/async/immutable_connection_context.rb +24 -0
  56. data/ruby/neo4j/driver/internal/async/inbound/byte_buf_input.rb +30 -0
  57. data/ruby/neo4j/driver/internal/async/inbound/channel_error_handler.rb +77 -0
  58. data/ruby/neo4j/driver/internal/async/inbound/chunk_decoder.rb +41 -0
  59. data/ruby/neo4j/driver/internal/async/inbound/connect_timeout_handler.rb +32 -0
  60. data/ruby/neo4j/driver/internal/async/inbound/connection_read_timeout_handler.rb +17 -0
  61. data/ruby/neo4j/driver/internal/async/inbound/inbound_message_dispatcher.rb +172 -0
  62. data/ruby/neo4j/driver/internal/async/inbound/inbound_message_handler.rb +42 -0
  63. data/ruby/neo4j/driver/internal/async/inbound/message_decoder.rb +51 -0
  64. data/ruby/neo4j/driver/internal/async/internal_async_session.rb +98 -0
  65. data/ruby/neo4j/driver/internal/async/internal_async_transaction.rb +13 -0
  66. data/ruby/neo4j/driver/internal/async/leak_logging_network_session.rb +34 -0
  67. data/ruby/neo4j/driver/internal/async/network_connection.rb +196 -0
  68. data/ruby/neo4j/driver/internal/async/network_session.rb +152 -0
  69. data/ruby/neo4j/driver/internal/async/outbound/chunk_aware_byte_buf_output.rb +110 -0
  70. data/ruby/neo4j/driver/internal/async/outbound/outbound_message_handler.rb +39 -0
  71. data/ruby/neo4j/driver/internal/async/pool/channel.rb +63 -0
  72. data/ruby/neo4j/driver/internal/async/pool/connection_pool_impl.rb +149 -0
  73. data/ruby/neo4j/driver/internal/async/pool/controller.rb +25 -0
  74. data/ruby/neo4j/driver/internal/async/pool/netty_channel_health_checker.rb +87 -0
  75. data/ruby/neo4j/driver/internal/async/pool/netty_channel_pool.rb +52 -0
  76. data/ruby/neo4j/driver/internal/async/pool/netty_channel_tracker.rb +137 -0
  77. data/ruby/neo4j/driver/internal/async/pool/network_connection_factory.rb +21 -0
  78. data/ruby/neo4j/driver/internal/async/pool/pool_settings.rb +34 -0
  79. data/ruby/neo4j/driver/internal/async/result_cursors_holder.rb +17 -0
  80. data/ruby/neo4j/driver/internal/async/unmanaged_transaction.rb +214 -0
  81. data/ruby/neo4j/driver/internal/bookmark_holder.rb +9 -0
  82. data/ruby/neo4j/driver/internal/cluster/cluster_composition.rb +58 -0
  83. data/ruby/neo4j/driver/internal/cluster/cluster_composition_lookup_result.rb +14 -0
  84. data/ruby/neo4j/driver/internal/cluster/cluster_routing_table.rb +139 -0
  85. data/ruby/neo4j/driver/internal/cluster/identity_resolver.rb +13 -0
  86. data/ruby/neo4j/driver/internal/cluster/loadbalancing/least_connected_load_balancing_strategy.rb +68 -0
  87. data/ruby/neo4j/driver/internal/cluster/loadbalancing/load_balancer.rb +159 -0
  88. data/ruby/neo4j/driver/internal/cluster/loadbalancing/round_robin_array_index.rb +13 -0
  89. data/ruby/neo4j/driver/internal/cluster/multi_databases_routing_procedure_runner.rb +34 -0
  90. data/ruby/neo4j/driver/internal/cluster/rediscovery_impl.rb +238 -0
  91. data/ruby/neo4j/driver/internal/cluster/route_message_routing_procedure_runner.rb +43 -0
  92. data/ruby/neo4j/driver/internal/cluster/routing_context.rb +77 -0
  93. data/ruby/neo4j/driver/internal/cluster/routing_procedure_cluster_composition_provider.rb +64 -0
  94. data/ruby/neo4j/driver/internal/cluster/routing_procedure_response.rb +19 -0
  95. data/ruby/neo4j/driver/internal/cluster/routing_settings.rb +24 -0
  96. data/ruby/neo4j/driver/internal/cluster/routing_table_handler_impl.rb +116 -0
  97. data/ruby/neo4j/driver/internal/cluster/routing_table_registry_impl.rb +140 -0
  98. data/ruby/neo4j/driver/internal/cluster/single_database_routing_procedure_runner.rb +76 -0
  99. data/ruby/neo4j/driver/internal/connection_settings.rb +16 -0
  100. data/ruby/neo4j/driver/internal/cursor/async_result_cursor_impl.rb +68 -0
  101. data/ruby/neo4j/driver/internal/cursor/async_result_cursor_only_factory.rb +28 -0
  102. data/ruby/neo4j/driver/internal/cursor/disposable_async_result_cursor.rb +59 -0
  103. data/ruby/neo4j/driver/internal/cursor/result_cursor_factory_impl.rb +29 -0
  104. data/ruby/neo4j/driver/internal/cursor/rx_result_cursor_impl.rb +110 -0
  105. data/ruby/neo4j/driver/internal/database_name.rb +12 -0
  106. data/ruby/neo4j/driver/internal/database_name_util.rb +37 -0
  107. data/ruby/neo4j/driver/internal/default_bookmark_holder.rb +15 -0
  108. data/ruby/neo4j/driver/internal/default_domain_name_resolver.rb +11 -0
  109. data/ruby/neo4j/driver/internal/direct_connection_provider.rb +40 -0
  110. data/ruby/neo4j/driver/internal/driver_factory.rb +126 -0
  111. data/ruby/neo4j/driver/internal/handlers/begin_tx_response_handler.rb +20 -0
  112. data/ruby/neo4j/driver/internal/handlers/channel_releasing_reset_response_handler.rb +29 -0
  113. data/ruby/neo4j/driver/internal/handlers/commit_tx_response_handler.rb +25 -0
  114. data/ruby/neo4j/driver/internal/handlers/hello_response_handler.rb +65 -0
  115. data/ruby/neo4j/driver/internal/handlers/init_response_handler.rb +34 -0
  116. data/ruby/neo4j/driver/internal/handlers/legacy_pull_all_response_handler.rb +228 -0
  117. data/ruby/neo4j/driver/internal/handlers/no_op_response_handler.rb +16 -0
  118. data/ruby/neo4j/driver/internal/handlers/ping_response_handler.rb +29 -0
  119. data/ruby/neo4j/driver/internal/handlers/pull_handlers.rb +32 -0
  120. data/ruby/neo4j/driver/internal/handlers/pulln/auto_pull_response_handler.rb +178 -0
  121. data/ruby/neo4j/driver/internal/handlers/pulln/basic_pull_response_handler.rb +288 -0
  122. data/ruby/neo4j/driver/internal/handlers/pulln/fetch_size_util.rb +20 -0
  123. data/ruby/neo4j/driver/internal/handlers/reset_response_handler.rb +34 -0
  124. data/ruby/neo4j/driver/internal/handlers/rollback_tx_response_handler.rb +19 -0
  125. data/ruby/neo4j/driver/internal/handlers/route_message_response_handler.rb +21 -0
  126. data/ruby/neo4j/driver/internal/handlers/routing_response_handler.rb +70 -0
  127. data/ruby/neo4j/driver/internal/handlers/run_response_handler.rb +38 -0
  128. data/ruby/neo4j/driver/internal/handlers/session_pull_response_completion_listener.rb +34 -0
  129. data/ruby/neo4j/driver/internal/handlers/transaction_pull_response_completion_listener.rb +20 -0
  130. data/ruby/neo4j/driver/internal/impersonation_util.rb +22 -0
  131. data/ruby/neo4j/driver/internal/internal_bookmark.rb +38 -0
  132. data/ruby/neo4j/driver/internal/internal_database_name.rb +11 -0
  133. data/ruby/neo4j/driver/internal/internal_driver.rb +78 -0
  134. data/ruby/neo4j/driver/internal/internal_entity.rb +22 -0
  135. data/ruby/neo4j/driver/internal/internal_node.rb +21 -0
  136. data/ruby/neo4j/driver/internal/internal_pair.rb +9 -0
  137. data/ruby/neo4j/driver/internal/internal_path.rb +35 -0
  138. data/ruby/neo4j/driver/internal/internal_point2_d.rb +9 -0
  139. data/ruby/neo4j/driver/internal/internal_point3_d.rb +6 -0
  140. data/{ffi → ruby}/neo4j/driver/internal/internal_record.rb +2 -1
  141. data/ruby/neo4j/driver/internal/internal_relationship.rb +26 -0
  142. data/ruby/neo4j/driver/internal/internal_result.rb +60 -0
  143. data/ruby/neo4j/driver/internal/internal_session.rb +81 -0
  144. data/ruby/neo4j/driver/internal/internal_transaction.rb +48 -0
  145. data/ruby/neo4j/driver/internal/logging/channel_activity_logger.rb +29 -0
  146. data/ruby/neo4j/driver/internal/logging/channel_error_logger.rb +17 -0
  147. data/ruby/neo4j/driver/internal/logging/prefixed_logger.rb +19 -0
  148. data/ruby/neo4j/driver/internal/logging/reformatted_logger.rb +17 -0
  149. data/ruby/neo4j/driver/internal/messaging/abstract_message_writer.rb +23 -0
  150. data/ruby/neo4j/driver/internal/messaging/bolt_protocol.rb +30 -0
  151. data/ruby/neo4j/driver/internal/messaging/bolt_protocol_version.rb +46 -0
  152. data/ruby/neo4j/driver/internal/messaging/common/common_message_reader.rb +51 -0
  153. data/ruby/neo4j/driver/internal/messaging/common/common_value.rb +31 -0
  154. data/ruby/neo4j/driver/internal/messaging/common/common_value_packer.rb +101 -0
  155. data/ruby/neo4j/driver/internal/messaging/common/common_value_unpacker.rb +234 -0
  156. data/ruby/neo4j/driver/internal/messaging/encode/begin_message_encoder.rb +15 -0
  157. data/ruby/neo4j/driver/internal/messaging/encode/commit_message_encoder.rb +14 -0
  158. data/ruby/neo4j/driver/internal/messaging/encode/discard_all_message_encoder.rb +14 -0
  159. data/ruby/neo4j/driver/internal/messaging/encode/discard_message_encoder.rb +15 -0
  160. data/ruby/neo4j/driver/internal/messaging/encode/goodbye_message_encoder.rb +14 -0
  161. data/ruby/neo4j/driver/internal/messaging/encode/hello_message_encoder.rb +15 -0
  162. data/ruby/neo4j/driver/internal/messaging/encode/init_message_encoder.rb +16 -0
  163. data/ruby/neo4j/driver/internal/messaging/encode/pull_all_message_encoder.rb +14 -0
  164. data/ruby/neo4j/driver/internal/messaging/encode/pull_message_encoder.rb +15 -0
  165. data/ruby/neo4j/driver/internal/messaging/encode/reset_message_encoder.rb +14 -0
  166. data/ruby/neo4j/driver/internal/messaging/encode/rollback_message_encoder.rb +14 -0
  167. data/ruby/neo4j/driver/internal/messaging/encode/route_message_encoder.rb +18 -0
  168. data/ruby/neo4j/driver/internal/messaging/encode/route_v44_message_encoder.rb +27 -0
  169. data/ruby/neo4j/driver/internal/messaging/encode/run_message_encoder.rb +16 -0
  170. data/ruby/neo4j/driver/internal/messaging/encode/run_with_metadata_message_encoder.rb +17 -0
  171. data/ruby/neo4j/driver/internal/messaging/request/abstract_streaming_message.rb +22 -0
  172. data/ruby/neo4j/driver/internal/messaging/request/begin_message.rb +26 -0
  173. data/ruby/neo4j/driver/internal/messaging/request/commit_message.rb +20 -0
  174. data/ruby/neo4j/driver/internal/messaging/request/discard_all_message.rb +20 -0
  175. data/ruby/neo4j/driver/internal/messaging/request/discard_message.rb +23 -0
  176. data/ruby/neo4j/driver/internal/messaging/request/goodbye_message.rb +20 -0
  177. data/ruby/neo4j/driver/internal/messaging/request/hello_message.rb +31 -0
  178. data/ruby/neo4j/driver/internal/messaging/request/init_message.rb +19 -0
  179. data/ruby/neo4j/driver/internal/messaging/request/message_with_metadata.rb +10 -0
  180. data/ruby/neo4j/driver/internal/messaging/request/multi_database_util.rb +26 -0
  181. data/ruby/neo4j/driver/internal/messaging/request/pull_all_message.rb +23 -0
  182. data/ruby/neo4j/driver/internal/messaging/request/pull_message.rb +22 -0
  183. data/ruby/neo4j/driver/internal/messaging/request/reset_message.rb +32 -0
  184. data/ruby/neo4j/driver/internal/messaging/request/rollback_message.rb +20 -0
  185. data/ruby/neo4j/driver/internal/messaging/request/route_message.rb +33 -0
  186. data/ruby/neo4j/driver/internal/messaging/request/run_message.rb +23 -0
  187. data/ruby/neo4j/driver/internal/messaging/request/run_with_metadata_message.rb +47 -0
  188. data/ruby/neo4j/driver/internal/messaging/request/transaction_metadata_builder.rb +24 -0
  189. data/ruby/neo4j/driver/internal/messaging/response/failure_message.rb +40 -0
  190. data/ruby/neo4j/driver/internal/messaging/response/ignored_message.rb +29 -0
  191. data/ruby/neo4j/driver/internal/messaging/response/record_message.rb +33 -0
  192. data/ruby/neo4j/driver/internal/messaging/response/success_message.rb +34 -0
  193. data/ruby/neo4j/driver/internal/messaging/v3/bolt_protocol_v3.rb +78 -0
  194. data/ruby/neo4j/driver/internal/messaging/v3/message_format_v3.rb +17 -0
  195. data/ruby/neo4j/driver/internal/messaging/v3/message_writer_v3.rb +27 -0
  196. data/ruby/neo4j/driver/internal/messaging/v4/bolt_protocol_v4.rb +29 -0
  197. data/ruby/neo4j/driver/internal/messaging/v4/message_format_v4.rb +17 -0
  198. data/ruby/neo4j/driver/internal/messaging/v4/message_writer_v4.rb +28 -0
  199. data/ruby/neo4j/driver/internal/messaging/v41/bolt_protocol_v41.rb +25 -0
  200. data/ruby/neo4j/driver/internal/messaging/v42/bolt_protocol_v42.rb +13 -0
  201. data/ruby/neo4j/driver/internal/messaging/v43/bolt_protocol_v43.rb +19 -0
  202. data/ruby/neo4j/driver/internal/messaging/v43/message_format_v43.rb +18 -0
  203. data/ruby/neo4j/driver/internal/messaging/v43/message_writer_v43.rb +34 -0
  204. data/ruby/neo4j/driver/internal/messaging/v44/bolt_protocol_v44.rb +17 -0
  205. data/ruby/neo4j/driver/internal/messaging/v44/message_format_v44.rb +18 -0
  206. data/ruby/neo4j/driver/internal/messaging/v44/message_writer_v44.rb +26 -0
  207. data/ruby/neo4j/driver/internal/metrics/connection_pool_metrics_listener.rb +34 -0
  208. data/ruby/neo4j/driver/internal/metrics/internal_abstract_metrics.rb +46 -0
  209. data/ruby/neo4j/driver/internal/metrics/internal_connection_pool_metrics.rb +105 -0
  210. data/ruby/neo4j/driver/internal/metrics/internal_metrics.rb +82 -0
  211. data/ruby/neo4j/driver/internal/metrics/internal_metrics_provider.rb +18 -0
  212. data/ruby/neo4j/driver/internal/metrics/listener_event.rb +17 -0
  213. data/ruby/neo4j/driver/internal/metrics/metrics_provider.rb +24 -0
  214. data/ruby/neo4j/driver/internal/metrics/time_recorder_listener_event.rb +15 -0
  215. data/ruby/neo4j/driver/internal/packstream/byte_array_incompatible_packer.rb +12 -0
  216. data/ruby/neo4j/driver/internal/packstream/pack_input.rb +47 -0
  217. data/ruby/neo4j/driver/internal/packstream/pack_output.rb +39 -0
  218. data/ruby/neo4j/driver/internal/packstream/pack_stream.rb +326 -0
  219. data/ruby/neo4j/driver/internal/packstream/pack_type.rb +17 -0
  220. data/ruby/neo4j/driver/internal/retry/exponential_backoff_retry_logic.rb +151 -0
  221. data/ruby/neo4j/driver/internal/revocation_strategy.rb +19 -0
  222. data/ruby/neo4j/driver/internal/scheme.rb +32 -0
  223. data/ruby/neo4j/driver/internal/security/internal_auth_token.rb +15 -0
  224. data/ruby/neo4j/driver/internal/security/security_plan_impl.rb +43 -0
  225. data/ruby/neo4j/driver/internal/security_setting.rb +66 -0
  226. data/ruby/neo4j/driver/internal/session_factory_impl.rb +32 -0
  227. data/ruby/neo4j/driver/internal/spi/connection.rb +19 -0
  228. data/ruby/neo4j/driver/internal/spi/connection_pool.rb +9 -0
  229. data/ruby/neo4j/driver/internal/spi/response_handler.rb +23 -0
  230. data/ruby/neo4j/driver/internal/summary/internal_database_info.rb +7 -0
  231. data/ruby/neo4j/driver/internal/summary/internal_input_position.rb +11 -0
  232. data/ruby/neo4j/driver/internal/summary/internal_notification.rb +16 -0
  233. data/ruby/neo4j/driver/internal/summary/internal_plan.rb +41 -0
  234. data/ruby/neo4j/driver/internal/summary/internal_profiled_plan.rb +32 -0
  235. data/ruby/neo4j/driver/internal/summary/internal_result_summary.rb +33 -0
  236. data/ruby/neo4j/driver/internal/summary/internal_server_info.rb +6 -0
  237. data/ruby/neo4j/driver/internal/summary/internal_summary_counters.rb +18 -0
  238. data/ruby/neo4j/driver/internal/svm/netty_substitutions.rb +196 -0
  239. data/ruby/neo4j/driver/internal/svm/z_lib_substitutions.rb +21 -0
  240. data/ruby/neo4j/driver/internal/util/certificate_tool.rb +65 -0
  241. data/ruby/neo4j/driver/internal/util/clock.rb +29 -0
  242. data/ruby/neo4j/driver/internal/util/error_util.rb +104 -0
  243. data/ruby/neo4j/driver/internal/util/extract.rb +123 -0
  244. data/ruby/neo4j/driver/internal/util/format.rb +39 -0
  245. data/ruby/neo4j/driver/internal/util/futures.rb +99 -0
  246. data/ruby/neo4j/driver/internal/util/iterables.rb +35 -0
  247. data/ruby/neo4j/driver/internal/util/lock_util.rb +23 -0
  248. data/ruby/neo4j/driver/internal/util/metadata_extractor.rb +109 -0
  249. data/ruby/neo4j/driver/internal/util/mutex.rb +9 -0
  250. data/ruby/neo4j/driver/internal/util/preconditions.rb +16 -0
  251. data/ruby/neo4j/driver/internal/util/server_version.rb +60 -0
  252. data/ruby/neo4j/driver/logging1.rb +51 -0
  253. data/ruby/neo4j/driver/net/server_address1.rb +9 -0
  254. data/ruby/neo4j/driver/query.rb +48 -0
  255. data/ruby/neo4j/driver/records.rb +13 -0
  256. data/ruby/neo4j/driver/session_config.rb +15 -0
  257. data/ruby/neo4j/driver/transaction_config.rb +46 -0
  258. data/ruby/neo4j/driver/values.rb +26 -0
  259. data/{lib → ruby}/neo4j/driver/version.rb +1 -1
  260. data/ruby/neo4j/driver.rb +30 -0
  261. metadata +267 -92
  262. data/ffi/bolt/address.rb +0 -11
  263. data/ffi/bolt/address_resolver.rb +0 -12
  264. data/ffi/bolt/address_set.rb +0 -9
  265. data/ffi/bolt/auth.rb +0 -10
  266. data/ffi/bolt/auto_releasable.rb +0 -22
  267. data/ffi/bolt/boolean.rb +0 -9
  268. data/ffi/bolt/bytes.rb +0 -10
  269. data/ffi/bolt/config.rb +0 -45
  270. data/ffi/bolt/connection.rb +0 -44
  271. data/ffi/bolt/connector.rb +0 -17
  272. data/ffi/bolt/dictionary.rb +0 -15
  273. data/ffi/bolt/error.rb +0 -74
  274. data/ffi/bolt/float.rb +0 -9
  275. data/ffi/bolt/integer.rb +0 -9
  276. data/ffi/bolt/library.rb +0 -12
  277. data/ffi/bolt/lifecycle.rb +0 -9
  278. data/ffi/bolt/list.rb +0 -10
  279. data/ffi/bolt/log.rb +0 -16
  280. data/ffi/bolt/socket_options.rb +0 -14
  281. data/ffi/bolt/status.rb +0 -25
  282. data/ffi/bolt/string.rb +0 -9
  283. data/ffi/bolt/structure.rb +0 -10
  284. data/ffi/bolt/value.rb +0 -35
  285. data/ffi/neo4j/driver/auth_tokens.rb +0 -18
  286. data/ffi/neo4j/driver/config.rb +0 -40
  287. data/ffi/neo4j/driver/graph_database.rb +0 -52
  288. data/ffi/neo4j/driver/internal/async/access_mode_connection.rb +0 -19
  289. data/ffi/neo4j/driver/internal/async/direct_connection.rb +0 -106
  290. data/ffi/neo4j/driver/internal/bolt_server_address.rb +0 -18
  291. data/ffi/neo4j/driver/internal/bookmarks_holder.rb +0 -30
  292. data/ffi/neo4j/driver/internal/direct_connection_provider.rb +0 -28
  293. data/ffi/neo4j/driver/internal/driver_factory.rb +0 -126
  294. data/ffi/neo4j/driver/internal/error_handling.rb +0 -112
  295. data/ffi/neo4j/driver/internal/explicit_transaction.rb +0 -146
  296. data/ffi/neo4j/driver/internal/handlers/pull_all_response_handler.rb +0 -104
  297. data/ffi/neo4j/driver/internal/handlers/response_handler.rb +0 -49
  298. data/ffi/neo4j/driver/internal/handlers/run_response_handler.rb +0 -32
  299. data/ffi/neo4j/driver/internal/handlers/session_pull_all_response_handler.rb +0 -32
  300. data/ffi/neo4j/driver/internal/handlers/transaction_pull_all_response_handler.rb +0 -23
  301. data/ffi/neo4j/driver/internal/internal_driver.rb +0 -45
  302. data/ffi/neo4j/driver/internal/internal_logger.rb +0 -32
  303. data/ffi/neo4j/driver/internal/internal_resolver.rb +0 -31
  304. data/ffi/neo4j/driver/internal/internal_statement_result.rb +0 -52
  305. data/ffi/neo4j/driver/internal/messaging/bolt_protocol.rb +0 -24
  306. data/ffi/neo4j/driver/internal/messaging/v1/bolt_protocol_v1.rb +0 -59
  307. data/ffi/neo4j/driver/internal/messaging/v2/bolt_protocol_v2.rb +0 -16
  308. data/ffi/neo4j/driver/internal/messaging/v3/bolt_protocol_v3.rb +0 -63
  309. data/ffi/neo4j/driver/internal/network_session.rb +0 -129
  310. data/ffi/neo4j/driver/internal/retry/exponential_backoff_retry_logic.rb +0 -80
  311. data/ffi/neo4j/driver/internal/session_factory_impl.rb +0 -28
  312. data/ffi/neo4j/driver/internal/summary/internal_result_summary.rb +0 -67
  313. data/ffi/neo4j/driver/internal/summary/internal_server_info.rb +0 -19
  314. data/ffi/neo4j/driver/internal/summary/internal_summary_counters.rb +0 -23
  315. data/ffi/neo4j/driver/internal/util/metadata_extractor.rb +0 -15
  316. data/ffi/neo4j/driver/internal/value/base_time_value.rb +0 -22
  317. data/ffi/neo4j/driver/internal/value/date_value.rb +0 -25
  318. data/ffi/neo4j/driver/internal/value/duration_value.rb +0 -27
  319. data/ffi/neo4j/driver/internal/value/local_date_time_value.rb +0 -24
  320. data/ffi/neo4j/driver/internal/value/local_time_value.rb +0 -19
  321. data/ffi/neo4j/driver/internal/value/node_value.rb +0 -18
  322. data/ffi/neo4j/driver/internal/value/offset_time_value.rb +0 -25
  323. data/ffi/neo4j/driver/internal/value/path_value.rb +0 -41
  324. data/ffi/neo4j/driver/internal/value/point2_d_value.rb +0 -24
  325. data/ffi/neo4j/driver/internal/value/point3_d_value.rb +0 -24
  326. data/ffi/neo4j/driver/internal/value/relationship_value.rb +0 -18
  327. data/ffi/neo4j/driver/internal/value/structure_value.rb +0 -42
  328. data/ffi/neo4j/driver/internal/value/time_with_zone_id_value.rb +0 -25
  329. data/ffi/neo4j/driver/internal/value/time_with_zone_offset_value.rb +0 -28
  330. data/ffi/neo4j/driver/internal/value/unbound_relationship_value.rb +0 -18
  331. data/ffi/neo4j/driver/internal/value/value_adapter.rb +0 -101
  332. data/ffi/neo4j/driver/net/server_address.rb +0 -13
  333. data/ffi/neo4j/driver/statement.rb +0 -15
  334. data/ffi/neo4j/driver/types/entity.rb +0 -21
  335. data/ffi/neo4j/driver/types/node.rb +0 -16
  336. data/ffi/neo4j/driver/types/path.rb +0 -35
  337. data/ffi/neo4j/driver/types/relationship.rb +0 -19
  338. data/ffi/neo4j/driver.rb +0 -61
  339. data/lib/neo4j/driver/internal/ruby_signature.rb +0 -18
@@ -0,0 +1,172 @@
1
+ module Neo4j::Driver
2
+ module Internal
3
+ module Async
4
+ module Inbound
5
+ class InboundMessageDispatcher
6
+ attr_reader :fatal_error_occurred, :current_error
7
+
8
+ def initialize(channel, logger)
9
+ @handlers = []
10
+ @channel = Validator.require_non_nil!(channel)
11
+ @log = Logging::ChannelActivityLogger.new(channel, logger, self.class)
12
+ @error_log = Logging::ChannelErrorLogger.new(channel, logger)
13
+ end
14
+
15
+ def enqueue(handler)
16
+ if fatal_error_occurred
17
+ handler.on_failure(@current_error)
18
+ else
19
+ @handlers << handler
20
+ update_auto_read_managing_handler_if_needed(handler)
21
+ end
22
+ end
23
+
24
+ def set_before_last_handler_hook(before_last_handler_hook)
25
+ unless @channel.event_loop.in_event_loop
26
+ raise Neo4j::Driver::Exceptions::IllegalStateException.new('This method may only be called in the EventLoop')
27
+ end
28
+ @before_last_handler_hook = before_last_handler_hook
29
+ end
30
+
31
+ def queued_handlers_count
32
+ @handlers.size
33
+ end
34
+
35
+ def handle_success_message(meta)
36
+ @log.debug("S: SUCCESS #{meta}")
37
+ invoke_before_last_handler_hook(HandlerHook::SUCCESS)
38
+ handler = remove_handler
39
+ handler.on_success(meta)
40
+ end
41
+
42
+ def handle_record_message(fields)
43
+ @log.debug { "S: RECORD #{fields}" }
44
+
45
+ (@handlers.first or
46
+ raise Exceptions::IllegalStateException,
47
+ "No handler exists to handle RECORD message with fields #{fields}")
48
+ .on_record(fields)
49
+ end
50
+
51
+ def handle_failure_message(code:, message:)
52
+ @log.debug("S: FAILURE #{code}, '#{message}'")
53
+ @current_error = Util::ErrorUtil.new_neo4j_error(code, message)
54
+
55
+ # we should not continue using channel after a fatal error
56
+ # fire error event back to the pipeline and avoid sending RESET
57
+
58
+ # return @channel.pipeline.fire_exception_caught(current_error) if Util::ErrorUtil.fatal?(current_error)
59
+ raise @current_error if Util::ErrorUtil.fatal?(@current_error) # TODO clarify
60
+
61
+ if @current_error.is_a?(Exceptions::AuthorizationExpiredException)
62
+ Connection::ChannelAttributes.authorization_state_listener(@channel).on_expired(@current_error, @channel)
63
+ else
64
+ # write a RESET to "acknowledge" the failure
65
+ enqueue(Handlers::ResetResponseHandler.new(self))
66
+ @channel.write_and_flush(Messaging::Request::ResetMessage::RESET)
67
+ end
68
+
69
+ invoke_before_last_handler_hook(HandlerHook::FAILURE)
70
+ handler = remove_handler
71
+ handler.on_failure(@current_error)
72
+ end
73
+
74
+ def handle_ignored_message
75
+ @log.debug('S: IGNORED')
76
+ handler = remove_handler
77
+
78
+ if @current_error
79
+ error = @current_error
80
+ else
81
+ @log.warn("Received IGNORED message for handler #{handler} but error is missing and RESET is not in progress. Current handlers #{@handlers}")
82
+ error = Exceptions::ClientException.new('Database ignored the request')
83
+ end
84
+
85
+ handler.on_failure(error)
86
+ end
87
+
88
+ def handle_channel_inactive(cause)
89
+ # report issue if the connection has not been terminated as a result of a graceful shutdown request from its
90
+ # parent pool
91
+ if !@gracefully_closed
92
+ handle_channel_error(cause)
93
+ else
94
+ @channel.close
95
+ end
96
+ end
97
+
98
+ def handle_channel_error(error)
99
+ if @current_error
100
+ # we already have an error, this new error probably is caused by the existing one, thus we chain the new error on this current error
101
+ Util::ErrorUtil.add_suppressed(@current_error, error)
102
+ else
103
+ @current_error = error
104
+ end
105
+
106
+ @fatal_error_occurred = true
107
+
108
+ while !@handlers.empty?
109
+ handler = remove_handler
110
+ handler.on_failure(@current_error)
111
+ end
112
+
113
+ @error_log.trace_or_debug('Closing channel because of a failure', error)
114
+ @channel.close
115
+ end
116
+
117
+ def clear_current_error
118
+ raise @current_error if @current_error
119
+ ensure
120
+ @current_error = nil
121
+ end
122
+
123
+ def prepare_to_close_channel
124
+ @gracefully_closed = true
125
+ end
126
+
127
+ def remove_handler
128
+ handler = @handlers.shift
129
+
130
+ if handler == @auto_read_managing_handler
131
+ # the auto-read managing handler is being removed
132
+ # make sure this dispatcher does not hold on to a removed handler
133
+ update_auto_read_managing_handler(nil)
134
+ end
135
+ handler
136
+ end
137
+
138
+ private
139
+
140
+ def update_auto_read_managing_handler_if_needed(handler)
141
+ if handler.can_manage_auto_read?
142
+ update_auto_read_managing_handler(handler)
143
+ end
144
+ end
145
+
146
+ def update_auto_read_managing_handler(new_handler)
147
+ if @auto_read_managing_handler
148
+
149
+ # there already exists a handler that manages channel's auto-read
150
+ # make it stop because new managing handler is being added and there should only be a single such handler
151
+ @auto_read_managing_handler.disable_auto_read_management
152
+
153
+ # restore the default value of auto-read
154
+ @channel.config.set_auto_read(true)
155
+ end
156
+
157
+ @auto_read_managing_handler = new_handler
158
+ end
159
+
160
+ def invoke_before_last_handler_hook(message_type)
161
+ @before_last_handler_hook&.run(message_type) if @handlers.size == 1
162
+ end
163
+
164
+ module HandlerHook
165
+ SUCCESS = :success
166
+ FAILURE = :failure
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,42 @@
1
+ module Neo4j::Driver
2
+ module Internal
3
+ module Async
4
+ module Inbound
5
+ class InboundMessageHandler #< org.neo4j.driver.internal.shaded.io.netty.channel.SimpleChannelInboundHandler
6
+ def initialize(message_format, logger)
7
+ @input = ByteBufInput.new
8
+ @reader = message_format.new_reader(input)
9
+ @logger = logger
10
+ end
11
+
12
+ def handler_added(ctx)
13
+ @message_dispatcher = Validator::require_non_nil!(connection.ChannelAttributes.message_dispatcher(ctx.channel))
14
+ @log = Logging::ChannelActivityLogger.new(ctx.channel, logger, self.class)
15
+ end
16
+
17
+ def handler_removed(_ctx)
18
+ @message_dispatcher = nil
19
+ @log = nil
20
+ end
21
+
22
+ def channel_read0(_ctx, msg)
23
+ if message_dispatcher.fatal_error_occurred
24
+ return @log.warn( "Message ignored because of the previous fatal error. Channel will be closed. Message:\n#{org.neo4j.driver.internal.shaded.io.netty.buffer.ByteBufUtil.hex_dump(msg)}")
25
+ end
26
+
27
+ @log.debug( "S: #{org.neo4j.driver.internal.shaded.io.netty.buffer.ByteBufUtil.hex_dump(msg)}") if @log.is_trace_enabled?
28
+
29
+ @input.start(msg)
30
+ begin
31
+ @reader.read(@message_dispatcher)
32
+ rescue StandardError => error
33
+ org.neo4j.driver.internal.shaded.io.netty.handler.codec.DecoderException.new("Failed to read inbound message:\n#{org.neo4j.driver.internal.shaded.io.netty.buffer.ByteBufUtil.hex_dump(msg)}\n", error)
34
+ ensure
35
+ @input.stop
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,51 @@
1
+ module Neo4j::Driver
2
+ module Internal
3
+ module Async
4
+ module Inbound
5
+ class MessageDecoder #< org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder
6
+ class << self
7
+ def determine_default_cumulator
8
+ value = ENV['message_decoder_cumulator']
9
+ # 'merge' == value ? org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder::MERGE_CUMULATOR : org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder::COMPOSITE_CUMULATOR
10
+ end
11
+ end
12
+
13
+ DEFAULT_CUMULATOR = determine_default_cumulator
14
+
15
+ def initialize
16
+ set_cumulator(DEFAULT_CUMULATOR)
17
+ end
18
+
19
+ def channel_read(ctx, msg)
20
+ if msg.is_a?(org.neo4j.driver.internal.shaded.io.netty.buffer.ByteBuf)
21
+
22
+ # on every read check if input buffer is empty or not
23
+ # if it is empty then it's a message boundary and full message is in the buffer
24
+ @read_message_boundary = msg.readable_bytes == 0
25
+ end
26
+
27
+ org.neo4j.driver.internal.shaded.io.netty.handler.codec.ByteToMessageDecoder.channel_read(ctx, msg)
28
+ end
29
+
30
+ def decode(ctx, inward, out)
31
+ if @read_message_boundary
32
+
33
+ # now we have a complete message in the input buffer
34
+
35
+ # increment ref count of the buffer and create it's duplicate that shares the content
36
+ # duplicate will be the output of this decoded and input for the next one
37
+ message_buf = inward.retained_duplicate
38
+
39
+ # signal that whole message was read by making input buffer seem like it was fully read/consumed
40
+ inward.reader_index(inward.readable_bytes)
41
+
42
+ # pass the full message to the next handler in the pipeline
43
+ out.add(message_buf)
44
+ @read_message_boundary = false
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,98 @@
1
+ module Neo4j::Driver
2
+ module Internal
3
+ module Async
4
+ class InternalAsyncSession
5
+ def initialize(session)
6
+ @session = session
7
+ end
8
+
9
+ delegate :last_bookmark, :close_async, to: :@session
10
+
11
+ def run_async(query, parameters = {}, config = {})
12
+ @session.run_async(org.neo4j.driver.Query.new(query, **parameters), **config)
13
+ end
14
+
15
+ def begin_transaction_async(**config)
16
+ @session.begin_transaction_async(**config).then(&InternalAsyncTransaction.method(:new))
17
+ end
18
+
19
+ def read_transaction_async(**config, &work)
20
+ transaction_async(org.neo4j.driver.AccessMode::READ, **config, &work)
21
+ end
22
+
23
+ def write_transaction_async(**config, &work)
24
+ transaction_async(org.neo4j.driver.AccessMode::WRITE, **config, &work)
25
+ end
26
+
27
+ private
28
+
29
+ def transaction_async(mode, **config, &work)
30
+ @session.retry_logic.retry_async do
31
+ result_future = java.util.concurrent.CompletableFuture.new
32
+ tx_future = @session.begin_transaction_async(mode, ** config)
33
+
34
+ tx_future.when_complete do |tx, completion_error|
35
+ error = Util::Futures.completion_exception_cause(completion_error)
36
+
37
+ if !error.nil?
38
+ result_future.complete_exceptionally(error)
39
+ else
40
+ execute_work(result_future, tx, &work)
41
+ end
42
+ end
43
+ result_future
44
+ end
45
+ end
46
+
47
+ def execute_work(result_future, tx, &work)
48
+ work_future = safe_execute_work(tx, &work)
49
+
50
+ work_future.when_complete do |result, completion_error|
51
+ error = Util::Futures.completion_exception_cause(completion_error)
52
+
53
+ if !error.nil?
54
+ close_tx_after_failed_transaction_work(tx, result_future, error)
55
+ else
56
+ close_tx_after_succeeded_transaction_work(tx, result_future, result)
57
+ end
58
+ end
59
+ end
60
+
61
+ def safe_execute_work(tx)
62
+ # given work might fail in both async and sync way
63
+ # async failure will result in a failed future being returned
64
+ # sync failure will result in an exception being thrown
65
+ begin
66
+ result = yield InternalAsyncTransaction.new(tx)
67
+
68
+ # protect from given transaction function returning null
69
+ result == nil ? Util::Futures.completed_with_null : result
70
+ rescue StandardError => work_error
71
+ # work threw an exception, wrap it in a future and proceed
72
+ Util::Futures.failed_future(work_error)
73
+ end
74
+ end
75
+
76
+ def close_tx_after_failed_transaction_work(tx, result_future, error)
77
+ tx.close_async.when_complete do |_ignored, rollback_error|
78
+ error.add_suppressed(rollback_error) unless rollback_error.nil?
79
+
80
+ result_future.complete_exceptionally(error)
81
+ end
82
+ end
83
+
84
+ def close_tx_after_succeeded_transaction_work(tx, result_future, result)
85
+ tx.close_async(true).when_complete do |_ignored, completion_error|
86
+ commit_error = Util::Futures.completion_exception_cause(completion_error)
87
+
88
+ if !commit_error.nil?
89
+ result_future.complete_exceptionally(commit_error)
90
+ else
91
+ result_future.complete(result)
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,13 @@
1
+ module Neo4j::Driver
2
+ module Internal
3
+ module Async
4
+ class InternalAsyncTransaction
5
+ delegate :run_async, :commit_async, :rollback_async, :open?, to: :@tx
6
+
7
+ def initialize(tx)
8
+ @tx = tx
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ module Neo4j::Driver
2
+ module Internal
3
+ module Async
4
+ class LeakLoggingNetworkSession < NetworkSession
5
+ def initialize(connection_provider, retry_logic, database_name, mode, bookmark_holder, impersonated_user, fetch_size, logger)
6
+ super
7
+ @stack_trace = capture_stack_trace
8
+ end
9
+
10
+ def finalize
11
+ log_leak_if_needed
12
+ super
13
+ end
14
+
15
+ private
16
+
17
+ def log_leak_if_needed
18
+ is_open = Util::Futures.blocking_get(current_connection_is_open)
19
+ if is_open
20
+ @log.error do
21
+ "Neo4j Session object leaked, please ensure that your application fully consumes results in "\
22
+ "Sessions or explicitly calls `close` on Sessions before disposing of the objects.\n"\
23
+ "Session was created at:\n#{@stack_trace}"
24
+ end
25
+ end
26
+ end
27
+
28
+ def capture_stack_trace
29
+ Thread.current.backtrace.join("\n")
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,196 @@
1
+ module Neo4j::Driver
2
+ module Internal
3
+ module Async
4
+ class NetworkConnection < ::Async::Pool::Resource
5
+ include Spi::Connection
6
+ delegate :protocol, to: :@channel
7
+
8
+ attr_reader :server_agent, :server_address, :server_version
9
+
10
+ def initialize(channel, channel_pool, logger)
11
+ super()
12
+ @log = logger
13
+ @channel = channel
14
+ @message_dispatcher = channel.attributes[:message_dispatcher]
15
+ @server_agent = channel.attributes[:server_agent]
16
+ @server_address = channel.attributes[:server_address]
17
+ @server_version = channel.attributes[:server_version]
18
+ @protocol = Messaging::BoltProtocol.for_channel(channel)
19
+ @channel_pool = channel_pool
20
+ # @release_future = java.util.concurrent.CompletableFuture.new
21
+ # @clock = clock
22
+ # @connection_read_timeout = Connection::ChannelAttributes.connection_read_timeout(channel) || nil
23
+ @status = Concurrent::AtomicReference.new(Status::OPEN)
24
+ end
25
+
26
+ # def close
27
+ # super
28
+ # @io.close
29
+ # end
30
+
31
+ def open?
32
+ @status.get == Status::OPEN
33
+ end
34
+
35
+ def enable_auto_read
36
+ set_auto_read(true) if open?
37
+ end
38
+
39
+ def disable_auto_read
40
+ set_auto_read(false) if open?
41
+ end
42
+
43
+ def flush
44
+ flush_in_event_loop if verify_open(nil, nil)
45
+ end
46
+
47
+ def write(message1, handler1, message2 = nil, handler2 = nil)
48
+ if message2.nil? && handler2.nil?
49
+ write_message_in_event_loop(message1, handler1, false) if verify_open(handler1, nil)
50
+ else
51
+ write_messages_in_event_loop(message1, handler1, message2, handler2, false) if verify_open(handler1, handler2)
52
+ end
53
+ end
54
+
55
+ def write_and_flush(message1, handler1, message2 = nil, handler2 = nil)
56
+ if message2.nil? && handler2.nil?
57
+ write_message_in_event_loop(message1, handler1, true) if verify_open(handler1, nil)
58
+ else
59
+ write_messages_in_event_loop(message1, handler1, message2, handler2, true) if verify_open(handler1, handler2)
60
+ end
61
+ end
62
+
63
+ def reset
64
+ result = java.util.concurrent.CompletableFuture.new
65
+ handler = Handlers::ResetResponseHandler.new(@message_dispatcher, result)
66
+ write_reset_message_if_needed(handler, true)
67
+ result
68
+ end
69
+
70
+ def release
71
+ if @status.compare_and_set(Status::OPEN, Status::RELEASED)
72
+ @channel_pool.release(@channel)
73
+ end
74
+ # handler = Handlers::ChannelReleasingResetResponseHandler.new(@channel, @channel_pool, @message_dispatcher, @clock, @release)
75
+ # write_reset_message_if_needed(handler, false)
76
+ # @metrics_listener.after_connection_released(Connection::ChannelAttributes.pool_id(@channel), @in_use_event)
77
+ # end
78
+ # @release_future
79
+ end
80
+
81
+ def terminate_and_release(reason)
82
+ if @status.compare_and_set(Status::OPEN, Status::TERMINATED)
83
+ Connection::ChannelAttributes.set_termination_reason(@channel, reason)
84
+ Util::Futures.as_completion_stage(@channel.close).exceptionally(-> (_throwable) { nil }).then_compose(-> (_ignored) { @channel_pool.release(@channel) }).when_complete do |_ignored, _throwable|
85
+ @release_future.complete(nil)
86
+ @metrics_listener.after_connection_released(Connection::ChannelAttributes.pool_id(@channel), @in_use_event)
87
+ end
88
+ end
89
+ end
90
+
91
+ private
92
+
93
+ def write_reset_message_if_needed(reset_handler, is_session_reset)
94
+ @channel.event_loop.execute do
95
+ if is_session_reset && !open?
96
+ reset_handler.on_success(java.util.Collections.empty_map)
97
+ else
98
+ # auto-read could've been disabled, re-enable it to automatically receive response for RESET
99
+ set_auto_read(true)
100
+ @message_dispatcher.enqueue(reset_handler)
101
+ @channel.write_and_flush(Messaging::Request::ResetMessage::RESET).add_listener(-> (_future) { register_connection_read_timeout(@channel) })
102
+ end
103
+ end
104
+ end
105
+
106
+ def flush_in_event_loop
107
+ @channel.event_loop.execute do
108
+ @channel.flush
109
+ register_connection_read_timeout(@channel)
110
+ end
111
+ end
112
+
113
+ def write_message_in_event_loop(message, handler, flush)
114
+ @message_dispatcher.enqueue(handler)
115
+
116
+ if flush
117
+ @channel.write_and_flush(message)#.add_listener(-> (_future) { register_connection_read_timeout(@channel) })
118
+ else
119
+ @channel.write(message)
120
+ end
121
+ end
122
+
123
+ def write_messages_in_event_loop(message1, handler1, message2, handler2, flush)
124
+ @channel.event_loop.execute do
125
+ @message_dispatcher.enqueue(handler1)
126
+ @message_dispatcher.enqueue(handler2)
127
+
128
+ @channel.write(message1, channel.void_promise)
129
+
130
+ if flush
131
+ @channel.write_and_flush(message2).add_listener(-> (_future) { register_connection_read_timeout(@channel) })
132
+ else
133
+ @channel.write(message2, @channel.void_promise)
134
+ end
135
+ end
136
+ end
137
+
138
+ def set_auto_read(value)
139
+ @channel.config.set_auto_read(value)
140
+ end
141
+
142
+ def verify_open(handler1, handler2)
143
+ connection_status = @status.get
144
+
145
+ case connection_status
146
+ when 'open'
147
+ true
148
+ when 'released'
149
+ error = Neo4j::Driver::Exceptions::IllegalStateException.new("Connection has been released to the pool and can't be used")
150
+
151
+ handler1.on_failure(error) unless handler1.nil?
152
+
153
+ handler2.on_failure(error) unless handler2.nil?
154
+
155
+ false
156
+ when 'terminated'
157
+ terminated_error = Neo4j::Driver::Exceptions::IllegalStateException.new("Connection has been terminated and can't be used")
158
+
159
+ handler1.on_failure(terminated_error) unless handler1.nil?
160
+
161
+ handler2.on_failure(terminated_error) unless handler2.nil?
162
+
163
+ false
164
+ else
165
+ raise Neo4j::Driver::Exceptions::IllegalStateException.new("Unknown status: #{connection_status}")
166
+ end
167
+ end
168
+
169
+ def register_connection_read_timeout(channel)
170
+ if !channel.event_loop.in_event_loop
171
+ raise Neo4j::Driver::Exceptions::IllegalStateException.new('This method may only be called in the EventLoop')
172
+ end
173
+
174
+ if !@connection_read_timeout.nil? && @connection_read_timeout_handler.nil?
175
+ connection_read_timeout_handler = Inbound::ConnectionReadTimeoutHandler.new(@connection_read_timeout, java.util.concurrent.TimeUnit::SECONDS)
176
+ channel.pipeline.add_first(connection_read_timeout_handler)
177
+ @log.debug('Added ConnectionReadTimeoutHandler')
178
+
179
+ @message_dispatcher.set_before_last_handler_hook do |message_type|
180
+ channel.pipeline.remove(connection_read_timeout_handler)
181
+ connection_read_timeout_handler = nil
182
+ @message_dispatcher.set_before_last_handler_hook(nil)
183
+ log.debug('Removed ConnectionReadTimeoutHandler')
184
+ end
185
+ end
186
+ end
187
+
188
+ class Status
189
+ OPEN = 'open'
190
+ RELEASED = 'released'
191
+ TERMINATED = 'terminated'
192
+ end
193
+ end
194
+ end
195
+ end
196
+ end