com.continuent.tungsten.replicator.extractor
Class ExtractorWrapper

java.lang.Object
  extended by com.continuent.tungsten.replicator.extractor.ExtractorWrapper
All Implemented Interfaces:
Extractor, ReplicatorPlugin

public class ExtractorWrapper
extends java.lang.Object
implements Extractor

This class wraps a basic Extractor so that it returns ReplDBMSEvent values with assigned sequence numbers. It contains logic to recognize that we have failed over; see setLastEvent(ReplDBMSHeader) for more information.

Version:
1.0
Author:
Robert Hodges

Constructor Summary
ExtractorWrapper(RawExtractor extractor)
          Create a new instance to wrap Creates a new ExtractorWrapper object
 
Method Summary
 void configure(PluginContext context)
          Complete plug-in configuration.
 ReplDBMSEvent extract()
          Extracts a raw event and wraps it in a ReplDBMS complete with sequence number, which increments each time we process the last fragment.
 java.lang.String getCurrentResourceEventId()
          Delegates to underlying extractor.
 RawExtractor getExtractor()
          Return wrapped extractor.
 boolean hasMoreEvents()
          Returns false until we implement caching.
 void prepare(PluginContext context)
          Prepare plug-in for use.
 void release(PluginContext context)
          Release all resources used by plug-in.
 void setLastEvent(ReplDBMSHeader header)
          Set the value of the last event called.
 void setLastEventId(java.lang.String eventId)
          Provides a new native event ID that overrides the default value that the extractor would otherwise use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtractorWrapper

public ExtractorWrapper(RawExtractor extractor)
Create a new instance to wrap Creates a new ExtractorWrapper object

Parameters:
extractor - Extractor to be wrapped
Method Detail

getExtractor

public RawExtractor getExtractor()
Return wrapped extractor.


extract

public ReplDBMSEvent extract()
                      throws ReplicatorException,
                             java.lang.InterruptedException
Extracts a raw event and wraps it in a ReplDBMS complete with sequence number, which increments each time we process the last fragment.

Specified by:
extract in interface Extractor
Returns:
next ReplDBMSEvent found in the logs or another ReplEvent subclass containing control data
Throws:
ReplicatorException
java.lang.InterruptedException
See Also:
Extractor.extract()

getCurrentResourceEventId

public java.lang.String getCurrentResourceEventId()
                                           throws ReplicatorException,
                                                  java.lang.InterruptedException
Delegates to underlying extractor. Returns the last event ID committed in a database from which we are extracting. It is used to help synchronize state between the database and the transaction history log. Values returned from this call must correspond with the last extracted DBMSEvent.eventId as follows:
  1. If the returned value is greater than DBMSEvent.eventId, the database has more recent updates
  2. If the returned value is equal to DBMSEvent.eventId, all events have been extracted
It should not be possible to receive a value that is less than the last extracted DBMSEvent.eventId as this implies that the extractor is somehow ahead of the state of the database, which would be inconsistent.

Specified by:
getCurrentResourceEventId in interface Extractor
Returns:
A current event ID that can be compared with event IDs in DBMSEvent or null if this type of extractor does not extract from a database
Throws:
ReplicatorException
java.lang.InterruptedException
See Also:
Extractor.getCurrentResourceEventId()

hasMoreEvents

public boolean hasMoreEvents()
Returns false until we implement caching.

Specified by:
hasMoreEvents in interface Extractor
See Also:
Extractor.hasMoreEvents()

setLastEvent

public void setLastEvent(ReplDBMSHeader header)
                  throws ReplicatorException
Set the value of the last event called. The extractor is responsible for returning the next event in sequence after this one the next time extract() is called.

Specified by:
setLastEvent in interface Extractor
Parameters:
header - Last event we extracted
Throws:
ReplicatorException
See Also:
Extractor.setLastEvent(com.continuent.tungsten.replicator.event.ReplDBMSHeader)

setLastEventId

public void setLastEventId(java.lang.String eventId)
                    throws ReplicatorException
Provides a new native event ID that overrides the default value that the extractor would otherwise use. This call is used to position raw extractors at a specific native event ID in the DBMS log. It can be ignored by other extractors that do not read from a data source.

Specified by:
setLastEventId in interface Extractor
Parameters:
eventId - Event ID at which to begin extracting
Throws:
ReplicatorException
See Also:
Extractor.setLastEventId(java.lang.String)

configure

public void configure(PluginContext context)
               throws ReplicatorException,
                      java.lang.InterruptedException
Complete plug-in configuration. This is called after setters are invoked at the time that the replicator goes through configuration.

Specified by:
configure in interface ReplicatorPlugin
Throws:
ReplicatorException - Thrown if configuration is incomplete or fails
java.lang.InterruptedException
See Also:
ReplicatorPlugin.configure(com.continuent.tungsten.replicator.plugin.PluginContext)

prepare

public void prepare(PluginContext context)
             throws ReplicatorException,
                    java.lang.InterruptedException
Prepare plug-in for use. This method is assumed to allocate all required resources. It is called before the plug-in performs any operations.

Specified by:
prepare in interface ReplicatorPlugin
Throws:
ReplicatorException - Thrown if resource allocation fails
java.lang.InterruptedException
See Also:
ReplicatorPlugin.prepare(com.continuent.tungsten.replicator.plugin.PluginContext)

release

public void release(PluginContext context)
             throws ReplicatorException,
                    java.lang.InterruptedException
Release all resources used by plug-in. This is called before the plug-in is deallocated.

Specified by:
release in interface ReplicatorPlugin
Throws:
ReplicatorException - Thrown if resource deallocation fails
java.lang.InterruptedException
See Also:
ReplicatorPlugin.release(com.continuent.tungsten.replicator.plugin.PluginContext)