Package com.mongodb.session
Interface ClientSession
-
- All Superinterfaces:
AutoCloseable,Closeable
@NotThreadSafe public interface ClientSession extends Closeable
A client session.- Since:
- 3.6
- See Also:
ClientSessionOptions- Since server release
- 3.6
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidadvanceClusterTime(BsonDocument clusterTime)voidadvanceOperationTime(BsonTimestamp operationTime)Set the operation time of the last operation executed in this session.voidclearTransactionContext()Clears the transaction context.voidclose()BsonDocumentgetClusterTime()BsonTimestampgetOperationTime()Gets the operation time of the last operation executed in this session.ClientSessionOptionsgetOptions()Get the options for this session.ObjectgetOriginator()Gets the originator for the session.ServerAddressgetPinnedServerAddress()Get the server address of the pinned mongos on this session.BsonDocumentgetRecoveryToken()Get the recovery token from the latest outcome in a sharded transaction.ServerSessiongetServerSession()BsonTimestampgetSnapshotTimestamp()For internal use only.ObjectgetTransactionContext()Gets the transaction context.booleanisCausallyConsistent()Returns true if operations in this session must be causally consistentvoidsetRecoveryToken(BsonDocument recoveryToken)Set the recovery token.voidsetSnapshotTimestamp(BsonTimestamp snapshotTimestamp)For internal use only.voidsetTransactionContext(ServerAddress address, Object transactionContext)Sets the transaction context.
-
-
-
Method Detail
-
getPinnedServerAddress
@Nullable ServerAddress getPinnedServerAddress()
Get the server address of the pinned mongos on this session. For internal use only.- Returns:
- the server address of the pinned mongos
- Since:
- 3.11
- Since server release
- 4.2
-
getTransactionContext
@Nullable Object getTransactionContext()
Gets the transaction context.For internal use only
- Returns:
- the transaction context
-
setTransactionContext
void setTransactionContext(ServerAddress address, Object transactionContext)
Sets the transaction context.For internal use only
Implementations may place additional restrictions on the type of the transaction context
- Parameters:
address- the server addresstransactionContext- the transaction context, which may be null
-
clearTransactionContext
void clearTransactionContext()
Clears the transaction context.For internal use only
-
getRecoveryToken
@Nullable BsonDocument getRecoveryToken()
Get the recovery token from the latest outcome in a sharded transaction. For internal use only.- Returns:
- the recovery token
- Since:
- 3.11
- Since server release
- 4.2
-
setRecoveryToken
void setRecoveryToken(BsonDocument recoveryToken)
Set the recovery token. For internal use only.- Parameters:
recoveryToken- the recovery token- Since:
- 3.11
- Since server release
- 4.2
-
getOptions
ClientSessionOptions getOptions()
Get the options for this session.- Returns:
- the options, which may not be null
-
isCausallyConsistent
boolean isCausallyConsistent()
Returns true if operations in this session must be causally consistent- Returns:
- whether operations in this session must be causally consistent.
-
getOriginator
Object getOriginator()
Gets the originator for the session.Important because sessions must only be used by their own originator.
- Returns:
- the sessions originator
-
getServerSession
ServerSession getServerSession()
- Returns:
- the server session
-
getOperationTime
BsonTimestamp getOperationTime()
Gets the operation time of the last operation executed in this session.- Returns:
- the operation time
-
advanceOperationTime
void advanceOperationTime(BsonTimestamp operationTime)
Set the operation time of the last operation executed in this session.- Parameters:
operationTime- the operation time
-
advanceClusterTime
void advanceClusterTime(BsonDocument clusterTime)
- Parameters:
clusterTime- the cluster time to advance to
-
setSnapshotTimestamp
void setSnapshotTimestamp(BsonTimestamp snapshotTimestamp)
For internal use only.- Parameters:
snapshotTimestamp- the snapshot timestamp
-
getSnapshotTimestamp
@Nullable BsonTimestamp getSnapshotTimestamp()
For internal use only.- Returns:
- the snapshot timestamp
-
getClusterTime
BsonDocument getClusterTime()
- Returns:
- the latest cluster time seen by this session
-
close
void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-