net.sourceforge.domian.repository
Class AbstractXStreamXmlFileRepository<T extends Entity>

java.lang.Object
  extended by net.sourceforge.domian.repository.AbstractRepository<T>
      extended by net.sourceforge.domian.repository.AbstractDomianCoreRepository<T>
          extended by net.sourceforge.domian.repository.AbstractXStreamXmlFileRepository<T>
All Implemented Interfaces:
HumanReadableFormatRepository<T>, PersistentRepository<T>, Repository<T>, TextualFormatRepository<T>
Direct Known Subclasses:
AbstractXStreamSingleXmlFileRepository, AbstractXStreamXmlFilePerEntityRepository

abstract class AbstractXStreamXmlFileRepository<T extends Entity>
extends AbstractDomianCoreRepository<T>
implements HumanReadableFormatRepository<T>

Common functionality for all Domian XStream-based repositories, e.g. an extensive set of Synchronizer convenience methods.

File encoding UTF-8 is defined in this class.

Since:
0.4
Author:
Eirik Torske

Field Summary
private static int ALL_STACKTRACE_LINES
           
private  java.lang.Integer maxNumberOfRetries
          When using the *WithRetry methods, this value defines the maximum number of times an operation will be retried.
protected  java.lang.String repositoryId
          The repository-ID the name of the repository.
protected  java.lang.String repositoryRootPath
          For file-based repositories the repositoryRootPath is the absolute path for all repositories of the same type.
private  java.lang.Integer retryTimeoutInMilliseconds
          When using the *WithRetry methods, this value defines the timeout for all retried operations.
protected static java.lang.String XSTREAM_XML_FILE_SUFFIX
           
 
Fields inherited from class net.sourceforge.domian.repository.AbstractDomianCoreRepository
DEFAULT_DOMIAN_ROOT_DIR_NAME, DEFAULT_DOMIAN_ROOT_PATH, log, synchronizer
 
Fields inherited from class net.sourceforge.domian.repository.AbstractRepository
supportsRecursiveIndexing, usesNativePartitioningSupport
 
Constructor Summary
AbstractXStreamXmlFileRepository()
           
 
Method Summary
protected  void call(java.util.concurrent.Callable<T> callable)
          Added for completeness.
protected
<T> T
callConcurrently(java.util.concurrent.Callable<T> callable)
          Convenience method for running a Callable in a concurrent manner.
protected
<T> T
callConcurrentlyInNewThread(java.util.concurrent.Callable<T> callable)
           
protected
<T> T
callConcurrentlyWithRetry(java.util.concurrent.Callable<T> callable)
          Convenience method for running a Callable in a concurrent manner.
protected
<T> T
callExclusively(java.util.concurrent.Callable<T> callable)
          Convenience method for running a Callable in an exclusively manner.
protected
<T> T
callExclusivelyInNewThread(java.util.concurrent.Callable<T> callable)
           
protected
<T> T
callExclusivelyWithRetry(java.util.concurrent.Callable<T> callable)
          Convenience method for running a Callable in an exclusively manner.
 java.lang.String getEncoding()
           
 java.lang.Integer getMaxNumberOfRetries()
           
 java.io.File getRepositoryDirectory()
           
 java.lang.String getRepositoryId()
           
protected  java.lang.String getRepositoryPath(java.lang.String repositoryRootPath, PersistentRepository<T> repository)
           
 java.lang.String getRepositoryPathString()
           
 java.lang.String getRepositoryRootPath()
           
 java.lang.Integer getRetryTimeoutInMilliseconds()
           
private
<T> T
retry(java.util.concurrent.Callable<T> callable, java.lang.Exception retryReason, Synchronizer.MODE synchronizedMode)
          Executes the given Callable in a fresh thread, with time-out set to retryTimeoutInMilliseconds.
private
<T> T
retry(java.lang.String methodName, java.util.concurrent.Callable<T> callable, java.lang.Exception reasonForRetry, Synchronizer.MODE synchronizedMode)
          Executes the given Callable in a fresh thread, with time-out set to retryTimeoutInMilliseconds.
protected  void run(java.lang.Runnable runnable)
          Added for completeness.
protected  void runAsynchronously(java.lang.Runnable runnable)
          Executes the given Runnable in a fresh and independent thread.
protected  void runConcurrently(java.lang.Runnable runnable)
          Convenience method for running a Runnable in a concurrent manner.
 void setMaxNumberOfRetries(java.lang.Integer maxNumberOfRetries)
           
 void setRetryTimeoutInMilliseconds(java.lang.Integer retryTimeoutInMilliseconds)
           
 
Methods inherited from class net.sourceforge.domian.repository.AbstractDomianCoreRepository
, createUniqueSpecificationFor, getSynchronizer, makePartition, onMakePartition, setSynchronizer
 
Methods inherited from class net.sourceforge.domian.repository.AbstractRepository
contains, count, countAll, countAllEntitiesSpecifiedBy, find, findAll, findSingle, findSingleEntitySpecifiedBy, isIndexingEntitiesRecursively, isPartitioningNatively, iterate, iterateAll, putAll, remove, removeAll, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sourceforge.domian.repository.PersistentRepository
close, getFormat, getMetaDataFor, getPersistenceDefinition, load, persist
 
Methods inherited from interface net.sourceforge.domian.repository.Repository
count, countAll, countAllEntitiesSpecifiedBy, find, findAll, findAllEntitiesSpecifiedBy, findSingle, findSingleEntitySpecifiedBy, isIndexingEntitiesRecursively, isPartitioningNatively, iterate, iterateAll, iterateAllEntitiesSpecifiedBy, makePartition, put, putAll, remove, remove, removeAll, removeAllEntitiesSpecifiedBy, update, update
 

Field Detail

XSTREAM_XML_FILE_SUFFIX

protected static final java.lang.String XSTREAM_XML_FILE_SUFFIX
See Also:
Constant Field Values

ALL_STACKTRACE_LINES

private static final int ALL_STACKTRACE_LINES
See Also:
Constant Field Values

repositoryRootPath

protected java.lang.String repositoryRootPath
For file-based repositories the repositoryRootPath is the absolute path for all repositories of the same type.


repositoryId

protected java.lang.String repositoryId
The repository-ID the name of the repository. It should be unique within a running system.

For file-based repositories the ${repositoryRootPath}/${repositoryId} forms the absolute folder path in which the repository data resides.


maxNumberOfRetries

private java.lang.Integer maxNumberOfRetries
When using the *WithRetry methods, this value defines the maximum number of times an operation will be retried.

The default value is 2.


retryTimeoutInMilliseconds

private java.lang.Integer retryTimeoutInMilliseconds
When using the *WithRetry methods, this value defines the timeout for all retried operations.

The default value is 500.

Constructor Detail

AbstractXStreamXmlFileRepository

AbstractXStreamXmlFileRepository()
Method Detail

getRepositoryRootPath

public java.lang.String getRepositoryRootPath()

getRepositoryId

public java.lang.String getRepositoryId()
Specified by:
getRepositoryId in interface PersistentRepository<T extends Entity>

getRepositoryPathString

public java.lang.String getRepositoryPathString()

getRepositoryDirectory

public java.io.File getRepositoryDirectory()
Specified by:
getRepositoryDirectory in interface PersistentRepository<T extends Entity>

getMaxNumberOfRetries

public java.lang.Integer getMaxNumberOfRetries()

setMaxNumberOfRetries

public void setMaxNumberOfRetries(java.lang.Integer maxNumberOfRetries)

getRetryTimeoutInMilliseconds

public java.lang.Integer getRetryTimeoutInMilliseconds()

setRetryTimeoutInMilliseconds

public void setRetryTimeoutInMilliseconds(java.lang.Integer retryTimeoutInMilliseconds)

getEncoding

public java.lang.String getEncoding()
Specified by:
getEncoding in interface TextualFormatRepository<T extends Entity>

getRepositoryPath

protected java.lang.String getRepositoryPath(java.lang.String repositoryRootPath,
                                             PersistentRepository<T> repository)
Returns:
the absolute path to the repository location based on root path and the repository ID

run

protected void run(java.lang.Runnable runnable)
Added for completeness.


call

protected void call(java.util.concurrent.Callable<T> callable)
             throws java.lang.Exception
Added for completeness.

Throws:
java.lang.Exception

runConcurrently

protected void runConcurrently(java.lang.Runnable runnable)
Convenience method for running a Runnable in a concurrent manner.

See Also:
Synchronizer

callConcurrently

protected <T> T callConcurrently(java.util.concurrent.Callable<T> callable)
Convenience method for running a Callable in a concurrent manner.

See Also:
Synchronizer

callExclusively

protected <T> T callExclusively(java.util.concurrent.Callable<T> callable)
Convenience method for running a Callable in an exclusively manner.

See Also:
Synchronizer

callConcurrentlyWithRetry

protected <T> T callConcurrentlyWithRetry(java.util.concurrent.Callable<T> callable)
Convenience method for running a Callable in a concurrent manner. If an exception is thrown, the Callable will be immediately retried. The nature of the retries are further defined by the maxNumberOfRetries and retryTimeoutInMilliseconds member values.


callExclusivelyWithRetry

protected <T> T callExclusivelyWithRetry(java.util.concurrent.Callable<T> callable)
Convenience method for running a Callable in an exclusively manner. If an exception is thrown, the Callable will be immediately queued for retrial. The nature of the retries are further defined by the maxNumberOfRetries and retryTimeoutInMilliseconds member values.


callConcurrentlyInNewThread

protected <T> T callConcurrentlyInNewThread(java.util.concurrent.Callable<T> callable)
                                 throws java.util.concurrent.ExecutionException,
                                        java.util.concurrent.TimeoutException,
                                        java.lang.InterruptedException
Throws:
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
java.lang.InterruptedException

callExclusivelyInNewThread

protected <T> T callExclusivelyInNewThread(java.util.concurrent.Callable<T> callable)
                                throws java.util.concurrent.ExecutionException,
                                       java.util.concurrent.TimeoutException,
                                       java.lang.InterruptedException
Throws:
java.util.concurrent.ExecutionException
java.util.concurrent.TimeoutException
java.lang.InterruptedException

runAsynchronously

protected void runAsynchronously(java.lang.Runnable runnable)
Executes the given Runnable in a fresh and independent thread. This method does not block the original thread. The Synchronizer mode is concurrent. (An asynchronous version of Synchronizer in exclusive mode has no meaning, as it is a "stop-the-world" kind of mode.)


retry

private <T> T retry(java.util.concurrent.Callable<T> callable,
                    java.lang.Exception retryReason,
                    Synchronizer.MODE synchronizedMode)
Executes the given Callable in a fresh thread, with time-out set to retryTimeoutInMilliseconds. The Callable will be retried maxNumberOfRetries times.

This method will use an uncapitalized version of the given callable's simple class name as method name.


retry

private <T> T retry(java.lang.String methodName,
                    java.util.concurrent.Callable<T> callable,
                    java.lang.Exception reasonForRetry,
                    Synchronizer.MODE synchronizedMode)
Executes the given Callable in a fresh thread, with time-out set to retryTimeoutInMilliseconds. The Callable will be retried maxNumberOfRetries times.



Copyright © 2008-2010. All Rights Reserved.