www.pudn.com > yidong.rar > Counter.java


package sample;
/**
 * @File: Counter.java
 * @Description: Thread Test for CMPP2.0, successful or failed counts
 * @Copyright: Copyright 2002 By AsiaInfo(c) ISMG. All right reserved
 * @Date: 2002-10-24
 * @Version 1.0
 */


/**
 * action counter
 */
public class Counter
{
  public static int ciSendSuccess=0;
  public static int ciSendFail=0;
  public static int ciRecvSuccess=0;
  public static int ciRecvFail=0;

 
  /**
   * MT sent counts, synchronized method
   */
  public synchronized static void SendAdd(int aiErrorCode)
  {
    //this following code can not be compiled in java, but works well in c/c++
    //(aiErrorCode == 0)? ciSendSuccess++ : ciSendFail++ ;
    if ( aiErrorCode == 0 ) {
      ciSendSuccess ++ ;
    } else {
      ciSendFail ++ ;
    }
  } //end SendAdd ( int )


  /**
   * MO received counts, synchronized method
   */
  public synchronized static void RecvAdd(int aiErrorCode)
  {
    //(aiErrorCode == 0)? ciRecvSuccess++ : ciRecvFail++ ;
    if ( aiErrorCode == 0 ) {
      ciRecvSuccess ++ ;
    } else {
      ciRecvFail ++ ;
    }
  } //end RecvAdd ( int )

}