com.continuent.tungsten.replicator.thl
Class THLManagerCtrl

java.lang.Object
  extended by com.continuent.tungsten.replicator.thl.THLManagerCtrl

public class THLManagerCtrl
extends java.lang.Object

This class defines a THLManagerCtrl that implements a utility to access THLManager methods. See the printHelp() command for a description of current commands.

Version:
1.0
Author:
Linas Virbalas

Nested Class Summary
static class THLManagerCtrl.InfoHolder
          This class holds elements returned by the info query.
 
Field Summary
protected static ArgvIterator argvIterator
           
protected  java.lang.String configFile
           
protected static java.lang.String defaultConfigPath
          Default path to replicator.properties if user not specified other.
 
Constructor Summary
THLManagerCtrl(java.lang.String configFile, boolean doChecksum)
          Creates a new THLManagerCtrl object.
 
Method Summary
protected static void fail()
          Exit with a process failure code.
protected static void fatal(java.lang.String msg, java.lang.Throwable t)
          Abort following a fatal error.
static java.lang.String formatColumn(OneRowChange.ColumnSpec colSpec, OneRowChange.ColumnVal value, java.lang.String prefix, java.lang.String charset, boolean hex)
          Formats column and column value for printing.
protected static boolean getBoolOrFalse(java.lang.Boolean bool)
          Returns a value of a given Boolean object or false if the object is null.
 THLManagerCtrl.InfoHolder getInfo()
          Queries THL for summary information.
 void listEvents(java.lang.Long low, java.lang.Long high, java.lang.Long by, boolean pureSQL, boolean headersOnly, boolean json, java.lang.String charset, boolean hex)
          List THL events within the given range.
static void main(java.lang.String[] argv)
          Main method to run utility.
 void prepare(boolean readOnly)
          Connect to the underlying database containing THL.
protected static void print(java.lang.String msg)
          Print a message to stdout without trailing new line character.
static void printHeader(java.lang.StringBuilder stringBuilder, ReplDBMSEvent event)
          Prints a formatted header into StringBuilder for the given ReplDBMSEvent.
static void printHeader(java.lang.StringBuilder stringBuilder, THLEvent thlEvent, int format)
          Prints a formatted header into StringBuilder for the given THLEvent.
protected static void printHelp()
           
protected static void println(java.lang.String msg)
          Print a message to stdout with trailing new line character.
static void printReplDBMSEvent(java.lang.StringBuilder stringBuilder, ReplDBMSEvent event, boolean pureSQL, java.lang.String charset, boolean hex)
          Formats and prints ReplDBMSEvent into a given stringBuilder.
 void purgeEvents(java.lang.Long low, java.lang.Long high)
          Purge THL events in the given seqno interval.
protected  TungstenProperties readConfig()
          Reads the replicator.properties.
protected static boolean readYes()
          Reads a character from stdin, blocks until it is not received.
 void release()
          Disconnect from the THL database.
protected static void succeed()
          Exit with a process success code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultConfigPath

protected static final java.lang.String defaultConfigPath
Default path to replicator.properties if user not specified other.


argvIterator

protected static ArgvIterator argvIterator

configFile

protected java.lang.String configFile
Constructor Detail

THLManagerCtrl

public THLManagerCtrl(java.lang.String configFile,
                      boolean doChecksum)
               throws java.lang.Exception
Creates a new THLManagerCtrl object.

Parameters:
configFile - Path to the Tungsten properties file.
doChecksum - If false disable checksums on log.
Throws:
java.lang.Exception
Method Detail

readConfig

protected TungstenProperties readConfig()
                                 throws java.lang.Exception
Reads the replicator.properties.

Throws:
java.lang.Exception

prepare

public void prepare(boolean readOnly)
             throws ReplicatorException,
                    java.lang.InterruptedException
Connect to the underlying database containing THL.

Throws:
ReplicatorException
java.lang.InterruptedException

release

public void release()
Disconnect from the THL database.


getInfo

public THLManagerCtrl.InfoHolder getInfo()
                                  throws ReplicatorException
Queries THL for summary information.

Returns:
Info holder
Throws:
ReplicatorException

formatColumn

public static java.lang.String formatColumn(OneRowChange.ColumnSpec colSpec,
                                            OneRowChange.ColumnVal value,
                                            java.lang.String prefix,
                                            java.lang.String charset,
                                            boolean hex)
Formats column and column value for printing.

Parameters:
charset - character set name to be used to decode byte arrays in row replication

listEvents

public void listEvents(java.lang.Long low,
                       java.lang.Long high,
                       java.lang.Long by,
                       boolean pureSQL,
                       boolean headersOnly,
                       boolean json,
                       java.lang.String charset,
                       boolean hex)
                throws ReplicatorException,
                       java.lang.InterruptedException
List THL events within the given range.

Parameters:
low - Sequence number specifying the beginning of the range. Leave null to start from the very beginning of the table.
high - Sequence number specifying the end of the range. Leave null to end at the very end of the table.
by -
pureSQL - Output events in the pure SQL form if true, formatted form otherwise.
charset - character set name to be used to decode byte arrays in row replication
hex - If true print hex representation of strings
Throws:
ReplicatorException
java.lang.InterruptedException

printHeader

public static void printHeader(java.lang.StringBuilder stringBuilder,
                               THLEvent thlEvent,
                               int format)
Prints a formatted header into StringBuilder for the given THLEvent.

Parameters:
stringBuilder - StringBuilder object to append formatted contents to.
thlEvent - THLEvent to print out.
format - 0 - human readable, 1 - JSON, 2 - tab-delimited.
See Also:
printHeader(StringBuilder, ReplDBMSEvent)

printHeader

public static void printHeader(java.lang.StringBuilder stringBuilder,
                               ReplDBMSEvent event)
Prints a formatted header into StringBuilder for the given ReplDBMSEvent. Note that ReplDBMSEvent doesn't contain eventId, thus it is not printed. If you need to print eventId, use printHeader(StringBuilder, THLEvent, int)

Parameters:
stringBuilder - StringBuilder object to append formatted contents to.
event - ReplDBMSEvent to print out.
See Also:
printHeader(StringBuilder, THLEvent, int)

printReplDBMSEvent

public static void printReplDBMSEvent(java.lang.StringBuilder stringBuilder,
                                      ReplDBMSEvent event,
                                      boolean pureSQL,
                                      java.lang.String charset,
                                      boolean hex)
Formats and prints ReplDBMSEvent into a given stringBuilder.

Parameters:
stringBuilder - StringBuilder object to append formatted contents to.
event - ReplDBMSEvent to print out.
pureSQL - If true, use pure SQL output. Formatted form otherwise.
charset - character set name to be used to decode byte arrays in row replication
hex - If true print hex representation of strings

purgeEvents

public void purgeEvents(java.lang.Long low,
                        java.lang.Long high)
                 throws ReplicatorException
Purge THL events in the given seqno interval.

Parameters:
low - Sequence number specifying the beginning of the range. Leave null to start from the very beginning of the table.
high - Sequence number specifying the end of the range. Leave null to end at the very end of the table.
Throws:
ReplicatorException

main

public static void main(java.lang.String[] argv)
Main method to run utility.

Parameters:
argv - optional command string

printHelp

protected static void printHelp()

println

protected static void println(java.lang.String msg)
Print a message to stdout with trailing new line character.

Parameters:
msg -

print

protected static void print(java.lang.String msg)
Print a message to stdout without trailing new line character.

Parameters:
msg -

fatal

protected static void fatal(java.lang.String msg,
                            java.lang.Throwable t)
Abort following a fatal error.

Parameters:
msg -
t -

fail

protected static void fail()
Exit with a process failure code.


succeed

protected static void succeed()
Exit with a process success code.


readYes

protected static boolean readYes()
                          throws java.io.IOException
Reads a character from stdin, blocks until it is not received.

Returns:
true if use pressed `y`, false otherwise.
Throws:
java.io.IOException

getBoolOrFalse

protected static boolean getBoolOrFalse(java.lang.Boolean bool)
Returns a value of a given Boolean object or false if the object is null.

Parameters:
bool - Boolean object to check and return.
Returns:
the value of a given Boolean object or false if the object is null.