类:Mongo::Server::Connection
- 继承:
-
ConnectionBase
- 对象
- ConnectionCommon
- ConnectionBase
- Mongo::Server::Connection
- 扩展方式:
- 可转发
- 包括:
- ID 、 Monitoring::Publishable 、 Retryable
- 定义于:
- lib/ Mongo/ 服务器/connection.rb
Overview
此类对服务器的套接字连接及其行为进行建模。
常量摘要折叠
- PING =
已弃用。
MongoDB Server选择规范不再需要此功能。
ping 命令。
{ 网络探测(ping): 1 }.冻结
- PING_OP_MSG =
已弃用。
MongoDB Server选择规范不再需要此功能。
OP_MSG 的网络探测(ping)命令
{ :ping => 1, ' $db ' => Database::ADMIN }.冻结
- PING_OP_MSG_MESSAGE =
已弃用。
MongoDB Server选择规范不再需要此功能。
作为 OP_MSG 的网络探测(ping)消息
protocol::消息.new([], {}, PING_OP_MSG)
- PING_OP_MSG_BYTES =
已弃用。
MongoDB Server选择规范不再需要此功能。
原始字节形式的网络探测(ping) OP_MSG 消息
PING_OP_MSG_MESSAGE.序列化.to_s.冻结
Loggable中包含的常量
从ConnectionBase继承的常量
Mongo::Server::ConnectionBase::DEFAULT_MAX_BSON_OBJECT_SIZE 、 Mongo::Server::ConnectionBase::MAX_BSON_COMMAND_OVERHEAD 、 Mongo::Server::ConnectionBase::REDUCED_MAX_BSON_SIZE
实例属性摘要折叠
-
# global_id ⇒ 整数
只读
跨所有连接。
-
# ID ⇒ 整数
只读
跨连接到同一服务器对象。
-
# last_checkin ⇒ 时间
只读
上次将连接检回池中的时间。
包含在Monitoring::Publishable 中的属性
从ConnectionBase继承的属性
#description 、 #options 、 #server
从ConnectionCommon继承的属性
实例方法摘要折叠
-
#已关闭? ⇒ true | false
连接是否已关闭。
-
# connect! (context = nil) ⇒ true
建立与目标地址的网络连接。
-
#已连接? ⇒ true | false
连接是否已连接且未中断、关闭或引发错误。
-
# connection_pool ⇒ 对象
private
创建此连接的连接池。
-
#断开连接! (options = nil) ⇒ true
断开连接。
- #错误? ⇒ 布尔 private
-
#initialize (server, options = {}) ⇒ 连接
构造函数
private
使用指定选项创建指向指定目标地址的新连接对象。
-
#中断! ⇒ 对象
将连接标记为已中断。
-
#中断? ⇒ true | false
连接是否中断。
-
# pin (reason =: 游标) ⇒ 对象
private
由于给定原因,将连接标记为固定。
-
# ping ="true, false"
已弃用
已弃用。
MongoDB Server选择规范不再需要此功能。
-
#已固定? ⇒ 布尔
private
该连接是由事务还是游标操作使用。
-
# record_checkin! ⇒ self
记录上次签到时间。
-
# socket_timeout ⇒ Float (也:#timeout)
获取在套接字上执行操作的超时时间。
-
#transport ⇒ Symbol | nil
private
获取此连接的传输类型。
-
# unpin (reason =: 游标) ⇒ 对象
private
由于给定原因,从连接中删除管脚。
-
#unpin_all ⇒ 对象
private
从连接中删除所有管脚。
ID中包含的方法
Retryable 中包含的方法
#read_worker、#select_server、#with_overload_retry、#write_worker
Monitoring::Publishable 中包含的方法
#publish_cmap_event 、 #publish_event 、 #publish_sdam_event
Loggable中包含的方法
#log_debug 、 #log_error 、 #log_ Fatal 、 #log_info 、 #log_warn 、 #logger
从ConnectionBase继承的方法
#app_metadata 、 #dispatch 、 #Generation 、 #service_id
从ConnectionCommon继承的方法
#handshake_command , #handshake_document
构造函数详情
#initialize (server, options = {}) ⇒连接
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
绝不能在MongoDB Server之外直接实例化连接。
使用指定选项创建指向指定目标地址的新连接对象。
构造函数不执行任何 I/O(因此不创建套接字、不握手也不进行身份验证);调用 connect! 连接对象上的方法来创建网络连接。
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 90 def 初始化(server, = {}) if server.load_balancer? && [:Generation] 提高 ArgumentError, '当服务器是负载负载均衡器时,无法设立生成 ' end @id = server.next_connection_id @global_id = self.class.next_id @monitoring = server.监控 @options = .冻结 @server = server @socket = nil @last_checkin = nil @auth_ Mechanism = nil @pid = 处理.进程 ID (PID) @pin_reasons = 集.new publish_cmap_event( 监控::事件::Cmap::connectionCreated.new(地址, id) ) end |
实例属性详细信息
# global_id ⇒整数(只读)
跨所有连接。
124 125 126 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 124 def global_id @global_id end |
# ID =" Integer " (只读)
跨连接到同一服务器对象。
120 121 122 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 120 def id @id end |
# last_checkin ⇒时间(只读)
返回上次将连接重新检入池中的时间。
114 115 116 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 114 def last_checkin @last_checkin end |
实例方法详细信息
#已关闭? ⇒ true | false
连接是否已关闭。
不应再使用关闭的连接。 而是从连接池中获取新连接。
152 153 154 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 152 def 已关闭? !!@close end |
# connect! (context = nil) ⇒ true
如果以前不存在套接字,则此方法会通过设置套接字来更改连接对象。
建立与目标地址的网络连接。
如果已建立连接,则此方法不执行任何操作。
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 228 def 连接!(上下文 = nil) ise_if_close! 除非 @socket @socket = create_socket(上下文) @description, @compressor = do_connect if server.load_balancer? if Lint.已启用? && !service_id 提高 错误::内部驱动程序错误, ' 连接到负载负载均衡器,必须在此处设立service_id,但没有 ' end @Generation = connection_pool.Generation_manager.生成(service_id: service_id) end publish_cmap_event( 监控::事件::Cmap::connectionReady.new(地址, id) ) @close_event_published = false end true end |
#已连接? ⇒ true | false
连接是否已连接且未中断、关闭或引发错误。
140 141 142 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 140 def 已连接? !已关闭? && !错误? && !中断? && !!@socket end |
# connection_pool ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
创建此连接的连接池。 可能为零。
132 133 134 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 132 def connection_pool [:connection_pool] end |
#断开连接! (options = nil) ⇒ true
连接断开后,不应再使用。 应从连接池获取新连接,连接池将返回就绪连接或创建新连接。 如果启用了 linting,则重复使用已断开的连接将引发 Error::LintError。 如果未启用 linting,则会记录警告。
如果关闭成功,此方法会通过将套接字设置为 nil 来更改连接对象。
断开连接。
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 310 def 断开连接!( = nil) # 注意:@close 在这里可能为 true,但我们也可能有一个套接字。 # 检查套接字,而不是@关闭标志。 @auth_ Mechanism = nil @last_checkin = nil if 套接字 开始 套接字.关闭 救援 StandardError nil end @socket = nil end @close = true 中断! if && [:interrupted] # 为了满足 CMAP 规范测试,发布关闭事件,即使 # 套接字从未连接(因此就绪事件从未 # 已发布)。 但跟踪我们是否发布了关闭事件,并且不 # 多次发布,除非重新连接套接字 - # 在这种情况下,每次套接字关闭都会发布一次关闭事件。 除非 @close_event_published 原因 = && [:reason] publish_cmap_event( 监控::事件::Cmap::connectionClosed.new( 地址, id, 原因 ) ) @close_event_published = true end true end |
#错误? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
172 173 174 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 172 def 错误? !!@error end |
#中断! ⇒对象
将连接标记为已中断。
167 168 169 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 167 def 中断! @interrupted = true end |
#中断? ⇒ true | false
连接是否中断。
中断的连接已从池中删除,不应重新检入池中。
162 163 164 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 162 def 中断? !!@interrupted end |
#pin (reason =: 游标) ⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
由于给定原因,将连接标记为固定。
194 195 196 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 194 def 销(原因 = :cursor) @pin_reasons << 原因 end |
# ping ⇒ true , false
MongoDB Server选择规范不再需要此功能。
它使用预序列化的 ping 消息进行优化。
对连接执行 Ping 操作,查看服务器是否响应命令。 这在服务器端是非阻塞的。
359 360 361 362 363 364 365 366 367 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 359 def ping 确保连接 do |套接字| 回复 = add_server_diagnostics do 套接字.写(PING_OP_MSG_BYTES) protocol::message.反序列化(套接字, ) end 回复.文档[0][操作::结果::正常] == 1 end end |
#已固定? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
该连接是由事务还是游标操作使用。
如果固定连接空闲或过时,则不应将其断开连接或从连接池中删除。
@return [ true | false ] 连接是否已固定。
184 185 186 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 184 def 已固定? !@pin_reasons.空? end |
# record_checkin! ⇒ self
记录上次签到时间。
388 389 390 391 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 388 def record_checkin! @last_checkin = 时间.now self end |
# socket_timeout ⇒ Float也称为:超时
获取在套接字上执行操作的超时时间。
374 375 376 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 374 def socket_timeout @timeout ||= [:socket_timeout] end |
#transport ⇒ Symbol | nil
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
获取此连接的传输类型。
398 399 400 401 402 403 404 405 406 407 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 398 def 传输 return nil if @socket.nil? 案例 @socket when mongo::套接字::Unix :unix else :tcp end end |
# unpin (reason =: 游标) ⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
由于给定原因,从连接中删除管脚。
204 205 206 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 204 def 取消固定(原因 = :cursor) @pin_reasons.删除(原因) end |
#unpin_all ⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
从连接中删除所有管脚。
211 212 213 |
# File 'lib/ Mongo/ 服务器/connection.rb', line 211 def unpin_all @pin_reasons.清除 end |