www.pudn.com > yidong.rar > 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; liLen160)? 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