Class GammaStm.GammaTxnFactoryBuilderImpl
- java.lang.Object
-
- org.multiverse.stms.gamma.GammaStm.GammaTxnFactoryBuilderImpl
-
- All Implemented Interfaces:
TxnFactoryBuilder,GammaTxnFactoryBuilder
- Enclosing class:
- GammaStm
private final class GammaStm.GammaTxnFactoryBuilderImpl extends java.lang.Object implements GammaTxnFactoryBuilder
-
-
Field Summary
Fields Modifier and Type Field Description private GammaTxnConfigconfig
-
Constructor Summary
Constructors Constructor Description GammaTxnFactoryBuilderImpl(GammaTxnConfig config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GammaTxnFactoryBuilderaddPermanentListener(TxnListener listener)Adds a permanentTxnTxnListener.GammaTxnConfiggetConfig()Returns theTxnConfigused by this TxnFactoryBuilder.private booleanisLean()GammaTxnFactorynewTransactionFactory()Builds a newTxnFactory.GammaTxnExecutornewTxnExecutor()Builds a newTxnExecutoroptimized for executing transactions created by this TxnFactoryBuilder.GammaTxnFactoryBuildersetBackoffPolicy(BackoffPolicy backoffPolicy)Sets theTxnBackoffPolicy.GammaTxnFactoryBuildersetBlockingAllowed(boolean blockingAllowed)Sets if theTxnis allowed to do an explicit retry (needed for a blocking operation).GammaTxnFactoryBuildersetControlFlowErrorsReused(boolean reused)Sets if theControlFlowErroris reused.GammaTxnFactoryBuildersetDirtyCheckEnabled(boolean dirtyCheckEnabled)Sets if theTxndirty check is enabled.GammaTxnFactoryBuildersetFamilyName(java.lang.String familyName)Sets theTxnfamilyname.GammaTxnFactoryBuildersetFat()GammaTxnFactoryBuildersetInterruptible(boolean interruptible)Sets if theTxncan be interrupted while doing blocking operations.GammaTxnFactoryBuildersetIsolationLevel(IsolationLevel isolationLevel)Sets theIsolationLevelon theTxn.GammaTxnFactoryBuildersetMaxRetries(int maxRetries)Sets the the maximum count aTxncan be retried.GammaTxnFactoryBuildersetPropagationLevel(PropagationLevel level)Sets thePropagationLevelused.GammaTxnFactoryBuildersetReadLockMode(LockMode lockMode)GammaTxnFactoryBuildersetReadonly(boolean readonly)Sets the readonly property on aTxn.GammaTxnFactoryBuildersetReadTrackingEnabled(boolean enabled)Sets if theTxnshould automatically track all reads that have been done.GammaTxnFactoryBuildersetSpeculative(boolean enabled)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.GammaTxnFactoryBuildersetTimeoutNs(long timeoutNs)Sets the timeout (the maximum time aTxnis allowed to block.GammaTxnFactoryBuildersetTraceLevel(TraceLevel traceLevel)Sets theTxnTraceLevel.GammaTxnFactoryBuildersetWriteLockMode(LockMode lockMode)
-
-
-
Field Detail
-
config
private final GammaTxnConfig config
-
-
Constructor Detail
-
GammaTxnFactoryBuilderImpl
GammaTxnFactoryBuilderImpl(GammaTxnConfig config)
-
-
Method Detail
-
setFat
public final GammaTxnFactoryBuilder setFat()
- Specified by:
setFatin interfaceGammaTxnFactoryBuilder
-
getConfig
public final GammaTxnConfig getConfig()
Description copied from interface:TxnFactoryBuilderReturns theTxnConfigused by this TxnFactoryBuilder.- Specified by:
getConfigin interfaceGammaTxnFactoryBuilder- Specified by:
getConfigin interfaceTxnFactoryBuilder- Returns:
- the used TxnConfig.
-
addPermanentListener
public GammaTxnFactoryBuilder addPermanentListener(TxnListener listener)
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:
TxnConfig.getPermanentListeners()
-
setControlFlowErrorsReused
public final GammaTxnFactoryBuilder setControlFlowErrorsReused(boolean reused)
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:
TxnConfig.isControlFlowErrorsReused()
-
setReadLockMode
public final GammaTxnFactoryBuilder setReadLockMode(LockMode lockMode)
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:
TxnConfig.getReadLockMode(),LockMode
-
setWriteLockMode
public final GammaTxnFactoryBuilder setWriteLockMode(LockMode lockMode)
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:
TxnConfig.getWriteLockMode(),LockMode
-
setFamilyName
public final GammaTxnFactoryBuilder setFamilyName(java.lang.String familyName)
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:
TxnConfig.getFamilyName()
-
setPropagationLevel
public final GammaTxnFactoryBuilder setPropagationLevel(PropagationLevel level)
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:
TxnConfig.getPropagationLevel(),PropagationLevel
-
setBlockingAllowed
public final GammaTxnFactoryBuilder setBlockingAllowed(boolean blockingAllowed)
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
public final GammaTxnFactoryBuilder setIsolationLevel(IsolationLevel isolationLevel)
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:
TxnConfig.getIsolationLevel(),IsolationLevel
-
setTraceLevel
public final GammaTxnFactoryBuilder setTraceLevel(TraceLevel traceLevel)
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:
TxnConfig.getTraceLevel(),TraceLevel
-
setTimeoutNs
public final GammaTxnFactoryBuilder setTimeoutNs(long timeoutNs)
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:
TxnConfig.getTimeoutNs(),Txn.getRemainingTimeoutNs()
-
setInterruptible
public final GammaTxnFactoryBuilder setInterruptible(boolean interruptible)
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:
TxnConfig.isInterruptible()
-
setBackoffPolicy
public final GammaTxnFactoryBuilder setBackoffPolicy(BackoffPolicy backoffPolicy)
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:
TxnConfig.getBackoffPolicy()
-
setDirtyCheckEnabled
public final GammaTxnFactoryBuilder setDirtyCheckEnabled(boolean dirtyCheckEnabled)
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:
TxnConfig.isDirtyCheckEnabled()
-
setSpinCount
public final GammaTxnFactoryBuilder setSpinCount(int spinCount)
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:
TxnConfig.getSpinCount()
-
setSpeculative
public final GammaTxnFactoryBuilder setSpeculative(boolean enabled)
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:
TxnConfig.isSpeculative()
-
setReadonly
public final GammaTxnFactoryBuilder setReadonly(boolean readonly)
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:
TxnConfig.isReadonly()
-
setReadTrackingEnabled
public final GammaTxnFactoryBuilder setReadTrackingEnabled(boolean enabled)
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:
TxnConfig.isReadTrackingEnabled()
-
setMaxRetries
public final GammaTxnFactoryBuilder setMaxRetries(int maxRetries)
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:
TxnConfig.getMaxRetries()
-
newTxnExecutor
public final GammaTxnExecutor 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
public GammaTxnFactory newTransactionFactory()
Description copied from interface:TxnFactoryBuilderBuilds a newTxnFactory.- Specified by:
newTransactionFactoryin interfaceGammaTxnFactoryBuilder- Specified by:
newTransactionFactoryin interfaceTxnFactoryBuilder- Returns:
- the build TxnFactory.
-
-