org.multiverse.api
Interface TransactionFactoryBuilder<T extends Transaction,B extends TransactionFactoryBuilder>


public interface TransactionFactoryBuilder<T extends Transaction,B extends TransactionFactoryBuilder>

An implementation of the builder design pattern to create a TransactionFactory. This is the place to be for transaction configuration. This approach also gives the freedom to access implementation specific setters by implementing and extending the TransactionFactoryBuilder interface.

Usage

In most cases the TransactionFactoryBuilder will be dropped once the TransactionFactory is created (the TransactionFactory is the one you want to store for later use).

Chained methods

It is important that the returned TransactionFactoryBuilder is used on the 'set' method because TransactionBuilders are immutable. If you don't do this, your transactions don't get the properties you want them to have.

Transaction familyName

The same TransactionFactory instance should not be used as general purpose transaction factory for the entire system. Each location that needs transactions, wants to receive its own TransactionFactory instance because it can be optimization for that specific situation (readonly vs update, automatic readtracking enabled and disabled etc). Besides these static optimizations, the TransactionFactories also are able to do runtime optimizations (like selecting better suiting transaction implementations) based on previous executions. For this to work, the transaction familyName needs to be set.

Default configuration

Default a TransactionFactoryBuilder will be configured with:
  1. readonlyfalse
  2. automatic read trackingtrue
  3. familyName null
  4. maxRetryCount 1000

The big advantage to a builder compared to just adding a big load of parameters or storing these parameters in a datastructure (so object without logic) is that the Stm implementation has a lot more room for adding custom parameters and stm-internal transaction-family related dependencies.

TransactionBuilders are immutable and therefor thread safe to use.

Author:
Peter Veentjer.

Method Summary
 TransactionFactory<T> build()
          Builds a TransactionFactory with the provided configuration.
 B setAutomaticReadTracking(boolean automaticReadTracking)
          If the transaction should automatically track all reads that have been done.
 B setBackoffPolicy(BackoffPolicy backoffPolicy)
          Sets the new backoff policy.
 B setFamilyName(java.lang.String familyName)
          Creates a new TransactionFactoryBuilder based on the this TransactionFactoryBuilder but now configured with the provided familyName.
 B setInterruptible(boolean interruptible)
          Sets if the transaction can be interrupted while doing blocking operations.
 B setMaxRetryCount(int retryCount)
          Sets the the maximum count a transaction can be retried.
 B setPreventWriteSkew(boolean preventWriteSkew)
          If writeskew prevention should be enabled.
 B setReadonly(boolean readonly)
          Creates a new TransactionFactoryBuilder based on the this TransactionFactoryBuilder but now configured with the readonly setting.
 B setSmartTxLengthSelector(boolean smartTxlengthSelector)
          Work around for making sure that on some locations there is a choice for the correct transaction length.
 

Method Detail

setFamilyName

B setFamilyName(java.lang.String familyName)
Creates a new TransactionFactoryBuilder based on the this TransactionFactoryBuilder but now configured with the provided familyName.

The transaction familyName is useful for a lot of reasons. It can be used for identification in logging but also can be used to make optimizations based on the transaction familyName. A stm could decide to return optimized transaction implementations for example.

Parameters:
familyName - the familyName of the transaction.
Returns:
the new TransactionFactoryBuilder

setReadonly

B setReadonly(boolean readonly)
Creates a new TransactionFactoryBuilder based on the this TransactionFactoryBuilder but now configured with the readonly setting. A readonly transaction normally is a lot faster than an update transaction and it also provides protection against unwanted changes.

Parameters:
readonly - true if the transaction should be readonly, false otherwise.
Returns:
the new TransactionFactoryBuilder

setAutomaticReadTracking

B setAutomaticReadTracking(boolean automaticReadTracking)
If the transaction should automatically track all reads that have been done. This is needed for blocking operations, but also for other features like writeskew detection.

Parameters:
automaticReadTracking - true if readtracking enabled, false otherwise.
Returns:
the new TransactionFactoryBuilder

setInterruptible

B setInterruptible(boolean interruptible)
Sets if the transaction can be interrupted while doing blocking operations.

Parameters:
interruptible - if the transaction can be interrupted while doing blocking operations.
Returns:
the new TransactionFactoryBuilder

setSmartTxLengthSelector

B setSmartTxLengthSelector(boolean smartTxlengthSelector)
Work around for making sure that on some locations there is a choice for the correct transaction length. Constructors are not able to deal with retrying tx.

Parameters:
smartTxlengthSelector - indicates if smartTxlength selection should be used.
Returns:
the new TransactionFactoryBuilder

setPreventWriteSkew

B setPreventWriteSkew(boolean preventWriteSkew)
If writeskew prevention should be enabled.

Parameters:
preventWriteSkew - indicates if writeSkews should be prevented.
Returns:
the new TransactionFactoryBuilder

setBackoffPolicy

B setBackoffPolicy(BackoffPolicy backoffPolicy)
Sets the new backoff policy. Policy is used to backoff when a transaction conflicts with another transaction. See the BackoffPolicy for more information.

Parameters:
backoffPolicy - the backoff policy to use.
Returns:
the new TransactionFactoryBuilder
Throws:
java.lang.NullPointerException - if backoffPolicy is null.

setMaxRetryCount

B setMaxRetryCount(int retryCount)
Sets the the maximum count a transaction can be retried. The default is 1000.

Parameters:
retryCount - the maximum number of times a transaction can be tried.
Returns:
the new TransactionFactoryBuilder

build

TransactionFactory<T> build()
Builds a TransactionFactory with the provided configuration.

Returns:
the started Transaction.
Throws:
java.lang.IllegalStateException - if this TransactionFactoryBuilder is not configured correctly and therefor the TransactionFactory can't be created.


Copyright © 2008-2010 Multiverse. All Rights Reserved.