com.continuent.tungsten.replicator.storage
Class InMemoryQueueAdapter

java.lang.Object
  extended by com.continuent.tungsten.replicator.storage.InMemoryQueueAdapter
All Implemented Interfaces:
Applier, Extractor, ReplicatorPlugin

public class InMemoryQueueAdapter
extends java.lang.Object
implements Extractor, Applier

Implements Extractor and Applier interfaces for an in-memory queue.

Version:
1.0
Author:
Robert Hodges

Constructor Summary
InMemoryQueueAdapter()
          Instantiate the adapter.
 
Method Summary
 void apply(ReplDBMSEvent event, boolean doCommit, boolean doRollback, boolean syncTHL)
          Apply the proffered event to the replication target.
 void commit()
          This method is meaningless for an in-memory queue, which is non-transactional.
 void configure(PluginContext context)
          Complete plug-in configuration.
 ReplDBMSEvent extract()
          Extract the next available event from the log.
 java.lang.String getCurrentResourceEventId()
          Returns the last event ID committed in a database from which we are extracting.
 ReplDBMSHeader getLastEvent()
          Return the header, which should have been place here by an extractor during restart.
 java.lang.String getStoreName()
           
 boolean hasMoreEvents()
          Returns true if the queue has more events.
 void prepare(PluginContext context)
          Connect to underlying queue.
 void release(PluginContext context)
          Release all resources used by plug-in.
 void rollback()
          This method is meaningless for an in-memory queue, which is non-transactional.
 void setLastEvent(ReplDBMSHeader header)
          Store the header so that it can be propagated back through the pipeline for restart.
 void setLastEventId(java.lang.String eventId)
          Ignored for now as in-memory queues do not extract.
 void setStoreName(java.lang.String storeName)
           
 void updatePosition(ReplDBMSHeader header, boolean doCommit, boolean syncTHL)
          Update current recovery position but do not apply an event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InMemoryQueueAdapter

public InMemoryQueueAdapter()
Instantiate the adapter.

Method Detail

getStoreName

public java.lang.String getStoreName()

setStoreName

public void setStoreName(java.lang.String storeName)

extract

public ReplDBMSEvent extract()
                      throws ReplicatorException,
                             java.lang.InterruptedException
Extract the next available event from the log.

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
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 true if the queue has more events. Returns true if there are additional events that may be read as part of block commit processing.

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

setLastEvent

public void setLastEvent(ReplDBMSHeader header)
                  throws ReplicatorException
Store the header so that it can be propagated back through the pipeline for restart. 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
Ignored for now as in-memory queues do not extract. 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
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
See Also:
ReplicatorPlugin.configure(com.continuent.tungsten.replicator.plugin.PluginContext)

prepare

public void prepare(PluginContext context)
             throws ReplicatorException
Connect to underlying queue. 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
See Also:
ReplicatorPlugin.prepare(com.continuent.tungsten.replicator.plugin.PluginContext)

release

public void release(PluginContext context)
             throws ReplicatorException
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
See Also:
ReplicatorPlugin.release(com.continuent.tungsten.replicator.plugin.PluginContext)

apply

public void apply(ReplDBMSEvent event,
                  boolean doCommit,
                  boolean doRollback,
                  boolean syncTHL)
           throws ReplicatorException,
                  ConsistencyException,
                  java.lang.InterruptedException
Apply the proffered event to the replication target.

Specified by:
apply in interface Applier
Parameters:
event - Event to be applied
doCommit - Boolean flag indicating whether this is the last part of multipart event
doRollback - Boolean flag indicating whether this transaction should rollback
syncTHL - Should this applier synchronize the trep_commit_seqno table? This should be false for slave.
Throws:
ReplicatorException - Thrown if applier processing fails
ConsistencyException - Thrown if the applier detects that a consistency check has failed
java.lang.InterruptedException - Thrown if the applier is interrupted
See Also:
Applier.apply(ReplDBMSEvent, boolean, boolean, boolean)

updatePosition

public void updatePosition(ReplDBMSHeader header,
                           boolean doCommit,
                           boolean syncTHL)
                    throws ReplicatorException,
                           java.lang.InterruptedException
Update current recovery position but do not apply an event.

Specified by:
updatePosition in interface Applier
Parameters:
header - Header containing seqno, event ID, etc.
doCommit - Boolean flag indicating whether this is the last part of multipart event
syncTHL - Should this applier synchronize the trep_commit_seqno table? This should be false for slave.
Throws:
ReplicatorException - Thrown if applier processing fails
java.lang.InterruptedException - Thrown if the applier is interrupted
See Also:
Applier.updatePosition(com.continuent.tungsten.replicator.event.ReplDBMSHeader, boolean, boolean)

commit

public void commit()
            throws ReplicatorException,
                   java.lang.InterruptedException
This method is meaningless for an in-memory queue, which is non-transactional. Commits current open transaction to ensure data applied up to current point are durable.

Specified by:
commit in interface Applier
Throws:
ReplicatorException - Thrown if applier processing fails
java.lang.InterruptedException - Thrown if the applier is interrupted
See Also:
Applier.commit()

rollback

public void rollback()
              throws java.lang.InterruptedException
This method is meaningless for an in-memory queue, which is non-transactional. Rolls back any current work.

Specified by:
rollback in interface Applier
Throws:
java.lang.InterruptedException
See Also:
Applier.rollback()

getLastEvent

public ReplDBMSHeader getLastEvent()
                            throws ReplicatorException,
                                   java.lang.InterruptedException
Return the header, which should have been place here by an extractor during restart. Return header information corresponding to last committed transaction.

Specified by:
getLastEvent in interface Applier
Returns:
Header data for last committed transaction
Throws:
ReplicatorException - Thrown if getting sequence number fails
java.lang.InterruptedException - Thrown if the applier is interrupted
See Also:
Applier.getLastEvent()