private final class GammaStm.GammaTxnFactoryBuilderImpl extends java.lang.Object implements GammaTxnFactoryBuilder
| Modifier and Type | Field and Description |
|---|---|
private GammaTxnConfig |
config |
| Constructor and Description |
|---|
GammaTxnFactoryBuilderImpl(GammaTxnConfig config) |
| Modifier and Type | Method and Description |
|---|---|
GammaTxnFactoryBuilder |
addPermanentListener(TxnListener listener)
Adds a permanent
Txn TxnListener. |
GammaTxnConfig |
getConfig()
Returns the
TxnConfig used by this TxnFactoryBuilder. |
private boolean |
isLean() |
GammaTxnFactory |
newTransactionFactory()
Builds a new
TxnFactory. |
GammaTxnExecutor |
newTxnExecutor()
Builds a new
TxnExecutor optimized for executing transactions created by this TxnFactoryBuilder. |
GammaTxnFactoryBuilder |
setBackoffPolicy(BackoffPolicy backoffPolicy)
Sets the
Txn BackoffPolicy. |
GammaTxnFactoryBuilder |
setBlockingAllowed(boolean blockingAllowed)
Sets if the
Txn is allowed to do an explicit retry (needed for a blocking operation). |
GammaTxnFactoryBuilder |
setControlFlowErrorsReused(boolean reused)
Sets if the
ControlFlowError is reused. |
GammaTxnFactoryBuilder |
setDirtyCheckEnabled(boolean dirtyCheckEnabled)
Sets if the
Txn dirty check is enabled. |
GammaTxnFactoryBuilder |
setFamilyName(java.lang.String familyName)
Sets the
Txn familyname. |
GammaTxnFactoryBuilder |
setFat() |
GammaTxnFactoryBuilder |
setInterruptible(boolean interruptible)
Sets if the
Txn can be interrupted while doing blocking operations. |
GammaTxnFactoryBuilder |
setIsolationLevel(IsolationLevel isolationLevel)
Sets the
IsolationLevel on the Txn. |
GammaTxnFactoryBuilder |
setMaxRetries(int maxRetries)
Sets the the maximum count a
Txn can be retried. |
GammaTxnFactoryBuilder |
setPropagationLevel(PropagationLevel level)
Sets the
PropagationLevel used. |
GammaTxnFactoryBuilder |
setReadLockMode(LockMode lockMode)
|
GammaTxnFactoryBuilder |
setReadonly(boolean readonly)
Sets the readonly property on a
Txn. |
GammaTxnFactoryBuilder |
setReadTrackingEnabled(boolean enabled)
Sets if the
Txn should automatically track all reads that have been done. |
GammaTxnFactoryBuilder |
setSpeculative(boolean enabled)
|
GammaTxnFactoryBuilder |
setSpinCount(int spinCount)
Sets the maximum number of spins that are allowed when a
Txn can't be read/written/locked
because it is locked by another transaction. |
GammaTxnFactoryBuilder |
setTimeoutNs(long timeoutNs)
Sets the timeout (the maximum time a
Txn is allowed to block. |
GammaTxnFactoryBuilder |
setTraceLevel(TraceLevel traceLevel)
Sets the
Txn TraceLevel. |
GammaTxnFactoryBuilder |
setWriteLockMode(LockMode lockMode)
|
private final GammaTxnConfig config
GammaTxnFactoryBuilderImpl(GammaTxnConfig config)
public final GammaTxnFactoryBuilder setFat()
setFat in interface GammaTxnFactoryBuilderpublic final GammaTxnConfig getConfig()
TxnFactoryBuilderTxnConfig used by this TxnFactoryBuilder.getConfig in interface TxnFactoryBuildergetConfig in interface GammaTxnFactoryBuilderpublic GammaTxnFactoryBuilder addPermanentListener(TxnListener listener)
TxnFactoryBuilderTxn TxnListener. 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
TxnListener for more information about normal vs permanent listeners.
addPermanentListener in interface TxnFactoryBuilderaddPermanentListener in interface GammaTxnFactoryBuilderlistener - the permanent listener to add.TxnConfig.getPermanentListeners()public final GammaTxnFactoryBuilder setControlFlowErrorsReused(boolean reused)
TxnFactoryBuilderControlFlowError is 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.setControlFlowErrorsReused in interface TxnFactoryBuildersetControlFlowErrorsReused in interface GammaTxnFactoryBuilderreused - true if ControlFlowErrors should be reused.TxnConfig.isControlFlowErrorsReused()public final GammaTxnFactoryBuilder setReadLockMode(LockMode lockMode)
TxnFactoryBuilderTxn LockMode for all reads. If a LockMode is set higher than LockMode.None, this transaction
will locks all reads (and writes since a read is needed for a write) and the transaction automatically becomes
serialized.setReadLockMode in interface TxnFactoryBuildersetReadLockMode in interface GammaTxnFactoryBuilderlockMode - the LockMode to set.TxnConfig.getReadLockMode(),
LockModepublic final GammaTxnFactoryBuilder setWriteLockMode(LockMode lockMode)
TxnFactoryBuilderTxn LockMode for all writes. For a write, always a read needs to be done, so if the read LockMode is
Freshly 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 IllegalTxnFactoryException will be thrown when a TxnFactory is 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.
setWriteLockMode in interface TxnFactoryBuildersetWriteLockMode in interface GammaTxnFactoryBuilderlockMode - the LockMode to set.TxnConfig.getWriteLockMode(),
LockModepublic final GammaTxnFactoryBuilder setFamilyName(java.lang.String familyName)
TxnFactoryBuilderTxn familyname. If an TxnExecutor is 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.setFamilyName in interface TxnFactoryBuildersetFamilyName in interface GammaTxnFactoryBuilderfamilyName - the familyName of the transaction.TxnConfig.getFamilyName()public final GammaTxnFactoryBuilder setPropagationLevel(PropagationLevel level)
TxnFactoryBuilderPropagationLevel used. With the PropagationLevel you have control
on how the transaction deals with transaction nesting. The default is PropagationLevel.Requires
which automatically starts a transaction is one is missing, or lifts on a transaction if available.setPropagationLevel in interface TxnFactoryBuildersetPropagationLevel in interface GammaTxnFactoryBuilderlevel - the new PropagationLevelTxnConfig.getPropagationLevel(),
PropagationLevelpublic final GammaTxnFactoryBuilder setBlockingAllowed(boolean blockingAllowed)
TxnFactoryBuilderTxn is 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).setBlockingAllowed in interface TxnFactoryBuildersetBlockingAllowed in interface GammaTxnFactoryBuilderblockingAllowed - true if explicit retry is allowed, false otherwise.public final GammaTxnFactoryBuilder setIsolationLevel(IsolationLevel isolationLevel)
TxnFactoryBuilderIsolationLevel on the Txn.
The Txn is free to upgraded to a higher IsolationLevel. 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).
setIsolationLevel in interface TxnFactoryBuildersetIsolationLevel in interface GammaTxnFactoryBuilderisolationLevel - the new IsolationLevelTxnConfig.getIsolationLevel(),
IsolationLevelpublic final GammaTxnFactoryBuilder setTraceLevel(TraceLevel traceLevel)
TxnFactoryBuilderTxn TraceLevel. With tracing it is possible to see what is happening inside a transaction.setTraceLevel in interface TxnFactoryBuildersetTraceLevel in interface GammaTxnFactoryBuildertraceLevel - the new traceLevel.TxnConfig.getTraceLevel(),
TraceLevelpublic final GammaTxnFactoryBuilder setTimeoutNs(long timeoutNs)
TxnFactoryBuilderTxn is allowed to block. Long.MAX_VALUE indicates that an
unbound timeout should be used.setTimeoutNs in interface TxnFactoryBuildersetTimeoutNs in interface GammaTxnFactoryBuildertimeoutNs - the timeout specified in nano secondsTxnConfig.getTimeoutNs(),
Txn.getRemainingTimeoutNs()public final GammaTxnFactoryBuilder setInterruptible(boolean interruptible)
TxnFactoryBuilderTxn can be interrupted while doing blocking operations.setInterruptible in interface TxnFactoryBuildersetInterruptible in interface GammaTxnFactoryBuilderinterruptible - if the transaction can be interrupted while doing blocking operations.TxnConfig.isInterruptible()public final GammaTxnFactoryBuilder setBackoffPolicy(BackoffPolicy backoffPolicy)
TxnFactoryBuilderTxn BackoffPolicy. Policy is used to backoff when a transaction conflicts with another Txn.
See the BackoffPolicy for more information.setBackoffPolicy in interface TxnFactoryBuildersetBackoffPolicy in interface GammaTxnFactoryBuilderbackoffPolicy - the backoff policy to use.TxnConfig.getBackoffPolicy()public final GammaTxnFactoryBuilder setDirtyCheckEnabled(boolean dirtyCheckEnabled)
TxnFactoryBuilderTxn dirty 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.setDirtyCheckEnabled in interface TxnFactoryBuildersetDirtyCheckEnabled in interface GammaTxnFactoryBuilderdirtyCheckEnabled - true if dirty check should be executed, false otherwise.TxnConfig.isDirtyCheckEnabled()public final GammaTxnFactoryBuilder setSpinCount(int spinCount)
TxnFactoryBuilderTxn can'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.
setSpinCount in interface TxnFactoryBuildersetSpinCount in interface GammaTxnFactoryBuilderspinCount - the maximum number of spinsTxnConfig.getSpinCount()public final GammaTxnFactoryBuilder setSpeculative(boolean enabled)
TxnFactoryBuilderStm is allowed to determine optimal settings for
a Txn.
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 Stm implementation on which properties it is going to speculate.
Enabling it can cause a few unexpected 'retries' of transactions, but it can seriously improve performance.
setSpeculative in interface TxnFactoryBuildersetSpeculative in interface GammaTxnFactoryBuilderenabled - indicates if speculative configuration should be enabled.TxnConfig.isSpeculative()public final GammaTxnFactoryBuilder setReadonly(boolean readonly)
TxnFactoryBuilderTxn. If a transaction is configured as readonly, no write operations
(also no construction of new transactional objects making use of that transaction) is allowedsetReadonly in interface TxnFactoryBuildersetReadonly in interface GammaTxnFactoryBuilderreadonly - true if the transaction should be readonly, false otherwise.TxnConfig.isReadonly()public final GammaTxnFactoryBuilder setReadTrackingEnabled(boolean enabled)
TxnFactoryBuilderTxn should 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.
setReadTrackingEnabled in interface TxnFactoryBuildersetReadTrackingEnabled in interface GammaTxnFactoryBuilderenabled - true if read tracking enabled, false otherwise.TxnConfig.isReadTrackingEnabled()public final GammaTxnFactoryBuilder setMaxRetries(int maxRetries)
TxnFactoryBuilderTxn can 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.
setMaxRetries in interface TxnFactoryBuildersetMaxRetries in interface GammaTxnFactoryBuildermaxRetries - the maximum number of times a transaction can be tried.TxnConfig.getMaxRetries()public final GammaTxnExecutor newTxnExecutor()
TxnFactoryBuilderTxnExecutor optimized for executing transactions created by this TxnFactoryBuilder.newTxnExecutor in interface TxnFactoryBuildernewTxnExecutor in interface GammaTxnFactoryBuilderprivate boolean isLean()
public GammaTxnFactory newTransactionFactory()
TxnFactoryBuilderTxnFactory.newTransactionFactory in interface TxnFactoryBuildernewTransactionFactory in interface GammaTxnFactoryBuilder