com.sleepycat.je.sync
Class SyncProcessor

java.lang.Object
  extended by com.sleepycat.je.sync.SyncProcessor
Direct Known Subclasses:
JDBCSyncProcessor, MobileSyncProcessor

public abstract class SyncProcessor
extends Object

Manages one or more synchronized data sets for a particular external system and processes sync operations. Subclasses of this abstract class are used for specific types of external systems.

This class provides two types of extensibility.

First, it may be extended directly to implement its abstract methods in in order to implement synchronization with an external system that is not supported by one of the built-in SyncProcessor subclasses. Such subclasses may call the writeProcessorMetadata, readProcessorMetadata, writeProcessorTxnData and readProcessorTxnData methods.

Second, a concrete SyncProcessor subclass may itself by extended to override the openChangeReader method to provide a custom source of change set information. Such subclasses may call the writeChangeSetData and readChangeSetData methods.


Field Summary
protected  Environment env
           
protected  EnvironmentImpl envImpl
           
protected  String processorName
           
 
Constructor Summary
protected SyncProcessor(Environment env, String processorName)
          Used by subclasses to create a SyncProcessor.
 
Method Summary
abstract  SyncDataSet addDataSet(String dataSetName, Collection<SyncDatabase> databases)
          Adds a data set that is managed by this processor.
abstract  void cancelSync()
          Cancels a sync operation being performed in another thread.
abstract  Map<String,SyncDataSet> getDataSets()
          Returns all SyncDataSets that are managed by this processor.
 Environment getEnvironment()
          Returns the JE Environment associated with this processor.
 String getName()
          Returns the name of the processor, which is unique among all processors for a JE Environment.
 SyncDB getSyncDB()
           
protected  ChangeReader openChangeReader(String dataSetName, boolean consolidateTransactions, long consolidateMaxMemory)
          Called internally by the SyncProcessor during a sync operation to obtain the set of local changes to be transferred to the external system.
 void readChangeSetData(Transaction txn, String dataSetName, DatabaseEntry data)
          Called internally by the SyncProcessor to read change set data.
<M extends ProcessorMetadata>
M
readProcessorMetadata(Transaction txn)
          Called internally by the SyncProcessor to read processor-specific configuration data, such as connection properties.
protected  void readProcessorTxnData(Transaction txn, String dataSetName, DatabaseEntry data)
          Called internally by the SyncProcessor to read processor-specific transaction data.
protected  void registerDataSet(SyncDataSet dataSet)
          Called internally by the SyncProcessor during a call to addDataSet(java.lang.String, java.util.Collection).
abstract  void removeDataSet(String dataSetName)
          Removes a data set that is managed by this processor.
 void setAddHook(TestHook addHook)
           
 void setRemoveHook(TestHook removeHook)
           
abstract  void sync(ExportConfig exportConfig, ImportConfig importConfig, String... dataSetName)
          Performs a sync operation for the specified SyncDataSets.
abstract  void syncAll(ExportConfig exportConfig, ImportConfig importConfig)
          Performs a sync operation for all SyncDataSets managed by this processor.
protected  void unregisterDataSet(String dataSetName)
          Called internally by the SyncProcessor during a call to removeDataSet(java.lang.String).
 void writeChangeSetData(Transaction txn, String dataSetName, DatabaseEntry data)
          Called internally by the SyncProcessor to write change set data.
<M extends ProcessorMetadata>
void
writeProcessorMetadata(Transaction txn, M metadata)
          Called internally by the SyncProcessor to write processor-specific metadata, including a collection of SyncDataSet objects and processor connection properties.
protected  void writeProcessorTxnData(Transaction txn, String dataSetName, DatabaseEntry data)
          Called internally by the SyncProcessor to write processor-specific transaction data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

env

protected final Environment env

envImpl

protected final EnvironmentImpl envImpl

processorName

protected final String processorName
Constructor Detail

SyncProcessor

protected SyncProcessor(Environment env,
                        String processorName)
Used by subclasses to create a SyncProcessor.

Method Detail

getName

public String getName()
Returns the name of the processor, which is unique among all processors for a JE Environment.


getEnvironment

public Environment getEnvironment()
Returns the JE Environment associated with this processor.


addDataSet

public abstract SyncDataSet addDataSet(String dataSetName,
                                       Collection<SyncDatabase> databases)
Adds a data set that is managed by this processor.

After calling this method, all changes to the JE databases in the data set will be tracked by JE, so they can be exported to the external system during a sync operation. The tracking of changes in the external system, if any, is defined by the SyncProcessor subclass.

The user must ensure that no transactions for the databases in the data set are active during the call to this method. If transactions are active, the results of the first sync operation with respect to these transactions are undefined, and the sync is unlikely to succeed.

Normally, each database in a newly added data set should be initially empty or non-existent. If a database is non-empty, the user must ensure that the records in the database are present in the external system.

Throws:
IllegalStateException - if a data set with the given name already exists.

setAddHook

public void setAddHook(TestHook addHook)

registerDataSet

protected void registerDataSet(SyncDataSet dataSet)
Called internally by the SyncProcessor during a call to addDataSet(java.lang.String, java.util.Collection). This method initializes change tracking for all databases in the data set.

The user should only call this method when extending SyncProcessor directly to implement a custom processor for an external system that is not supported by the built-in SyncProcessor classes.


removeDataSet

public abstract void removeDataSet(String dataSetName)
Removes a data set that is managed by this processor.

Throws:
IllegalStateException - if a data set with the given name does not exist.

setRemoveHook

public void setRemoveHook(TestHook removeHook)

unregisterDataSet

protected void unregisterDataSet(String dataSetName)
Called internally by the SyncProcessor during a call to removeDataSet(java.lang.String). This method will remove the change tracking information for this SyncDataSet from the internal databases.

The user should only call this method when extending SyncProcessor directly to implement a custom processor for an external system that is not supported by the built-in SyncProcessor classes.


getDataSets

public abstract Map<String,SyncDataSet> getDataSets()
Returns all SyncDataSets that are managed by this processor.


syncAll

public abstract void syncAll(ExportConfig exportConfig,
                             ImportConfig importConfig)
                      throws SyncCanceledException
Performs a sync operation for all SyncDataSets managed by this processor.

Throws:
SyncCanceledException

sync

public abstract void sync(ExportConfig exportConfig,
                          ImportConfig importConfig,
                          String... dataSetName)
                   throws SyncCanceledException
Performs a sync operation for the specified SyncDataSets.

Throws:
SyncCanceledException

cancelSync

public abstract void cancelSync()
Cancels a sync operation being performed in another thread. Causes the SyncCancelException to be thrown by the method that invoked the sync.


openChangeReader

protected ChangeReader openChangeReader(String dataSetName,
                                        boolean consolidateTransactions,
                                        long consolidateMaxMemory)
Called internally by the SyncProcessor during a sync operation to obtain the set of local changes to be transferred to the external system.

The user should never have a need to call this method, but may wish to override it as described below.

The default implementation of this method returns a ChangeReader that reads the JE log and keeps track of processed and pending changes automatically. Note that the portion the JE log that contains change sets will be retained (the log cleaner will not delete the log files in this portion of the log) until all changes in that portion of the log are fully processed.

For advanced use, a user may override this method in any SyncProcessor to provide the change set by some other mechanism. For example, if a JE Database is used as an insert-only input queue for data to be transferred to an external system, a ChangeReader could be implemented that uses key ranges to keep track of processed and pending changes, and that reads the records in a key range from the Database, in order to supply the changes to the SyncProcessor. To keep track of change set metadata, a custom implementation may call writeChangeSetData and readChangeSetDat.


writeChangeSetData

public final void writeChangeSetData(Transaction txn,
                                     String dataSetName,
                                     DatabaseEntry data)
Called internally by the SyncProcessor to write change set data.

The user should only call this method when extending a SyncProcessor class to override the openChangeReader method.


readChangeSetData

public final void readChangeSetData(Transaction txn,
                                    String dataSetName,
                                    DatabaseEntry data)
Called internally by the SyncProcessor to read change set data.

The user should only call this method when extending a SyncProcessor class to override the openChangeReader method.


writeProcessorMetadata

public final <M extends ProcessorMetadata> void writeProcessorMetadata(Transaction txn,
                                                                       M metadata)
Called internally by the SyncProcessor to write processor-specific metadata, including a collection of SyncDataSet objects and processor connection properties.

The user should only call this method when extending SyncProcessor directly to implement a custom processor for an external system that is not supported by the built-in SyncProcessor classes. Such implementations will also normally subclass ProcessorMetadata to add processor specific connection properties and other metadata.


readProcessorMetadata

public final <M extends ProcessorMetadata> M readProcessorMetadata(Transaction txn)
Called internally by the SyncProcessor to read processor-specific configuration data, such as connection properties.

The user should only call this method when extending SyncProcessor directly to implement a custom processor for an external system that is not supported by the built-in SyncProcessor classes.


writeProcessorTxnData

protected final void writeProcessorTxnData(Transaction txn,
                                           String dataSetName,
                                           DatabaseEntry data)
Called internally by the SyncProcessor to write processor-specific transaction data.

The user should only call this method when extending SyncProcessor directly to implement a custom processor for an external system that is not supported by the built-in SyncProcessor classes.


readProcessorTxnData

protected final void readProcessorTxnData(Transaction txn,
                                          String dataSetName,
                                          DatabaseEntry data)
Called internally by the SyncProcessor to read processor-specific transaction data.

The user should only call this method when extending SyncProcessor directly to implement a custom processor for an external system that is not supported by the built-in SyncProcessor classes.


getSyncDB

public SyncDB getSyncDB()


Copyright (c) 2004-2012 Oracle. All rights reserved.