Class: Mongo::Session::ServerSession Private
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
Dirtyable
|
|
Inherits: | Object |
Defined in: | lib/mongo/session/server_session.rb, lib/mongo/session/server_session/dirtyable.rb |
Overview
An object representing the server-side session.
Constant Summary
-
DASH_REGEX =
Regex for removing dashes from the UUID string.
/\-/.freeze
-
UUID_PACK =
Pack directive for the UUID.
'H*'.freeze
Class Method Summary
-
.new ⇒ ServerSession
constructor
Internal use only
Initialize a
ServerSession
.
Instance Attribute Summary
-
#last_use
readonly
Internal use only
The last time the server session was used.
-
#txn_num
readonly
Internal use only
The current transaction number.
Dirtyable
- Included
#dirty? | Query whether the server session has been marked dirty or not. |
Instance Method Summary
-
#inspect ⇒ String
Internal use only
Get a formatted string for use in inspection.
-
#next_txn_num ⇒ Integer
Internal use only
Increment the current transaction number and return the new value.
-
#session_id ⇒ BSON::Document
Internal use only
The session id of this server session.
-
#set_last_use! ⇒ Time
Internal use only
Update the last_use attribute of the server session to now.
Dirtyable
- Included
#dirty! | Mark the server session as dirty (the default) or clean. |
Instance Attribute Details
#last_use (readonly)
The last time the server session was used.
# File 'lib/mongo/session/server_session.rb', line 45
attr_reader :last_use
#txn_num (readonly)
The current transaction number.
When a transaction is active, all operations in that transaction use the same transaction number. If the entire transaction is restarted (for example, by Session#with_transaction, in which case it would also invoke the block provided to it again), each transaction attempt has its own transaction number.
Transaction number is also used outside of transactions for retryable writes. In this case, each write operation has its own transaction number, but retries of a write operation use the same transaction number as the first write (which is how the server knows that subsequent writes are retries and should be ignored if the first write succeeded on the server but was not read by the client, for example).
# File 'lib/mongo/session/server_session.rb', line 64
attr_reader :txn_num
Instance Method Details
#inspect ⇒ String
Get a formatted string for use in inspection.
# File 'lib/mongo/session/server_session.rb', line 120
def inspect "#<Mongo::Session::ServerSession:0x#{object_id} session_id=#{session_id} last_use=#{@last_use}>" end
#next_txn_num ⇒ Integer
Increment the current transaction number and return the new value.
# File 'lib/mongo/session/server_session.rb', line 108
def next_txn_num @txn_num += 1 end
#session_id ⇒ BSON::Document
The session id of this server session.
# File 'lib/mongo/session/server_session.rb', line 98
def session_id @session_id ||= (bytes = [SecureRandom.uuid.gsub(DASH_REGEX, '')].pack(UUID_PACK) BSON::Document.new(id: BSON::Binary.new(bytes, :uuid))) end
#set_last_use! ⇒ Time
Update the last_use attribute of the server session to now.
# File 'lib/mongo/session/server_session.rb', line 86
def set_last_use! @last_use = Time.now end