www.pudn.com > yidong.rar > ThreadTest.java
package sample;
/**
* @File: ThreadTest.java
* @Description: Thread Test for CMPP2.0, MT sent or/and MO received thread test
* @Copyright: Copyright 2002 By AsiaInfo(c) ISMG. All right reserved
* @Date: 2002-10-24
* @Version 1.0
*/
import java.io.*;
import aiismg.jcmppapi30.CMPPAPI;
/**
* @Description: A class for reading parameter from console, creating MT or/and
* MO thread, and testing the java api of cmppapi2.0
*/
public class ThreadTest
{
/**
* created threads counts
*/
private static int ciThreadCount = 0 ;
/**
* loop times of each thread
*/
private static int ciThreadLoop = 0 ;
/**
* time out seconds at receiving MO
*/
private static int ciTimeOut = 0;
/**
* boolean flag of creating sending MT thread
*/
private static boolean cbSendThread = false ;
/**
* boolean flag of creating receiving MO thread
*/
private static boolean cbRecvThread = false ;
/**
* boolean flag of writing parameter and msg file at receiving MO
*/
private static boolean cbWriteFile = false ;
/**
* parameter file name of sending MT
*/
private static String csArgFile = null ;
/**
* @Description: print help message about this tool
* @Return: none
*/
private static void cvPrintUsage ()
{
System.out.println ( "" ) ;
System.out.println ( "AsiaInfo ISMG thread Test tool for CMPP2.0. Version 1.0" );
System.out.println ( "" ) ;
System.out.println ( "ThreadTest <-c digit> <-l digit> <-s | -r> [-f argfile] [-t timeout] [-w] [-v]" ) ;
System.out.println ( " Usage -c : created thread counts, int value " ) ;
System.out.println ( " -l : each thread loop, int value" ) ;
System.out.println ( " -s : run send MT thread" ) ;
System.out.println ( " -r : run recv MO thread" ) ;
System.out.println ( " -f : arg file when send MT" ) ;
System.out.println ( " -t : time out second, int value, default is no time out" ) ;
System.out.println ( " -w : write parameter and msg file at receiving MO");
System.out.println ( " -v : Show this screen" ) ;
System.out.println ( "" ) ;
}
/**
* @Description: return the loop time of each thread, specified by user input
* @Return: int value, equal or larger than zero
*/
public static int ciGetThreadLoop ( )
{
return ciThreadLoop ;
}
/**
* @Description: return the argument file name at sending MT,specified by user input
* @Return: String value, should not be null
*/
public static String csGetArgFile()
{
return csArgFile ;
}
/**
* @Description: return time out value at receiving MO, specified by user input
* @Return: int value, equal or larger than zero, and zero means waits forever
*/
public static int ciGetTimeout()
{
return ciTimeOut ;
}
/**
* @Description: return the flag of writing parameter and msg file when receiving MO
* @Return: boolean value, true means write output file, default is false
*/
public static boolean cbGetWriteFile()
{
return cbWriteFile ;
}
/**
* @Description: main function
*/
public static void main(String arg[])
{
if ( arg.length <= 0 ) {
cvPrintUsage () ;
System.exit ( 1 ) ;
}
//parse input argument
int liErrRet = 0 ;
for ( int i=0; i= arg.length ) {
liErrRet = -1 ;
break ;
} else {
try {
if ( (ciThreadCount = Integer.parseInt (arg[i])) <= 0 ) {
liErrRet = -1 ;
break ;
}
} catch ( NumberFormatException e ) {
System.out.println ( "Error: Illegal thread count value = " + arg[i] ) ;
liErrRet = -1 ;
break ;
}
}
} else if ( arg[i].compareTo ("-l") == 0 ) {
i++ ;
if ( i >= arg.length ) {
liErrRet = -1 ;
break ;
} else {
try {
if ( (ciThreadLoop = Integer.parseInt (arg[i])) <= 0 ) {
liErrRet = -1 ;
break ;
}
} catch ( NumberFormatException e ) {
System.out.println ( "Error: Illegal thread loop value = " + arg[i] ) ;
liErrRet = -1 ;
break ;
}
}
} else if ( arg[i].compareTo ("-s") == 0 ) {
cbSendThread = true ;
} else if ( arg[i].compareTo ("-r") == 0 ) {
cbRecvThread = true ;
} else if ( arg[i].compareTo ("-t") == 0 ) {
i++ ;
if ( i >= arg.length ) {
liErrRet = -1 ;
break ;
} else {
try {
if ( (ciTimeOut = Integer.parseInt (arg[i])) < 0 ) {
liErrRet = -1 ;
break ;
}
} catch ( NumberFormatException e ) {
System.out.println ( "Error: Illegal time out value = " + arg[i] ) ;
liErrRet = -1 ;
break ;
}
}
} else if ( arg[i].compareTo ("-f") == 0 ) {
i++ ;
if ( i >= arg.length ) {
liErrRet = -1 ;
break ;
} else {
csArgFile = arg[i] ;
}
} else if ( arg[i].compareTo ("-w") == 0 ) {
cbWriteFile = true ;
} else if ( arg[i].compareTo ("-v") == 0 ) {
cvPrintUsage() ;
System.exit ( 1 ) ;
} else {
liErrRet = -1 ;
break ;
}
} //end for
if ( liErrRet != 0 ) {
cvPrintUsage() ;
System.exit ( 1 ) ;
}
//start MT sending
if ( cbSendThread == true ) { //threads for send MT
ThreadSend[] coSendRunner = new ThreadSend[ciThreadCount];
Thread[] coSendThread = new Thread[ciThreadCount];
int i;
CMPPAPI loSendCMPPAPI = new CMPPAPI() ;
loSendCMPPAPI.InitCMPPAPI("../config/javacmppc.ini");
System.out.println("Start MT Sending...");
for (i=0;i