org.neo4j.kernel.impl.transaction.xaframework
Class XaDataSource

java.lang.Object
  extended by org.neo4j.kernel.impl.transaction.xaframework.XaDataSource
Direct Known Subclasses:
LogBackedXaDataSource

public abstract class XaDataSource
extends Object

XaDataSource is as a factory for creating XaConnections.

If you're writing a data source towards a XA compatible resource the implementation should be fairly straight forward. This will basically be a factory for your XaConnections that in turn will wrap the XA compatible XAResource.

If you're writing a data source towards a non XA compatible resource use the XaContainer and extend the XaConnectionHelpImpl as your XaConnection implementation. Here is an example:

 
 public class MyDataSource implements XaDataSource {
     MyDataSource( params ) {
         // ... initalization stuff
         container = XaContainer.create( myLogicalLogFile, myCommandFactory,
             myTransactionFactory );
         // ... more initialization stuff
         container.openLogicalLog();
     }
     public XaConnection getXaCo nnection() {
         return new MyXaConnection( params );
     }
     public void close() {
         // ... cleanup
         container.close();
     }
 }
 
 


Constructor Summary
XaDataSource(Map<?,?> params)
          Constructor used by the Neo4j kernel to create datasources.
 
Method Summary
 void applyCommittedTransaction(long txId, ReadableByteChannel transaction)
           
 long applyPreparedTransaction(ReadableByteChannel transaction)
           
abstract  void close()
          Closes this data source.
 boolean deleteLogicalLog(long version)
          Deletes a log specific logical log.
 byte[] getBranchId()
          Returns any assigned or default branch id for this data source.
 long getCreationTime()
          Returns a timestamp when this data source was created.
 long getCurrentLogVersion()
          Returns the current version of this data source.
 String getFileName(long version)
           
 long getLastCommittedTxId()
           
 LogExtractor getLogExtractor(long startTxId, long endTxIdHint)
           
 ReadableByteChannel getLogicalLog(long version)
          Returns a readable byte channel of the specified logical log.
 long getLogicalLogLength(long version)
           
 Pair<Integer,Long> getMasterForCommittedTx(long txId)
           
 String getName()
          Returns the assigned name of this resource.
 ReadableByteChannel getPreparedTransaction(int identifier)
           
 void getPreparedTransaction(int identifier, LogBuffer targetBuffer)
           
 long getRandomIdentifier()
          Returns a random identifier that gets generated when the data source is created.
abstract  XaConnection getXaConnection()
          Creates a XA connection to the resource this data source represents.
 XaContainer getXaContainer()
           
 boolean hasLogicalLog(long version)
          Tests if a specific logical log exists.
 boolean isLogicalLogKept()
           
 void keepLogicalLogs(boolean keepLogs)
          Sets wether logical logs should be saved upon rotation or not.
 ClosableIterable<File> listStoreFiles(boolean includeLogicalLogs)
           
 long rotateLogicalLog()
          Rotates this logical log.
 void setAutoRotate(boolean rotate)
          Turns off/on auto rotate of logical logs.
 void setBranchId(byte[] branchId)
          Used by the container/transaction manager in place to assign a branch id for this data source.
 void setLastCommittedTxId(long txId)
           
 void setLogicalLogTargetSize(long size)
          Sets the target size of the logical log that will cause a rotation of the log if setAutoRotate(boolean) is set to true.
 void setName(String name)
          Used by the container to assign a name to this resource.
 boolean setRecovered(boolean recovered)
          Returns previous value
protected  Boolean shouldKeepLog(String config, String resourceName)
          If the config says that logical logs should be kept for the given resourceName this method will return true, otherwise false.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XaDataSource

public XaDataSource(Map<?,?> params)
             throws InstantiationException
Constructor used by the Neo4j kernel to create datasources.

Parameters:
params - A map containing configuration parameters
Throws:
InstantiationException
Method Detail

getXaConnection

public abstract XaConnection getXaConnection()
Creates a XA connection to the resource this data source represents.

Returns:
A connection to an XA resource

close

public abstract void close()
Closes this data source. Calling getXaConnection after this method has been invoked is illegal.


setBranchId

public void setBranchId(byte[] branchId)
Used by the container/transaction manager in place to assign a branch id for this data source.

Parameters:
branchId - the branch id

getBranchId

public byte[] getBranchId()
Returns any assigned or default branch id for this data source.

Returns:
the branch id

getCreationTime

public long getCreationTime()
Returns a timestamp when this data source was created. Note this is not the timestamp for the creation of the data source object instance, if the data source is for example a database timestamp is meant to be when the database was created.

Creation time together with random identifier can be used to uniqley identify a data source (since it is possible to have multiple sources of same type).

Returns:
timestamp when this datasource was created

getFileName

public String getFileName(long version)

getRandomIdentifier

public long getRandomIdentifier()
Returns a random identifier that gets generated when the data source is created. Note with "created" we mean first time data source is created and not object creation.

Creation time together with the random identifier can be used to uniquely identify a data source (since it is possible to have multiple sources of the same type).

Returns:
random identifier for this data source

getCurrentLogVersion

public long getCurrentLogVersion()
Returns the current version of this data source. A invoke to the rotateLogicalLog() when keepLogicalLogs(boolean) is set to true will result in a log with that version created.

Returns:
the current version of the logical log

rotateLogicalLog

public long rotateLogicalLog()
                      throws IOException
Rotates this logical log. If keepLogicalLogs(boolean) is configured to true the log will be saved and can be retrieved with the getLogicalLog(long) method. If not it will be deleted. Active transactions get copied to a new logical log.

Throws:
IOException - if unable to read old log or write to new one

getLogicalLog

public ReadableByteChannel getLogicalLog(long version)
                                  throws IOException
Returns a readable byte channel of the specified logical log.

Parameters:
version - version of the logical log
Returns:
readable byte channel of the logical log
Throws:
IOException - if no such log exist

hasLogicalLog

public boolean hasLogicalLog(long version)
Tests if a specific logical log exists.

Parameters:
version - the version of the logical log
Returns:
true if the log exists

getLogicalLogLength

public long getLogicalLogLength(long version)

deleteLogicalLog

public boolean deleteLogicalLog(long version)
Deletes a log specific logical log.

Parameters:
version - version of log to delete
Returns:
true if the log existed and was deleted

keepLogicalLogs

public void keepLogicalLogs(boolean keepLogs)
Sets wether logical logs should be saved upon rotation or not. Default is false.

Parameters:
keepLogs - true means save, false means delete

isLogicalLogKept

public boolean isLogicalLogKept()

setName

public void setName(String name)
Used by the container to assign a name to this resource.

Parameters:
name - name of this resource

getName

public String getName()
Returns the assigned name of this resource.

Returns:
the assigned name of this resource

setAutoRotate

public void setAutoRotate(boolean rotate)
Turns off/on auto rotate of logical logs. Default is true.

Parameters:
rotate - true to turn on

setLogicalLogTargetSize

public void setLogicalLogTargetSize(long size)
Sets the target size of the logical log that will cause a rotation of the log if setAutoRotate(boolean) is set to true.

Parameters:
size - target size in bytes

shouldKeepLog

protected Boolean shouldKeepLog(String config,
                                String resourceName)
If the config says that logical logs should be kept for the given resourceName this method will return true, otherwise false. The format of the configuration value is either: The first and last are recommended, since the data source names are really an implementation detail.

Parameters:
config - the configuration value specified by user configuration.
resourceName - the name of the xa data source to check.
Returns:
whether or not logical logs should be kept for the data source by the name resourceName or not. Or null if not specified.

getPreparedTransaction

public ReadableByteChannel getPreparedTransaction(int identifier)
                                           throws IOException
Throws:
IOException

getPreparedTransaction

public void getPreparedTransaction(int identifier,
                                   LogBuffer targetBuffer)
                            throws IOException
Throws:
IOException

applyCommittedTransaction

public void applyCommittedTransaction(long txId,
                                      ReadableByteChannel transaction)
                               throws IOException
Throws:
IOException

applyPreparedTransaction

public long applyPreparedTransaction(ReadableByteChannel transaction)
                              throws IOException
Throws:
IOException

getLastCommittedTxId

public long getLastCommittedTxId()

setLastCommittedTxId

public void setLastCommittedTxId(long txId)

getXaContainer

public XaContainer getXaContainer()

getMasterForCommittedTx

public Pair<Integer,Long> getMasterForCommittedTx(long txId)
                                           throws IOException
Throws:
IOException

listStoreFiles

public ClosableIterable<File> listStoreFiles(boolean includeLogicalLogs)
                                      throws IOException
Throws:
IOException

setRecovered

public boolean setRecovered(boolean recovered)
Returns previous value


getLogExtractor

public LogExtractor getLogExtractor(long startTxId,
                                    long endTxIdHint)
                             throws IOException
Throws:
IOException


Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.