tppt.util
Class Terminal

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--tppt.util.Terminal
All Implemented Interfaces:
java.lang.Runnable

class Terminal
extends java.lang.Thread

Terminal is a thread to simulate a terminal that run the a group of transaction session user define in the Transaction Script File.

Version:
1.1 04/25/00
Author:
Jie Su, modified by Jiang Yin 2001
See Also:
java.lang.Thread.

Field Summary
private  java.util.Vector argumentFiles
          array of OpenedFiles, opened non-terminal key argument files
(package private)  java.sql.Connection connection
           
private  GlobalData global
           
(package private)  int numOfDeadlocks
          This variable is used to store the number of deadlocks occurs in this Terminal including the retry times.
private  int numOfRetry
           
(package private)  int ONE_SECOND
           
(package private)  boolean script_cycle
          JY2001 for v1.4 JY changes the code to make it only execute the script file once.
private  java.lang.String scriptFileName
           
private  java.util.Vector sessKeysVaules
          Array of session keys.
private  boolean stop
           
private  int terminalNum
          Terminal number to identify this terminal.
private  java.util.Vector termKeysValues
          Array of TermKeyValues instance.
 
Fields inherited from class java.lang.Thread
contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ
 
Constructor Summary
(package private) Terminal(int i)
           
 
Method Summary
(package private)  void closeArgFiles()
          Close the opened argument files stored in the OpenedFiles Vector.
private  void countDeadlocks()
           
(package private)  boolean dbConnect(java.lang.String user, java.lang.String passwd)
          Create the connection to the database.
(package private)  Transaction getTrans(java.lang.String procName)
          Get the transaction instance from the line of Transaction Script File.
(package private)  boolean openArgFiles()
          This method is used to seperate terminal key, session key and neither, and open or assign the argument file to each key.
 void run()
          Start to run the transaction on this terminal.
(package private)  int runTransaction(java.lang.String procName)
          prepares the and runs the transaction with name- procName.
(package private)  java.lang.String selectArgValues(java.lang.String arg)
          retrieve a value for non-sesskey (terminal key or neither)argument.
(package private)  boolean selectSessKeyValues()
          select one value for each session-key argument and store them to the Vector- sessKeysVaules.
(package private)  boolean selectTermKeyValues()
          create a TermKeyValue class for each terminal key and read its values from each corresponding argument file.
(package private)  void showError(java.lang.String errorMsg)
           
 void stopTerm()
          Set the stop flag to true to indicate this terminal has been stopped.
 
Methods inherited from class java.lang.Thread
, activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, exit, getContextClassLoader, getName, getPriority, getThreadGroup, init, interrupt, interrupt0, interrupted, isAlive, isDaemon, isInterrupted, isInterrupted, join, join, join, nextThreadNum, registerNatives, resume, resume0, setContextClassLoader, setDaemon, setName, setPriority, setPriority0, sleep, sleep, start, stop, stop, stop0, suspend, suspend0, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ONE_SECOND

final int ONE_SECOND

connection

java.sql.Connection connection

numOfDeadlocks

int numOfDeadlocks
This variable is used to store the number of deadlocks occurs in this Terminal including the retry times.

terminalNum

private int terminalNum
Terminal number to identify this terminal.

numOfRetry

private int numOfRetry

script_cycle

boolean script_cycle
JY2001 for v1.4 JY changes the code to make it only execute the script file once.

stop

private boolean stop

scriptFileName

private java.lang.String scriptFileName

argumentFiles

private java.util.Vector argumentFiles
array of OpenedFiles, opened non-terminal key argument files

sessKeysVaules

private java.util.Vector sessKeysVaules
Array of session keys.

termKeysValues

private java.util.Vector termKeysValues
Array of TermKeyValues instance.

global

private GlobalData global
Constructor Detail

Terminal

Terminal(int i)
Method Detail

showError

void showError(java.lang.String errorMsg)

dbConnect

boolean dbConnect(java.lang.String user,
                  java.lang.String passwd)
Create the connection to the database.
Parameters:
user - the user name to login the database.
passd - the password to login the database
Returns:
returns true if connection established sucessfully, false otherwise.

getTrans

Transaction getTrans(java.lang.String procName)
Get the transaction instance from the line of Transaction Script File.
Parameters:
procName - the transaction procedure read from Transaction Script File.
Returns:
returns the Transaction instance for that procedure,or null if that transaction is not defined in the transaction prototype file.
See Also:
GlobalData.transactions, Transaction.copy()

selectTermKeyValues

boolean selectTermKeyValues()
create a TermKeyValue class for each terminal key and read its values from each corresponding argument file.
Returns:
returns true if no error occurs, false otherwise.
See Also:
TermKeyValues, GlobalData.termKeys

openArgFiles

boolean openArgFiles()
This method is used to seperate terminal key, session key and neither, and open or assign the argument file to each key. The terminal key uses TermKeyValues class to store the keyword and the values. All the TermKeyValues instances are stored in the Vector- termKeysValues. The non-terminal key -session key and neither, uses OpenedFiles class to store the filename and its arguemnt file handler. All the OpenedFiles instances are stored in the Vector - argumentFiles.
See Also:
selectTermKeyValues(), OpenedFiles, getTrans(String)

closeArgFiles

void closeArgFiles()
Close the opened argument files stored in the OpenedFiles Vector.
See Also:
OpenedFiles.fileStream

selectSessKeyValues

boolean selectSessKeyValues()
select one value for each session-key argument and store them to the Vector- sessKeysVaules.
Returns:
returns true when no error occurs, false otherwise.

selectArgValues

java.lang.String selectArgValues(java.lang.String arg)
retrieve a value for non-sesskey (terminal key or neither)argument.
Parameters:
arg - the name of argument to be retrieved.
Returns:
returns the value of the key.

runTransaction

int runTransaction(java.lang.String procName)
prepares the and runs the transaction with name- procName. If the return from transaction is deadlock (-5), the program will retry the number of numOfRetry times. Each retry starts 10 milliseconds after the previous transaction ends.
Returns:
returns the result of transaction procedure. The meaning of return value is listed below: >=0 -- suceeded -5 -- deadlock -1 -- SQL exception error in user transaction -2 -- Logic errors due to constraints -100 -- procedure not found -101 -- can't get value for argument -201 -- ClassNotFoundException -202 -- SecurityException -203 -- NoSuchMethodException -204 -- InstantiationException -205 -- IllegalAccessException -206 -- IllegalArgumentException -207 -- InvocationTargetException other -- other errors
See Also:
getTrans(String), Transaction.execTransaction()

run

public void run()
Start to run the transaction on this terminal. It runs the transaction according to Transaction Script File. There are 3 kind of situations that terminal or experiment will terminate. 1. Certian transaction keep resulting in deadlock - specifically, if one transaction occurs 4 times (origial one time + 3 retry times)deadlock, that terminal will abort.

2. Due to the errors in the students' procedure. If any this kind of error occurs, the program will report this error to user and then whole experiment terminates.

3.Due to other errors. The same with 2.

Overrides:
run in class java.lang.Thread
See Also:
openArgFiles(), selectSessKeyValues(), runTransaction(String)

countDeadlocks

private void countDeadlocks()

stopTerm

public void stopTerm()
Set the stop flag to true to indicate this terminal has been stopped.