类:Mongo::CsotTimeoutHolder Private
- 继承:
-
对象
- 对象
- Mongo::CsotTimeoutHolder
- 定义于:
- lib/mongo/csot_timeout_holder.rb
Overview
此类是私有 API 的一部分。 应尽可能避免使用此类,因为它将来可能会被删除或更改。
此类存储操作超时并提供相应的辅助方法。
直接已知子类
实例属性摘要折叠
- #截止日期 ⇒ 对象 只读 private
- # operation_timeups ⇒ 对象 只读 private
- # timeout_sec ⇒ 对象 只读 private
实例方法摘要折叠
-
# check_timeout!⇒ 对象
private
检查操作超时是否已过期,如果已过期,则引发相应的错误。
-
#csot? ⇒ true | false
private
是否为该操作启用了 CSOT。
-
#initialize (session: nil, operation_timeups: {}) ⇒ CsotTimeoutHolder
构造函数
private
CsotTimeoutHolder 的新实例。
-
#剩余超时时间 ⇒ 整数 | nil
private
返回为操作设立的剩余超时毫秒数;如果未设立超时,或者超时为 0(表示无限制),则返回 nil。
- #剩余超时毫秒! ⇒ 对象 private
-
#剩余超时秒 ⇒ Float | nil
private
返回为操作设立的剩余超时秒数;如果未设立超时,或者超时为 0(表示无限制),则返回 nil。
- #剩余超时秒! ⇒ 对象 private
-
# timeout?⇒ true | false
private
如果未启用 CSOT,或者将 CSOT设立为 0(表示无限制),则返回 false,否则返回 true。
-
# timeout_expired? ⇒ true | false
private
操作超时时间是否已到。
构造函数详情
#initialize (session: nil, operation_timeups: {}) ⇒ CsotTimeoutHolder
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回 CsotTimeoutHolder 的新实例。
22 23 24 25 26 |
# File 'lib/ Mongo/csot_timeout_holder.rb', line 22 def 初始化(会话: nil, operation_timeups: {}) @deadline = 计算截止日期(operation_timeups, 会话) @operation_timeups = operation_timeups @timeout_sec = (@deadline - Utils.monotic_time if @deadline) end |
实例属性详细信息
#截止日期 ⇒ 对象(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
28 29 30 |
# File 'lib/ Mongo/csot_timeout_holder.rb', line 28 def 截止日期 @deadline end |
# operation_timeups ⇒ 对象(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
28 29 30 |
# File 'lib/ Mongo/csot_timeout_holder.rb', line 28 def operation_timeups @operation_timeups end |
# timeout_sec ⇒ 对象(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
28 29 30 |
# File 'lib/ Mongo/csot_timeout_holder.rb', line 28 def timeout_sec @timeout_sec end |
实例方法详细信息
# check_timeout!⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
检查操作超时是否已过期,如果已过期,则引发相应的错误。
84 85 86 87 88 |
# File 'lib/ Mongo/csot_timeout_holder.rb', line 84 def check_timeout! return 除非 timeout_expired? 提高 错误::超时错误, " 操作花费了超过 #{ timeout_sec } 秒 " end |
#csot? ⇒ true | false
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回是否为该操作启用了 CSOT。
31 32 33 |
# File 'lib/ Mongo/csot_timeout_holder.rb', line 31 def csot? !截止日期.nil? end |
#剩余超时时间 ⇒ 整数 | nil
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回为操作设立的剩余超时毫秒数;如果未设立超时,或者超时为 0(表示无限制),则返回 nil。
58 59 60 61 62 63 |
# File 'lib/ Mongo/csot_timeout_holder.rb', line 58 def 剩余超时毫秒 秒数 = 剩余超时秒数 return nil if 秒数.nil? (秒数 * 1 _ 000).to_i end |
#剩余超时毫秒! ⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
65 66 67 68 |
# File 'lib/ Mongo/csot_timeout_holder.rb', line 65 def 剩余超时毫秒! check_timeout! 剩余超时毫秒 end |
#剩余超时秒 ⇒ Float | nil
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回为操作设立的剩余超时秒数;如果未设立超时,或者超时为 0(表示无限制),则返回 nil。
44 45 46 47 48 |
# File 'lib/ Mongo/csot_timeout_holder.rb', line 44 def 剩余超时秒数 return nil 除非 超时? 截止日期 - Utils.monotic_time end |
#剩余超时秒! ⇒ 对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
50 51 52 53 |
# File 'lib/ Mongo/csot_timeout_holder.rb', line 50 def 剩余超时秒! check_timeout! 剩余超时秒数 end |
# timeout?⇒ true | false
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
如果未启用 CSOT,或者将 CSOT设立为 0(表示无限制),则返回 false,否则返回 true。
37 38 39 |
# File 'lib/ Mongo/csot_timeout_holder.rb', line 37 def 超时? ![ nil, 0 ].包括?(@deadline) end |
# timeout_expired? ⇒ true | false
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回操作的超时时间是否已到。 如果未设立超时,此方法将返回 false。
72 73 74 75 76 77 78 |
# File 'lib/ Mongo/csot_timeout_holder.rb', line 72 def timeout_expired? if 超时? Utils.monotic_time >= 截止日期 else false end end |