com.continuent.tungsten.replicator.management.tungsten
Class TungstenPlugin

java.lang.Object
  extended by javax.management.NotificationBroadcasterSupport
      extended by com.continuent.tungsten.replicator.management.tungsten.TungstenPlugin
All Implemented Interfaces:
OpenReplicatorPlugin, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter

public class TungstenPlugin
extends javax.management.NotificationBroadcasterSupport
implements OpenReplicatorPlugin

This class defines a ReplicatorManager, which is the starting class for a Tungsten Replicator instance. The ReplicatorManager accepts the following Java properties which may be set prior to startup.

Version:
1.0
Author:
Seppo Jaakola

Field Summary
 
Fields inherited from interface com.continuent.tungsten.replicator.management.OpenReplicatorPlugin
STATUS_APPLIED_LATENCY, STATUS_ERRMSG, STATUS_LAST_APPLIED, STATUS_LAST_RECEIVED, STATUS_LAST_SENT, STATUS_ROLE
 
Constructor Summary
TungstenPlugin()
           
 
Method Summary
 void configure(TungstenProperties properties)
          Read configuration data and configure replication behavior appropriately.
 int consistencyCheck(java.lang.String method, java.lang.String schemaName, java.lang.String tableName, int rowOffset, int rowLimit)
          Initiates consistency check transaction on a given table.
static Table findConsistencyTable(Database conn, java.lang.String replicatorSchema)
          Tries to locate consistency check table.
static int findNextConsistencyId(Database conn, Table ct)
          Finds what ID should be used for the next consistency check.
 java.lang.String flush(long timeout)
          Implements a flush operation to synchronize the state of the database with the replication log and return a comparable event ID that can be used in a wait operation on a slave.
 ReplicatorCapabilities getCapabilities()
          gets the capabilties for the replicator
 ReplicatorRuntime getReplicatorRuntime()
           
 boolean heartbeat(TungstenProperties params)
          Starts a heartbeat event.
 void offline(TungstenProperties params)
          Puts the replicator immediately into the offline state, which turns off replication.
 void offlineDeferred(TungstenProperties params)
          Performs a deferred shutdown.
 void online(TungstenProperties params)
          Puts the replicator into the online state, which turns on replication.
 void prepare(OpenReplicatorContext context)
          Set event dispatcher and instantiate the Tungsten monitor.
 void provision(java.lang.String uri)
          Performs a provision operation.
 int purge(TungstenProperties params)
          Wait for a particular event to be committed on the slave.
 void release()
          Deallocate all resources.
 void setRole(java.lang.String role, java.lang.String uri)
          Sets the replicator role.
 java.util.HashMap<java.lang.String,java.lang.String> status()
          Returns the current replicator status as a set of name-value pairs.
 java.util.List<java.util.Map<java.lang.String,java.lang.String>> statusList(java.lang.String name)
          Returns a list of status instances for a particular list of items.
 boolean waitForAppliedEvent(java.lang.String event, long timeout)
          Wait for a particular event to be applied on the slave.
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TungstenPlugin

public TungstenPlugin()
Method Detail

prepare

public void prepare(OpenReplicatorContext context)
             throws ReplicatorException
Set event dispatcher and instantiate the Tungsten monitor. Prepare plug-in for use. It is invoked once after setters have been invoke but before the plug-in performs any operations and after

Specified by:
prepare in interface OpenReplicatorPlugin
Parameters:
context - Context with access to replicator service resources
Throws:
ReplicatorException - Thrown if resource allocation fails
See Also:
OpenReplicatorPlugin.prepare(OpenReplicatorContext)

release

public void release()
             throws ReplicatorException
Deallocate all resources.

Specified by:
release in interface OpenReplicatorPlugin
Throws:
ReplicatorException - Thrown if resource deallocation fails
See Also:
OpenReplicatorPlugin.release()

consistencyCheck

public int consistencyCheck(java.lang.String method,
                            java.lang.String schemaName,
                            java.lang.String tableName,
                            int rowOffset,
                            int rowLimit)
                     throws java.lang.Exception
Initiates consistency check transaction on a given table.

Specified by:
consistencyCheck in interface OpenReplicatorPlugin
Parameters:
method - consistency check method to use
schemaName - name of the table schema
tableName - name of the table, if null all tables in schema are checked
rowOffset - start consistency check from this row (numeration starts with 0). If negative - whole table is checked.
rowLimit - limit consistency check to that many rows. If rowOffset is negative this is ignored.
Returns:
Executed consistency check's ID.
Throws:
java.lang.Exception
See Also:
OpenReplicatorPlugin.consistencyCheck(java.lang.String, java.lang.String, java.lang.String, int, int)

findConsistencyTable

public static Table findConsistencyTable(Database conn,
                                         java.lang.String replicatorSchema)
                                  throws java.lang.Exception
Tries to locate consistency check table. Throws a wrapped exception on failure.

Parameters:
conn - Database connection.
replicatorSchema - Schema name of the Replicator service.
Returns:
Consistency check table.
Throws:
java.lang.Exception

findNextConsistencyId

public static int findNextConsistencyId(Database conn,
                                        Table ct)
                                 throws java.lang.Exception
Finds what ID should be used for the next consistency check.

Parameters:
conn - Database connection.
ct - Consistency check table.
Returns:
Next consistency check ID.
Throws:
java.lang.Exception - If SQL query fails.

configure

public void configure(TungstenProperties properties)
               throws ReplicatorException
Read configuration data and configure replication behavior appropriately. This may be called multiple times to process configuration data.

Specified by:
configure in interface OpenReplicatorPlugin
Throws:
ReplicatorException - Thrown if configuration is incomplete or fails
See Also:
OpenReplicatorPlugin.configure(com.continuent.tungsten.common.config.TungstenProperties)

online

public void online(TungstenProperties params)
            throws java.lang.Exception
Puts the replicator into the online state, which turns on replication.

Specified by:
online in interface OpenReplicatorPlugin
Parameters:
params - Plugin-specific name-value pairs that alter online operation
Throws:
java.lang.Exception

offline

public void offline(TungstenProperties params)
             throws java.lang.Exception
Puts the replicator immediately into the offline state, which turns off replication. This operation is a hard shutdown that does no clean-up. If clean-up is required, call deferredShutdown() instead.

Specified by:
offline in interface OpenReplicatorPlugin
Throws:
java.lang.Exception

offlineDeferred

public void offlineDeferred(TungstenProperties params)
                     throws java.lang.Exception
Performs a deferred shutdown. All deferred operations then enqueue a GoOfflineEvent to do a hard shutdown.

Specified by:
offlineDeferred in interface OpenReplicatorPlugin
Throws:
java.lang.Exception
See Also:
OpenReplicatorPlugin.offlineDeferred(com.continuent.tungsten.common.config.TungstenProperties)

heartbeat

public boolean heartbeat(TungstenProperties params)
                  throws java.lang.Exception
Starts a heartbeat event. Inserts a heartbeat event into the transaction history. The replicator plugin must be in the MASTER state for this call to be successful.

Specified by:
heartbeat in interface OpenReplicatorPlugin
Returns:
true if the heartbeat is inserted.
Throws:
java.lang.Exception
See Also:
OpenReplicatorPlugin.heartbeat(com.continuent.tungsten.common.config.TungstenProperties)

flush

public java.lang.String flush(long timeout)
                       throws java.lang.Exception
Implements a flush operation to synchronize the state of the database with the replication log and return a comparable event ID that can be used in a wait operation on a slave.

Specified by:
flush in interface OpenReplicatorPlugin
Parameters:
timeout - Number of seconds to wait. 0 is indefinite.
Returns:
The event ID at which the log is synchronized
Throws:
java.lang.Exception

purge

public int purge(TungstenProperties params)
          throws java.lang.Exception
Wait for a particular event to be committed on the slave.

Specified by:
purge in interface OpenReplicatorPlugin
Parameters:
params - 0 or more control parameters expressed as name-value pairs
Returns:
Number of sessions terminated
Throws:
java.lang.Exception - Thrown if we timeout

waitForAppliedEvent

public boolean waitForAppliedEvent(java.lang.String event,
                                   long timeout)
                            throws java.lang.Exception
Wait for a particular event to be applied on the slave.

Specified by:
waitForAppliedEvent in interface OpenReplicatorPlugin
Parameters:
event - Event to wait for
timeout - Number of seconds to wait. 0 is indefinite.
Returns:
true if requested sequence number or greater applied, else false if the wait timed out
Throws:
java.lang.Exception - if there is a timeout or we are canceled

status

public java.util.HashMap<java.lang.String,java.lang.String> status()
                                                            throws java.lang.Exception
Returns the current replicator status as a set of name-value pairs.

Specified by:
status in interface OpenReplicatorPlugin
Throws:
java.lang.Exception

statusList

public java.util.List<java.util.Map<java.lang.String,java.lang.String>> statusList(java.lang.String name)
                                                                            throws java.lang.Exception
Returns a list of status instances for a particular list of items.

Specified by:
statusList in interface OpenReplicatorPlugin
Parameters:
name - Name of the status list. 'tasks' is supported by the native Tungsten replicator plugin.
Returns:
List of TungstenProperties instances containing task status
Throws:
java.lang.Exception
See Also:
OpenReplicatorPlugin.statusList(java.lang.String)

provision

public void provision(java.lang.String uri)
               throws java.lang.Exception
Description copied from interface: OpenReplicatorPlugin
Performs a provision operation. The provision operation is invoked on the replicator to be provisioned. The optional URI value provides the source for provisioning.

Specified by:
provision in interface OpenReplicatorPlugin
Throws:
java.lang.Exception

getCapabilities

public ReplicatorCapabilities getCapabilities()
                                       throws java.lang.Exception
Description copied from interface: OpenReplicatorPlugin
gets the capabilties for the replicator

Specified by:
getCapabilities in interface OpenReplicatorPlugin
Throws:
java.lang.Exception

setRole

public void setRole(java.lang.String role,
                    java.lang.String uri)
             throws ReplicatorException
Sets the replicator role.

Specified by:
setRole in interface OpenReplicatorPlugin
Parameters:
role - A supported role name, such as 'master', 'slave', or 'standby'
uri - An optional URI referring to another replicator if required for role (e.g., a slave typically points to a master)
Throws:
ReplicatorException
See Also:
OpenReplicatorPlugin.setRole(java.lang.String, java.lang.String)

getReplicatorRuntime

public ReplicatorRuntime getReplicatorRuntime()
Specified by:
getReplicatorRuntime in interface OpenReplicatorPlugin