📄 threadrecv.java
字号:
package sample;/** * @File: ThreadRecv.java * @Description: Thread Test for CMPP2.0, MO received thread test * @Copyright: Copyright 2002 By AsiaInfo(c) ISMG. All right reserved * @Date: 2002-10-24 * @Version 1.0 */import aiismg.jcmppapi30.CMPPAPI;import aiismg.jcmppapi30.CMPPDeliverResp;import java.io.*;/** * @Description: a multi thread implementation class of MO received, for testing * function CMPPDeliver(int, CMPPDeliverResp) of cmppapi2.0 */ public class ThreadRecv implements Runnable{ private int ciErrorCode; private boolean cbWriteFile; public CMPPAPI coThreadTest = new CMPPAPI() ; CMPPDeliverResp coDeliverResp = new CMPPDeliverResp(); /** * @Description: Write parameter and msg content into file * @Return: none * @Note: the default is not write output file, unless the caller speicified * to write output file */ public void cvWriteMsgFile ( String asThreadname, int aiLoop ) { if ( cbWriteFile == false ) { //user disabled write output file return ; } String lsParaFile, lsMsgFile ; //parameter file name is built as "p"+"threadname"+"-"+"loop time" lsParaFile = new StringBuffer().append("p").append(asThreadname).append("-").append(aiLoop).toString(); lsMsgFile = new StringBuffer().append("m").append(asThreadname).append("-").append(aiLoop).toString(); //write parameter into specifiled file FileOutputStream loParaFile ; try { int liLen ; String lsContentBuf ; loParaFile = new FileOutputStream ( lsParaFile ) ; loParaFile.write ( coDeliverResp.sMsgID.getBytes() ) ; //msg ID loParaFile.write ( '\n' ) ; lsContentBuf = Byte.toString ( coDeliverResp.nMsgLevel ) ; //msg level loParaFile.write ( lsContentBuf.getBytes() ) ; loParaFile.write ( '\n' ) ; lsContentBuf = Byte.toString ( coDeliverResp.nMsgFormat ) ; //msg format loParaFile.write ( lsContentBuf.getBytes() ) ; loParaFile.write ( '\n' ) ; for ( liLen=0; liLen<coDeliverResp.sSrcTermID.length; liLen++ ) { //src term ID if ( coDeliverResp.sSrcTermID[liLen] == 0 ) { break ; } } //end for loParaFile.write ( coDeliverResp.sSrcTermID, 0, liLen ) ; loParaFile.write ( '\n' ) ; lsContentBuf = Byte.toString ( coDeliverResp.nIsReply ) ; //reply loParaFile.write ( lsContentBuf.getBytes() ) ; loParaFile.write ( '\n' ) ; for ( liLen=0; liLen<coDeliverResp.sDestTermID.length; liLen++ ) {//dest term ID if ( coDeliverResp.sDestTermID[liLen] == 0 ) { break ; } } //end for loParaFile.write ( coDeliverResp.sDestTermID, 0, liLen ) ; loParaFile.write ( '\n' ) ; loParaFile.close() ; } catch ( SecurityException e ) { System.out.println ( "Error: failed to write parameter file, SecurityException" + asThreadname + "---" + e.toString() ) ; } catch ( FileNotFoundException e ) { System.out.println("Error: failed to write parameter file,FileNotFoundException" + asThreadname + "---" + e.toString() ) ; } catch ( IOException e ) { System.out.println ( "Error: failed to write parameter file, IOException" + asThreadname + "---" + e.toString() ) ; } //write msg file FileOutputStream loMsgFile ; try { loMsgFile = new FileOutputStream ( lsMsgFile ) ; loMsgFile.write ( coDeliverResp.sMsgContent, 0, ((coDeliverResp.nMsgLen>160)? 160 : coDeliverResp.nMsgLen) ) ; loMsgFile.write ( '\n' ) ; loMsgFile.close() ; } catch ( SecurityException e ) { System.out.println ( "Error: failed to write msgID file, SecurityException" + asThreadname + "---" + e.toString() ) ; } catch ( FileNotFoundException e ) { System.out.println("Error: failed to write msgID file,FileNotFoundException" + asThreadname + "---" + e.toString() ) ; } catch ( IOException e ) { System.out.println ( "Error: failed to write msgID file, IOException" + asThreadname + "---" + e.toString() ) ; } } //end cvWriteMsgFile /** * MO received thread run method */ public void run() { int i; byte[] lsMsgID = new byte[20]; System.out.println(Thread.currentThread().getName()); int liThreadLoop = ThreadTest.ciGetThreadLoop() ; int liTimeout = ThreadTest.ciGetTimeout() ; cbWriteFile = ThreadTest.cbGetWriteFile() ; for ( i=0; i<liThreadLoop; i++ ) { //System.out.println ( "CMPPDeliver call..." ) ; ciErrorCode = coThreadTest.CMPPDeliver ( liTimeout, coDeliverResp ) ; //System.out.println ( "CMPPDeliver return...errorno=" + i ) ; //ciErrorCode=coThreadTest.GetErrCode() ; if (ciErrorCode!=0) { System.out.println ( Thread.currentThread().getName() + "Recv Error, ErrorCode=" + Integer.toString(ciErrorCode)); } else { cvWriteMsgFile ( Thread.currentThread().getName(), i ) ; System.out.println ( Thread.currentThread().getName() + "Recv Ok, loop time i=" + i ) ; } Counter.RecvAdd(ciErrorCode); } System.out.println(Thread.currentThread().getName() + "Recv End"); } //end run()}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -