tppt.xopen
Class TwoPhaseController

java.lang.Object
  |
  +--tppt.xopen.TwoPhaseController

public class TwoPhaseController
extends java.lang.Object

TwoPhaseController class is the main class to perform the two-phase commit simulation environment.

Version:
2.0
Author:
Jodie Wu

Inner Class Summary
(package private)  class TwoPhaseController.Worker
          The Worker class.
 
Field Summary
(package private)  APInterface[] ap
           
private  java.lang.String apClassDir
          Directory path to load the ApplicationProgram
(package private)  AX ax
           
private  ListItem dot
          The ListItem to show the dot(.) to the log window.
private  java.lang.String dotStr
           
protected  TwoPhaseLogger logger
          The logger
private  int numOfAp
          Number of ApplicationProgram the program expected to load
protected  javax.swing.Timer timer
          The timer that control the transition of the worker.
(package private)  TMInterface tm
           
private  java.lang.String tmClassPath
          File path to load the TransactionManager
(package private)  TX tx
           
(package private)  TwoPhaseController.Worker[] worker
          The array of Worker.
 
Constructor Summary
private TwoPhaseController()
          Empty constructor.
  TwoPhaseController(java.lang.String tmPath, java.lang.String apDir, int num, java.lang.String schemaFile)
          The constructor.
 
Method Summary
private  void confirmRegistration()
          Performs the first stage check.
private  void confirmResult()
          Perform the Two-Phase Commit check Check whether user commit or abort the transaction correctly.
private  void forceCloseConnection()
          Force all the ResourceManager to release its connection.
private  boolean loadClass()
          Dynamically load the TransactionManager and ApplicationProgram(s) classes user provided
static void main(java.lang.String[] args)
           
 boolean twoPhaseDBInit(java.lang.String file)
          Initialize the database.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

tmClassPath

private java.lang.String tmClassPath
File path to load the TransactionManager

apClassDir

private java.lang.String apClassDir
Directory path to load the ApplicationProgram

numOfAp

private int numOfAp
Number of ApplicationProgram the program expected to load

logger

protected TwoPhaseLogger logger
The logger

timer

protected javax.swing.Timer timer
The timer that control the transition of the worker.

worker

TwoPhaseController.Worker[] worker
The array of Worker.

dot

private ListItem dot
The ListItem to show the dot(.) to the log window.

dotStr

private java.lang.String dotStr

ax

AX ax

tx

TX tx

tm

TMInterface tm

ap

APInterface[] ap
Constructor Detail

TwoPhaseController

private TwoPhaseController()
Empty constructor.

TwoPhaseController

public TwoPhaseController(java.lang.String tmPath,
                          java.lang.String apDir,
                          int num,
                          java.lang.String schemaFile)
The constructor. It will first do the database initialization, then load the required classes. If classes loaded sucessfully, it creates the worker(thread) for each ApplicationProgram that has been loaded. There are the status flag inside the worker and a timer will control the transition of worker.

Below shows the status and what the timer process will behave regarding to each status : -1 : Something is wrong. Exception throws inside this worker. Terminates all the worker, close the connection and stop the timer. 1: If status of all workers are 1, it means they all finish the setup process before the two-phase commit, then timer will first confirm the result and then change their status to 2. 2: If worker's status =2, it will commit its ApplicationProgram so the two-phase commit starts. And worker set the status to 3. 3: If status of all workers are 3, it means two-phase commit is done. Timer will check the result, terminate all the workers and kill itself.

Parameters:
tmPath - the file path of user's TransactionManager Class
apDir - the directory path of user's ApplicationProgram class(es)
num - number of ApplicationProgram
schemaFile - the file path of user's Database initialization File
See Also:
twoPhaseDBInit(java.lang.String), loadClass()
Method Detail

loadClass

private boolean loadClass()
Dynamically load the TransactionManager and ApplicationProgram(s) classes user provided
Returns:
boolean true if load sucessfully. false otherwise.
See Also:
java.net.URLClassLoader

forceCloseConnection

private void forceCloseConnection()
Force all the ResourceManager to release its connection.
See Also:
ResourceManager.forceCloseConnection()

confirmRegistration

private void confirmRegistration()
Performs the first stage check. Checkpoint: 1. whether ResourceManager.connectToRM() called 2. whether TransactionManager.tx_begin() is called or implementation correctly 3. whether ResourceManager.registerToTM() is called.
See Also:
ResourceManager.connectToRM(int, int, tppt.db.DBSetting), ResourceManager.registerToTM()

confirmResult

private void confirmResult()
Perform the Two-Phase Commit check Check whether user commit or abort the transaction correctly.

twoPhaseDBInit

public boolean twoPhaseDBInit(java.lang.String file)
Initialize the database. It first cleans all the existing table and objects and then re-create the tables and data according to the database initialization file user provides.
Parameters:
file - database initialization file
Returns:
true if initialization process performs sucessfully; false otherwise.
See Also:
DBHandler, DB2Handler, SybaseHandler, DBSetting

main

public static void main(java.lang.String[] args)