类:Mongo::Server::Monitor::Connection Private
- 继承:
-
ConnectionCommon
- 对象
- ConnectionCommon
- Mongo::Server::Monitor::Connection
- 包括:
- Loggable
- 定义于:
- lib/ Mongo/ 服务器/ 监控/connection.rb
Overview
此类是私有 API 的一部分。 应尽可能避免使用此类,因为它将来可能会被删除或更改。
此类对监视器连接及其行为进行建模。
常量摘要
Loggable中包含的常量
实例属性摘要折叠
-
#地址⇒ Mongo::Address
只读
private
地址 要连接到的地址。
-
# options ⇒ 哈希
只读
private
选项 传入的选项。
-
# server_connection_id ⇒ 整数
只读
private
Server_connection_id 服务器连接 ID。
从ConnectionCommon继承的属性
实例方法摘要折叠
-
# check_document ⇒ BSON::Document
private
构建用于连接检查的文档。
-
# connect! ⇒ true
private
建立与目标地址的网络连接。
-
# 断开连接! (_options = nil) ⇒ true
private
断开连接。
-
#dispatch(message) ⇒ Protocol::Message
private
发送消息并返回结果。
-
#dispatch_bytes(bytes, **opts) ⇒ Protocol::Message
private
发送预序列化消息并返回结果。
-
#握手! ⇒ BSON::Document
private
向连接的主机发送握手命令并验证响应。
-
#initialize (address, options = {}) ⇒ 连接
构造函数
private
使用指定选项创建指向指定目标地址的新连接对象。
- # read_response (**opts) ⇒ 对象 private
-
# socket_timeout = "Float"
private
返回监控套接字超时时间。
- # write_bytes (bytes) ⇒ 对象 private
Loggable中包含的方法
#log_debug 、 #log_error 、 #log_ Fatal 、 #log_info 、 #log_warn 、 #logger
从ConnectionCommon继承的方法
#connected? , #handshake_command , #handshake_document
构造函数详情
#initialize (address, options = {}) ⇒连接
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
监控连接不会进行身份验证。
使用指定选项创建指向指定目标地址的新连接对象。
构造函数不执行任何 I/O(因此不创建套接字也不握手);调用 connect! 连接对象上的方法来创建网络连接。
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ Mongo/ 服务器/ 监控/connection.rb', line 56 def 初始化(地址, = {}) @address = 地址 @options = .dup.冻结 提高 ArgumentError, ' App 元数据 is required ' 除非 @app_metadata = [:app_metadata] @socket = nil @pid = 处理.进程 ID (PID) @compressor = nil @hello_ok = false end |
实例属性详细信息
#地址⇒ Mongo::Address (readonly)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回要连接到的地址。
71 72 73 |
# File 'lib/ Mongo/ 服务器/ 监控/connection.rb', line 71 def 地址 @address end |
# options ⇒哈希(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回 options 传入的选项。
68 69 70 |
# File 'lib/ Mongo/ 服务器/ 监控/connection.rb', line 68 def @options end |
# server_connection_id ⇒整数(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回 server_connection_id 服务器连接 ID。
87 88 89 |
# File 'lib/ Mongo/ 服务器/ 监控/connection.rb', line 87 def server_connection_id @server_connection_id end |
实例方法详细信息
# check_document ⇒ BSON::Document
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
构建用于连接检查的文档。
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/ Mongo/ 服务器/ 监控/connection.rb', line 224 def check_document server_api = @app_metadata.server_api || [:server_api] doc = if hello_ok? || server_api _doc = HELLO_DOC _doc = _doc.合并(merge)(Utils.transform_server_api(server_api)) if server_api _doc else LEGACY_HELLO_DOC end # 必须将压缩器设置为保持正确的压缩状态 # 在服务器描述中。 请参阅 RUBY- 2427 if compressors = [:compressors] doc = doc.合并(merge)(压缩: compressors) end doc end |
# connect! ⇒ true
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
如果以前不存在套接字,则此方法会通过设置套接字来更改连接类。
建立与目标地址的网络连接。
如果已建立连接,则此方法不执行任何操作。
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/ Mongo/ 服务器/ 监控/connection.rb', line 151 def 连接! 提高 ArgumentError, '监控连接已连接' if @socket @socket = add_server_diagnostics do 地址.套接字(socket_timeout, .合并(merge)( connection_address: 地址, 监控: true )) end true end |
# 断开连接! (_options = nil) ⇒ true
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
如果关闭成功,此方法会通过将套接字设置为零来改变连接。
此方法接受一个选项参数,以与 Server::Connections 兼容。 但是,所有选项都会被忽略。
断开连接。
176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/ Mongo/ 服务器/ 监控/connection.rb', line 176 def 断开连接!( = nil) if 套接字 开始 套接字.关闭 救援 StandardError nil end @socket = nil end true end |
#dispatch(message) ⇒ Protocol::Message
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
发送消息并返回结果。
94 95 96 |
# File 'lib/ Mongo/ 服务器/ 监控/connection.rb', line 94 def 调度() dispatch_bytes(.序列化.to_s) end |
#dispatch_bytes(bytes, **opts) ⇒ Protocol::Message
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
发送预序列化消息并返回结果。
106 107 108 109 110 111 |
# File 'lib/ Mongo/ 服务器/ 监控/connection.rb', line 106 def dispatch_bytes(字节, **opts) write_bytes(字节) read_response( socket_timeout: opts[:read_socket_timeout] ) end |
#握手! ⇒ BSON::Document
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
向连接的主机发送握手命令并验证响应。
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/ Mongo/ 服务器/ 监控/connection.rb', line 193 def 握手! 命令 = handshake_command( 握手文档( @app_metadata, server_api: [:server_api] ) ) 有效负载 = 命令.序列化.to_s = dispatch_bytes(有效负载) 结果 = 操作::结果.new() 结果.validate! 回复 = 结果.文档.first set_compressor!(回复) set_hello_ok!(回复) @server_connection_id = 回复[' connectionId '] 回复 救援 StandardError => e msg = "无法与#{ Address }握手" Utils.warn_bg_Exception(msg, e, 记录器: [:logger], log_prefix: [:log_prefix], bg_error_backtrace: [:bg_error_backtrace]) 提高 end |
# read_response (**opts) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/ Mongo/ 服务器/ 监控/connection.rb', line 125 def read_response(**opts) 提高 ArgumentError, "尝试在未连接的连接上读取#{ self } " 除非 已连接? add_server_connection_id do add_server_diagnostics do protocol::message.反序列化(套接字, protocol::message::MAX_MESSAGE_SIZE, nil, **opts) end end end |
# socket_timeout = " Float "
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回监控套接字超时时间。
请注意,监控连接使用连接超时值作为套接字超时值。 有关详细信息,请参阅MongoDB Server发现和监控规范。
82 83 84 |
# File 'lib/ Mongo/ 服务器/ 监控/connection.rb', line 82 def socket_timeout [:connect_timeout] || 服务器::CONNECT_TIMEOUT end |
# write_bytes (bytes) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
113 114 115 116 117 118 119 120 121 |
# File 'lib/ Mongo/ 服务器/ 监控/connection.rb', line 113 def write_bytes(字节) 提高 ArgumentError, "尝试在未连接的连接上进行分派#{ self } " 除非 已连接? add_server_connection_id do add_server_diagnostics do 套接字.写(字节) end end end |