com.continuent.tungsten.replicator.management.script
Class ScriptPlugin

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

public class ScriptPlugin
extends javax.management.NotificationBroadcasterSupport
implements OpenReplicatorPlugin

This class defines an OpenReplicatorPlugin that invokes an external program to control replication.

Version:
1.0
Author:
Seppo Jaakola

Field Summary
static java.lang.String ARG_URI
           
 
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
ScriptPlugin()
           
 
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.
 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()
          Return the capabilities of this replicator plugin.
 ReplicatorRuntime getReplicatorRuntime()
           
 boolean heartbeat(TungstenProperties params)
          Inserts a heartbeat event into the transaction history.
 void offline(TungstenProperties params)
          Puts the replicator into the offline state, which turns off replication.
 void offlineDeferred(TungstenProperties params)
          Issues a request to go offline at a later point in replication.
 void online(TungstenProperties params)
          Puts the replicator into the goingonline state, which turns on replication.
 void prepare(OpenReplicatorContext context)
          Prepare plug-in for use.
 void provision(java.lang.String uri)
          Calls the provision method on the script.
 int purge(TungstenProperties params)
          Kill logins other than the connection(s) used for replication.
 void release()
          Release all resources used by plug-in.
 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
 

Field Detail

ARG_URI

public static final java.lang.String ARG_URI
See Also:
Constant Field Values
Constructor Detail

ScriptPlugin

public ScriptPlugin()
Method Detail

prepare

public void prepare(OpenReplicatorContext context)
             throws ReplicatorException
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
Release all resources used by plug-in. This is called before the plug-in is deallocated.

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

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 goingonline 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 into the offline state, which turns off replication.

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

offlineDeferred

public void offlineDeferred(TungstenProperties params)
                     throws java.lang.Exception
Issues a request to go offline at a later point in replication. Not all plug-ins support deferred offline behavior.

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
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
Kill logins other than the connection(s) used for replication. @ *

The following control parameters are accepted:

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 or are canceled

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. The following values are defined for all replicators.

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
Calls the provision method on the script. 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
See Also:
OpenReplicatorPlugin.provision(java.lang.String)

consistencyCheck

public int consistencyCheck(java.lang.String method,
                            java.lang.String schemaName,
                            java.lang.String tableName,
                            int rowOffset,
                            int rowLimit)
                     throws java.lang.Exception
Description copied from interface: OpenReplicatorPlugin
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

setRole

public void setRole(java.lang.String role,
                    java.lang.String uri)
             throws ReplicatorException
Sets the replicator role. 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)

getCapabilities

public ReplicatorCapabilities getCapabilities()
                                       throws java.lang.Exception
Return the capabilities of this replicator plugin.

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

getReplicatorRuntime

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