com.continuent.tungsten.replicator.thl
Class RemoteTHLExtractor

java.lang.Object
  extended by com.continuent.tungsten.replicator.thl.RemoteTHLExtractor
All Implemented Interfaces:
Extractor, ReplicatorPlugin, ShutdownHook

public class RemoteTHLExtractor
extends java.lang.Object
implements Extractor, ShutdownHook

Implements an extractor to pull events from a remote THL.

This class has specialized concurrency requirements as there is a potential race condition to close connections within the task thread and thread trying to shut down the pipeline. The race arises due the fact that connections may hang when connecting or reading from a connection to a dropped interface and do not accept interrupts. They need to be interrupted by closing the connection. For this reason, closing the connection is synchronized.

Version:
1.0
Author:
Robert Hodges

Constructor Summary
RemoteTHLExtractor()
          Create Connector instance.
 
Method Summary
 void configure(PluginContext context)
          Complete plug-in configuration.
 ReplDBMSEvent extract()
          Extract the next available event from the log.
 java.util.List<java.lang.String> getConnectUri()
           
 java.lang.String getCurrentResourceEventId()
          Does not make sense for this extractor type.
 int getHeartbeatInterval()
           
 java.lang.String getPreferredRole()
          Returns the preferred master server role.
 int getPreferredRoleTimeout()
           
 int getResetPeriod()
           
 int getRetryInterval()
           
 boolean hasMoreEvents()
          Returns true if there are additional events that may be read as part of block commit processing.
 boolean isCheckSerialization()
           
 void prepare(PluginContext context)
          Prepare plug-in for use.
 void release(PluginContext context)
          Release all resources used by plug-in.
 void setCheckSerialization(boolean checkSerialization)
          If true, check epoch number and sequence number of last event we have received.
 void setConnectUri(java.util.List<java.lang.String> connectUri)
          Set the URI(s) of the store to which we connect.
 void setHeartbeatInterval(int heartbeatMillis)
          Sets the interval for sending heartbeat events from server to avoid TCP/IP timeout on server connection.
 void setLastEvent(ReplDBMSHeader event)
          Set the value of the last event called.
 void setLastEventId(java.lang.String eventId)
          Sets the last event ID for extraction.
 void setPreferredRole(java.lang.String preferredRole)
          Sets the preferred role of the master replicator.
 void setPreferredRoleTimeout(int preferredRoleTimeout)
          Sets the timeout to find the preferred master role in seconds.
 void setResetPeriod(int resetPeriod)
          Set the number of iterations before resetting the communications stream.
 void setRetryInterval(int retryTimeout)
          Sets the timeout between connection retries in seconds.
 void shutdown(PluginContext context)
          Shut down component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RemoteTHLExtractor

public RemoteTHLExtractor()
Create Connector instance.

Method Detail

getConnectUri

public java.util.List<java.lang.String> getConnectUri()

setConnectUri

public void setConnectUri(java.util.List<java.lang.String> connectUri)
Set the URI(s) of the store to which we connect.

Parameters:
connectUri -

getResetPeriod

public int getResetPeriod()

setResetPeriod

public void setResetPeriod(int resetPeriod)
Set the number of iterations before resetting the communications stream. Higher values use more memory but are more efficient.


isCheckSerialization

public boolean isCheckSerialization()

setCheckSerialization

public void setCheckSerialization(boolean checkSerialization)
If true, check epoch number and sequence number of last event we have received.

Parameters:
checkSerialization -

getHeartbeatInterval

public int getHeartbeatInterval()

setHeartbeatInterval

public void setHeartbeatInterval(int heartbeatMillis)
Sets the interval for sending heartbeat events from server to avoid TCP/IP timeout on server connection. The normal read timeout is 10x this value. The value is also used for connection timeouts, where we use 1x this value.


getPreferredRole

public java.lang.String getPreferredRole()
Returns the preferred master server role.


setPreferredRole

public void setPreferredRole(java.lang.String preferredRole)
Sets the preferred role of the master replicator. If set to 'slave' we will try to find a slave from the URL list before accepting a master.


getPreferredRoleTimeout

public int getPreferredRoleTimeout()

setPreferredRoleTimeout

public void setPreferredRoleTimeout(int preferredRoleTimeout)
Sets the timeout to find the preferred master role in seconds.


getRetryInterval

public int getRetryInterval()

setRetryInterval

public void setRetryInterval(int retryTimeout)
Sets the timeout between connection retries in seconds.


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
Does not make sense for this extractor type.

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

hasMoreEvents

public boolean hasMoreEvents()
Description copied from interface: Extractor
Returns true if there are additional events that may be read as part of block commit processing.

Specified by:
hasMoreEvents in interface Extractor

setLastEvent

public void setLastEvent(ReplDBMSHeader event)
                  throws ReplicatorException
Description copied from interface: Extractor
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:
event - Last event we extracted
Throws:
ReplicatorException

setLastEventId

public void setLastEventId(java.lang.String eventId)
                    throws ReplicatorException
Sets the last event ID for extraction. If this is set, we will request (and receive) the first event from the master log that matches this event.

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
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)

shutdown

public void shutdown(PluginContext context)
              throws ReplicatorException,
                     java.lang.InterruptedException
Shut down component. This is called after the task interrupt and should ensure the component responds correctly to an interrupt.

Specified by:
shutdown in interface ShutdownHook
Throws:
ReplicatorException - Thrown if shutdown is unsuccessful
java.lang.InterruptedException
See Also:
ShutdownHook.shutdown(com.continuent.tungsten.replicator.plugin.PluginContext)