Class GammaStm.GammaTxnFactoryBuilderImpl
- All Implemented Interfaces:
TxnFactoryBuilder, GammaTxnFactoryBuilder
- Enclosing class:
GammaStm
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddPermanentListener(TxnListener listener) Adds a permanentTxnTxnListener.final GammaTxnConfigReturns theTxnConfigused by this TxnFactoryBuilder.private booleanisLean()Builds a newTxnFactory.final GammaTxnExecutorBuilds a newTxnExecutoroptimized for executing transactions created by this TxnFactoryBuilder.final GammaTxnFactoryBuildersetBackoffPolicy(BackoffPolicy backoffPolicy) Sets theTxnBackoffPolicy.final GammaTxnFactoryBuildersetBlockingAllowed(boolean blockingAllowed) Sets if theTxnis allowed to do an explicit retry (needed for a blocking operation).final GammaTxnFactoryBuildersetControlFlowErrorsReused(boolean reused) Sets if theControlFlowErroris reused.final GammaTxnFactoryBuildersetDirtyCheckEnabled(boolean dirtyCheckEnabled) Sets if theTxndirty check is enabled.final GammaTxnFactoryBuildersetFamilyName(String familyName) Sets theTxnfamilyname.final GammaTxnFactoryBuildersetFat()final GammaTxnFactoryBuildersetInterruptible(boolean interruptible) Sets if theTxncan be interrupted while doing blocking operations.final GammaTxnFactoryBuildersetIsolationLevel(IsolationLevel isolationLevel) Sets theIsolationLevelon theTxn.final GammaTxnFactoryBuildersetMaxRetries(int maxRetries) Sets the the maximum count aTxncan be retried.final GammaTxnFactoryBuilderSets thePropagationLevelused.final GammaTxnFactoryBuildersetReadLockMode(LockMode lockMode) final GammaTxnFactoryBuildersetReadonly(boolean readonly) Sets the readonly property on aTxn.final GammaTxnFactoryBuildersetReadTrackingEnabled(boolean enabled) Sets if theTxnshould automatically track all reads that have been done.final GammaTxnFactoryBuildersetSpeculative(boolean enabled) final GammaTxnFactoryBuildersetSpinCount(int spinCount) Sets the maximum number of spins that are allowed when aTxncan't be read/written/locked because it is locked by another transaction.final GammaTxnFactoryBuildersetTimeoutNs(long timeoutNs) Sets the timeout (the maximum time aTxnis allowed to block.final GammaTxnFactoryBuildersetTraceLevel(TraceLevel traceLevel) Sets theTxnTraceLevel.final GammaTxnFactoryBuildersetWriteLockMode(LockMode lockMode)
-
Field Details
-
config
-
-
Constructor Details
-
GammaTxnFactoryBuilderImpl
GammaTxnFactoryBuilderImpl(GammaTxnConfig config)
-
-
Method Details
-
setFat
- Specified by:
setFatin interfaceGammaTxnFactoryBuilder
-
getConfig
Description copied from interface:TxnFactoryBuilderReturns theTxnConfigused by this TxnFactoryBuilder.- Specified by:
getConfigin interfaceGammaTxnFactoryBuilder- Specified by:
getConfigin interfaceTxnFactoryBuilder- Returns:
- the used TxnConfig.
-
addPermanentListener
Description copied from interface:TxnFactoryBuilderAdds a permanentTxnTxnListener. All permanent listeners are always executed after all normal listeners are executed. If the same listener is added multiple times, it will be executed multiple times.This method is very useful for integrating Multiverse in other JVM based environments because with this approach you have a callback when transaction aborts/commit and can add your own logic. See the
TxnListenerfor more information about normal vs permanent listeners.- Specified by:
addPermanentListenerin interfaceGammaTxnFactoryBuilder- Specified by:
addPermanentListenerin interfaceTxnFactoryBuilder- Parameters:
listener- the permanent listener to add.- Returns:
- the updated TxnFactoryBuilder.
- See Also:
-
setControlFlowErrorsReused
Description copied from interface:TxnFactoryBuilderSets if theControlFlowErroris reused. Normally you don't want to reuse them because they can be expensive to create (especially the stacktrace) and they could be created very often. But for debugging purposes it can be quite annoying because you want to see the stacktrace.- Specified by:
setControlFlowErrorsReusedin interfaceGammaTxnFactoryBuilder- Specified by:
setControlFlowErrorsReusedin interfaceTxnFactoryBuilder- Parameters:
reused- true if ControlFlowErrors should be reused.- Returns:
- the updated TxnFactoryBuilder.
- See Also:
-
setReadLockMode
Description copied from interface:TxnFactoryBuilderSets theTxnLockModefor all reads. If a LockMode is set higher thanLockMode.None, this transaction will locks all reads (and writes since a read is needed for a write) and the transaction automatically becomes serialized.- Specified by:
setReadLockModein interfaceGammaTxnFactoryBuilder- Specified by:
setReadLockModein interfaceTxnFactoryBuilder- Parameters:
lockMode- the LockMode to set.- Returns:
- the updated TxnFactoryBuilder.
- See Also:
-
setWriteLockMode
Description copied from interface:TxnFactoryBuilderSets theTxnLockModefor all writes. For a write, always a read needs to be done, so if the read LockMode isFreshly constructed objects that are not committed, automatically are locked with
LockMode.Exclusive.If the write LockMode is set after the read LockMode and the write LockMode is lower than the read LockMode, an
IllegalTxnFactoryExceptionwill be thrown when aTxnFactoryis created.If the write LockMode is set before the read LockMode and the write LockMode is lower than the read LockMode, the write LockMode automatically is upgraded to that of the read LockMode. This makes setting the readLock mode less of a nuisance.
- Specified by:
setWriteLockModein interfaceGammaTxnFactoryBuilder- Specified by:
setWriteLockModein interfaceTxnFactoryBuilder- Parameters:
lockMode- the LockMode to set.- Returns:
- the updated TxnFactoryBuilder.
- See Also:
-
setFamilyName
Description copied from interface:TxnFactoryBuilderSets theTxnfamilyname. If anTxnExecutoris used inside a method, a useful familyname could be the full name of the class and the method. The transaction familyName is useful debugging purposes, but has not other meaning.- Specified by:
setFamilyNamein interfaceGammaTxnFactoryBuilder- Specified by:
setFamilyNamein interfaceTxnFactoryBuilder- Parameters:
familyName- the familyName of the transaction.- Returns:
- the updated TxnFactoryBuilder
- See Also:
-
setPropagationLevel
Description copied from interface:TxnFactoryBuilderSets thePropagationLevelused. With the PropagationLevel you have control on how the transaction deals with transaction nesting. The default isPropagationLevel.Requireswhich automatically starts a transaction is one is missing, or lifts on a transaction if available.- Specified by:
setPropagationLevelin interfaceGammaTxnFactoryBuilder- Specified by:
setPropagationLevelin interfaceTxnFactoryBuilder- Parameters:
level- the new PropagationLevel- Returns:
- the updated TxnFactoryBuilder
- See Also:
-
setBlockingAllowed
Description copied from interface:TxnFactoryBuilderSets if theTxnis allowed to do an explicit retry (needed for a blocking operation). One use case for disallowing it, it when the transaction is used inside an actor, and you don't want that inside the logic executed by the agent a blocking operations is done (e.g. taking an item of a blocking queue).- Specified by:
setBlockingAllowedin interfaceGammaTxnFactoryBuilder- Specified by:
setBlockingAllowedin interfaceTxnFactoryBuilder- Parameters:
blockingAllowed- true if explicit retry is allowed, false otherwise.- Returns:
- the updated TxnFactoryBuilder
-
setIsolationLevel
Description copied from interface:TxnFactoryBuilderSets theIsolationLevelon theTxn.The
Txnis free to upgraded to a higherIsolationLevel. This is essentially the same behavior you get when Oracle is used, where a read uncommitted is upgraded to a read committed and a repeatable read is upgraded to the Oracle version of serialized (so with the writeskew problem still there).- Specified by:
setIsolationLevelin interfaceGammaTxnFactoryBuilder- Specified by:
setIsolationLevelin interfaceTxnFactoryBuilder- Parameters:
isolationLevel- the new IsolationLevel- Returns:
- the updated TxnFactoryBuilder
- See Also:
-
setTraceLevel
Description copied from interface:TxnFactoryBuilderSets theTxnTraceLevel. With tracing it is possible to see what is happening inside a transaction.- Specified by:
setTraceLevelin interfaceGammaTxnFactoryBuilder- Specified by:
setTraceLevelin interfaceTxnFactoryBuilder- Parameters:
traceLevel- the new traceLevel.- Returns:
- the updated TxnFactoryBuilder.
- See Also:
-
setTimeoutNs
Description copied from interface:TxnFactoryBuilderSets the timeout (the maximum time aTxnis allowed to block. Long.MAX_VALUE indicates that an unbound timeout should be used.- Specified by:
setTimeoutNsin interfaceGammaTxnFactoryBuilder- Specified by:
setTimeoutNsin interfaceTxnFactoryBuilder- Parameters:
timeoutNs- the timeout specified in nano seconds- Returns:
- the updated TxnFactoryBuilder
- See Also:
-
setInterruptible
Description copied from interface:TxnFactoryBuilderSets if theTxncan be interrupted while doing blocking operations.- Specified by:
setInterruptiblein interfaceGammaTxnFactoryBuilder- Specified by:
setInterruptiblein interfaceTxnFactoryBuilder- Parameters:
interruptible- if the transaction can be interrupted while doing blocking operations.- Returns:
- the updated TxnFactoryBuilder
- See Also:
-
setBackoffPolicy
Description copied from interface:TxnFactoryBuilderSets theTxnBackoffPolicy. Policy is used to backoff when a transaction conflicts with anotherTxn. See theBackoffPolicyfor more information.- Specified by:
setBackoffPolicyin interfaceGammaTxnFactoryBuilder- Specified by:
setBackoffPolicyin interfaceTxnFactoryBuilder- Parameters:
backoffPolicy- the backoff policy to use.- Returns:
- the updated TxnFactoryBuilder
- See Also:
-
setDirtyCheckEnabled
Description copied from interface:TxnFactoryBuilderSets if theTxndirty check is enabled. Dirty check is that something only needs to be written, if there really is a change (else it will be interpreted as a read). If it is disabled, it will always write, and this could prevent the aba isolation anomaly, but causes more conflicts so more contention. In most cases enabling it is the best option.- Specified by:
setDirtyCheckEnabledin interfaceGammaTxnFactoryBuilder- Specified by:
setDirtyCheckEnabledin interfaceTxnFactoryBuilder- Parameters:
dirtyCheckEnabled- true if dirty check should be executed, false otherwise.- Returns:
- the updated TxnFactoryBuilder.
- See Also:
-
setSpinCount
Description copied from interface:TxnFactoryBuilderSets the maximum number of spins that are allowed when aTxncan't be read/written/locked because it is locked by another transaction.Setting the value to a very high value, could lead to more an increased chance of a live locking.
- Specified by:
setSpinCountin interfaceGammaTxnFactoryBuilder- Specified by:
setSpinCountin interfaceTxnFactoryBuilder- Parameters:
spinCount- the maximum number of spins- Returns:
- the updated TxnFactoryBuilder.
- See Also:
-
setSpeculative
Description copied from interface:TxnFactoryBuilderWith the speculative configuration enabled, theStmis allowed to determine optimal settings for aTxn.Some behavior like readonly or the need for tracking reads can be determined runtime. The system can start with a readonly non readtracking transaction and upgrade to an update or a read tracking once a write or retry happens.
It depends on the
Stmimplementation on which properties it is going to speculate.Enabling it can cause a few unexpected 'retries' of transactions, but it can seriously improve performance.
- Specified by:
setSpeculativein interfaceGammaTxnFactoryBuilder- Specified by:
setSpeculativein interfaceTxnFactoryBuilder- Parameters:
enabled- indicates if speculative configuration should be enabled.- Returns:
- the updated TxnFactoryBuilder
- See Also:
-
setReadonly
Description copied from interface:TxnFactoryBuilderSets the readonly property on aTxn. If a transaction is configured as readonly, no write operations (also no construction of new transactional objects making use of that transaction) is allowed- Specified by:
setReadonlyin interfaceGammaTxnFactoryBuilder- Specified by:
setReadonlyin interfaceTxnFactoryBuilder- Parameters:
readonly- true if the transaction should be readonly, false otherwise.- Returns:
- the updated TxnFactoryBuilder
- See Also:
-
setReadTrackingEnabled
Description copied from interface:TxnFactoryBuilderSets if theTxnshould automatically track all reads that have been done. This is needed for blocking operations, but also for other features like writeskew detection.Tracking reads puts more pressure on the transaction since it needs to store all reads, but it reduces the chance of read conflicts, since once read from main memory, it can be retrieved from the transaction. The transaction is free to track reads even though this property is disabled.
- Specified by:
setReadTrackingEnabledin interfaceGammaTxnFactoryBuilder- Specified by:
setReadTrackingEnabledin interfaceTxnFactoryBuilder- Parameters:
enabled- true if read tracking enabled, false otherwise.- Returns:
- the updated TxnFactoryBuilder
- See Also:
-
setMaxRetries
Description copied from interface:TxnFactoryBuilderSets the the maximum count aTxncan be retried. The default is 1000. Setting it to a very low value could mean that a transaction can't complete. Setting it to a very high value could lead to live-locking.If the speculative configuration mechanism is enabled (
TxnFactoryBuilder.setSpeculative(boolean)), a few retries are done in the beginning to figure out the best settings.- Specified by:
setMaxRetriesin interfaceGammaTxnFactoryBuilder- Specified by:
setMaxRetriesin interfaceTxnFactoryBuilder- Parameters:
maxRetries- the maximum number of times a transaction can be tried.- Returns:
- the updated TxnFactoryBuilder
- See Also:
-
newTxnExecutor
Description copied from interface:TxnFactoryBuilderBuilds a newTxnExecutoroptimized for executing transactions created by this TxnFactoryBuilder.- Specified by:
newTxnExecutorin interfaceGammaTxnFactoryBuilder- Specified by:
newTxnExecutorin interfaceTxnFactoryBuilder- Returns:
- the created TxnExecutor.
-
isLean
private boolean isLean() -
newTransactionFactory
Description copied from interface:TxnFactoryBuilderBuilds a newTxnFactory.- Specified by:
newTransactionFactoryin interfaceGammaTxnFactoryBuilder- Specified by:
newTransactionFactoryin interfaceTxnFactoryBuilder- Returns:
- the build TxnFactory.
-