-
Type:
Bug
-
Resolution: Won't Fix
-
Priority:
P4
-
None
-
Affects Version/s: 1.2.0, 1.2.1
-
Component/s: vm-legacy
-
x86
-
windows_95, windows_nt
lBufferIndex < MSG_LENGTH;
++lIndex ){
lBuffer[lBufferIndex] = (byte)lTmp.charAt( lIndex );
++lBufferIndex;
}
//System.out.println( "-->>" + new String( lBuffer ) );
return lBuffer;
}
public boolean readFromByte( int iLength, byte[] iData ){
boolean lRetValue = true;
if( iLength > 0 ) {
dataType = iData[0];
if( iLength > 3 ){
id = (int)iData[1];
int lNameLength = (int)iData[2];
name = new String( iData, 3, lNameLength);
int lDataLength = iLength - lNameLength -3 ;
if( lDataLength > 0 ) {
data = new String( iData ,
lNameLength +3,
lDataLength );
}
else{
data = new String( "null");
}
}
else if( dataType != INVOKE_IND ) {
lRetValue = false;
}
}
else {
lRetValue = false;
}
return lRetValue;
}
public udpData( int iId,
String iName,
String iData ) {
dataType = INVOKE_IND;
id = iId;
name = new String( iName );
data = new String( iData );
}
public udpData( ) {
id = 0;
data = null;
name = null;
}
public udpData( int iMsgId ) {
id = iMsgId ;
data = null;
name = null;
}
public String getData( ){
return data;
}
public String getName( ){
return name;
}
public void copyData( int iId,
String iName,
String iData ){
id = iId;
name = new String( iName );
data = new String( iData );
}
public void setData( int iId,
String iName,
String iData ){
id = iId;
name = iName;
data = iData;
}
}
package se.ericsson.lmc.kd.wap.gateway.prototype.wapstack;
import java.io.*;
import java.net.*;
import java.util.*;
public class serverUdpData extends udpData {
private InetAddress address;
private int port;
public boolean compare( serverUdpData iData ){
boolean lRetValue = compare( (udpData)iData );
if( lRetValue == true &&
compareNetData( iData ) == true ){
lRetValue = true;
}
else{
lRetValue = false;
}
return lRetValue;
}
public boolean compareNetData( serverUdpData iData ){
boolean lRetValue = false;
if( iData.address.equals( this.address ) == true &&
iData.port == this.port &&
iData.getId() == this.getId() ){
lRetValue = true;
}
else{
lRetValue = false;
}
return lRetValue;
}
public int getPort(){
return port;
}
public InetAddress getAddress(){
return address;
}
public serverUdpData( DatagramPacket iPacket ) {
super();
address = iPacket.getAddress();
port = iPacket.getPort();
readFromByte( iPacket.getLength(), iPacket.getData() );
}
}
(Review ID: 47833)
======================================================================
Name: skT88420 Date: 09/23/99
A nonfatal internal JIT (3.00.078(x)) error 'GetRegisterA' has occurred in :
'Bank.transfer (III)V': Interpreting method.
Source Code:
class UnsyncBank{
public static void main(String [] arg){
Bank b = new Bank();
int i;
for(i=1;i<=Bank.NACCOUNTS;i++){
new TransactionSource(b,i).start();
}
}
}
class Bank
{
public Bank()
{
accounts = new long[NACCOUNTS];
int i;
for(i=1;i<NACCOUNTS;i++)
accounts[i]=INITIAL_BALANCE;
ntransacts=0;
test();
}
public void transfer(int from, int to, int amount)
{
while(accounts[from]<amount)
{ try {Thread.sleep(5);}
catch(InterruptedException e){}
accounts[from] -=amount;
accounts[to] +=amount;
ntransacts++;
if(ntransacts % 5000 ==0)test();
}
}
public void test(){
int i;
long sum=0;
for(i=0; i<NACCOUNTS ;i++) sum +=accounts[i];
System.out.println("Transactions: "+ntransacts +", Sum: "+sum);
}
public static final int INITIAL_BALANCE=10000;
public static final int NACCOUNTS=10;
private long[] accounts;
private int ntransacts;
}
class TransactionSource extends Thread{
public TransactionSource(Bank b, int i)
{
from=i-1;
bank=b;
}
public void run(){
while(true)
{
int to = (int)(Bank.NACCOUNTS *Math.random());
if(to==from) to = (to+1) % Bank.NACCOUNTS ;
int amount=(int)(Bank.INITIAL_BALANCE * Math.random());
bank.transfer(from, to, amount);
try{sleep(1);}catch(InterruptedException e){}
}
}
private Bank bank;
private int from;
}
(Review ID: 95622)
======================================================================
Name: krT82822 Date: 02/04/99
(dies in "report" contstructor)
Message received :
-------------------------------------------------------
A nonfatal internal JIT (3.00.078(x)) error 'GetRegisterA' has occurred in :
'se/ericsson/lmc/kd/wap/gateway/prototype/wapstack/udpdriver/report.<init> ([L
se/ericsson/lmc/kd/wap/gateway/prototype/wapstack/udpdriver/clientThread;III)V':
Interpreting method.
Please report this error in detail to http://java.sun.com/cgi-bin/bugreport.cgi
-----------------------------------------------------------------
in class :
----------------------------------------------------
package se.ericsson.lmc.kd.wap.gateway.prototype.wapstack.udpdriver;
public class report {
private long minSleep = 1000;
private long maxSleep = 0;
private long avrSleep;
private int nbFailedCalls =0;
private int nbLate=0;
private int nbThreads;
private int nbCalls;
private int nbSec;
public report(clientThread[] iThreawds, int iNbThreads,
int iNbCalls, int iNbSec ) {
long lThAvrSleep;
avrSleep =0;
nbCalls = iNbCalls;
nbSec = iNbSec;
nbThreads = iNbThreads;
for ( int i=0; i< iNbThreads; ++i){
nbFailedCalls += iThreawds[i].getNbFailedCalls();
nbLate += iThreawds[i].getNbLate();
lThAvrSleep = iThreawds[i].getAvrTime();
if( lThAvrSleep > 0 ) {
if( minSleep > lThAvrSleep){
minSleep = lThAvrSleep;
}
if( maxSleep < lThAvrSleep){
maxSleep = lThAvrSleep;
}
avrSleep += lThAvrSleep;
}
}
avrSleep = avrSleep/(long)(iNbThreads - nbFailedCalls );
}
public void print(){
System.out.println( "(ms) Avr = " + avrSleep + " min " + minSleep + " max " + maxSleep );
System.out.println( "Num. failed ="+ nbFailedCalls + " Num. timeout =" + nbLate );
System.out.println("");
int lfailed = (nbFailedCalls*1000)/(nbThreads* nbCalls*nbSec);
System.out.println(lfailed+" calls failed over 1000 . " );
}
}
package se.ericsson.lmc.kd.wap.gateway.prototype.wapstack.udpdriver;
import java.io.*;
import java.net.*;
import java.util.*;
public class clientThread extends Thread {
private InetAddress address;
private int nbCalls;
private int nbSec;
private long invokeTime;
private long totalTime = 0;
private int nbFailed =0;
private int nbLate=0;
private long sleepTime;
private boolean active = true;
private static final int TIMEOUT_TIME_MS = 3000;
public boolean isActive(){
return active;
}
public long getAvrTime(){
long lRetValue;
lRetValue = (totalTime/(long)(nbSec * nbCalls)) -
1000 ;
return lRetValue ;
}
public long getTotalTime(){
return totalTime;
}
public int getNbLate(){
return nbLate;
}
public int getNbFailedCalls(){
return nbFailed;
}
public clientThread( String iServerHostName ,
int iNbCalls ,
int iNbSec ,
long iSleep ) throws IOException {
address = InetAddress.getByName(iServerHostName);
nbCalls = iNbCalls;
nbSec = iNbSec;
totalTime =0;
sleepTime = iSleep;
}
public void run() {
try{
long lStartTime;
long lEndTime;
long lOneMsgTime;
udpData lData = makeMsg();
active = true;
// get a datagram socket
DatagramSocket socket = new DatagramSocket();
// send request
byte[] buf;
// 5 sec timeout
socket.setSoTimeout( TIMEOUT_TIME_MS );
for ( int lNbSec=0; lNbSec < nbSec; ++lNbSec){
DatagramPacket packet ;
lStartTime = System.currentTimeMillis();
for ( int lNbCalls=0; lNbCalls < nbCalls; ++lNbCalls){
lStartTime = System.currentTimeMillis();
lData.incId();
buf = lData.getByteToSend();
packet = new DatagramPacket( buf, buf.length,
address, 4445);
socket.send(packet);
// get response
packet = new DatagramPacket(buf, buf.length);
if( getResponce( socket , lData.getId() ) == false ){
++nbFailed;
}
else {
lEndTime = System.currentTimeMillis();
invokeTime = lEndTime - lStartTime;
totalTime += invokeTime ;
}
}
try {
java.lang.Thread.sleep ( sleepTime );
}
catch (Exception e){
}
}
socket.close();
active = false;
}
catch (IOException e) {
}
}
private boolean getResponce( DatagramSocket iSocket ,
int iMsgId ){
boolean lRetValue = true;
long lReadStartTime;
long lReadEndTime;
serverUdpData lData;
DatagramPacket packet = null;
int lMsgSize;
//System.out.println("Waiting for responce.");
// waite for InvokeResponce
lReadStartTime = System.currentTimeMillis();
try {
// get response
byte[] buf = new byte[ udpData.MSG_LENGTH ];
packet = new DatagramPacket(buf, buf.length);
iSocket.receive(packet);
lReadEndTime = System.currentTimeMillis();
lReadEndTime -= lReadStartTime;
if( lReadEndTime >= TIMEOUT_TIME_MS ) {
totalTime -= lReadEndTime;
++nbLate;
}
//checkMsg( packet );
}
catch (Exception e){
lRetValue = false;
}
if ( lRetValue == true && packet != null ){
lData = new serverUdpData( packet );
if( lData.getDataType() != udpData.INVOKE_RES ){
System.out.println("b" + (int)lData.getDataType() + "!="+ (int)udpData.INVOKE_RES+ "..");
lRetValue = false;
}
else{
lReadStartTime = System.currentTimeMillis();
try {
// get response
byte[] buf = new byte[ udpData.MSG_LENGTH ];
packet = new DatagramPacket(buf, buf.length);
iSocket.receive(packet);
lReadEndTime = System.currentTimeMillis();
lReadEndTime -= lReadStartTime;
if( lReadEndTime >= TIMEOUT_TIME_MS ) {
totalTime -= lReadEndTime;
++nbLate;
}
else{
}
//checkMsg( packet );
}
catch (Exception e){
lRetValue = false;
}
}
}
else {
}
if ( lRetValue == true ){
lData = new serverUdpData( packet );
if( lData.getDataType() != udpData.RESULT_REQ ){
lRetValue = false;
}
else{
}
}
else {
}
if( lRetValue == false ) {
System.out.println("Warning udp transaction "+ iMsgId + " canceled");
}
else{
}
// send Cnf any way to make sure we remove data..
sendResultCnf( iSocket , iMsgId );
return lRetValue;
}
public static void checkMsg( DatagramPacket iPacket ){
serverUdpData lData = new serverUdpData( iPacket );
System.out.print("Received data type :");
switch ( lData.getDataType() ){
case udpData.INVOKE_IND:
System.out.println("INVOKE_IND");
break;
case udpData.INVOKE_RES:
System.out.println("INVOKE_RES");
break;
case udpData.RESULR_CNF:
System.out.println("RESULR_CNF");
break;
case udpData.RESULT_REQ:
System.out.println("RESULT_REQ");
break;
default :
System.out.println("..BAD DATA..");
}
}
private udpData makeMsg( ){
String lName = "Testing";
String lStrData = makeString( '-' , 400 );
udpData lData = new udpData( 0, lName ,lStrData );
return lData ;
}
private String makeString( char iChar, int iNb){
char[] lData = new char[ iNb +1 ];
for (int i=0; i< iNb; ++i){
lData[i] = iChar;
}
lData[ iNb ] = '\0';
return new String( lData );
}
private void sendResultCnf( DatagramSocket iSocket ,
int iMsgId ){
DatagramPacket lPacket ;
byte[] buf;
udpData lData = new udpData( iMsgId );
lData.setDataType( udpData.RESULR_CNF );
buf = lData.getByteToSend();
lPacket = new DatagramPacket( buf, buf.length,
address, 4445);
//System.out.println("sending invoke:");
// waite for InvokeResponce
try {
iSocket.send(lPacket);
}
catch (Exception e){
}
}
}
package se.ericsson.lmc.kd.wap.gateway.prototype.wapstack;
import java.io.*;
import java.net.*;
import java.util.*;
public class udpData {
private String data;
private String name;
private int id;
private byte dataType;
// 500 UDP read fixe data length
public static final int MSG_LENGTH = 500 ;
public static final byte INVOKE_IND = 0;
public static final byte INVOKE_RES = 1;
public static final byte RESULT_REQ = 2;
public static final byte RESULR_CNF = 3;
public void incId(){
if( id < 125 ){ // writen to socket using byte sign
++id;
}
else{
id = 1;
}
}
// not needed any more
private void writeMsgSize( byte[] iOutBuffer ){
int lMsgLength = iOutBuffer.length - 10;
Integer lIntSize = new Integer( lMsgLength );
String lMsgSize = lIntSize.toString();
for ( int i=0 ; i< 10; ++i){
if( i< lMsgSize.length() ) {
iOutBuffer[i] = (byte)lMsgSize.charAt( i);
}
else{
iOutBuffer[i] = ' ';
}
}
}
// not needed any more
private static int getMsgSizeFromByte( byte[] iMsg ){
String lIntMsg;
int lTmp;
for ( lTmp =0 ;
lTmp < 10 &&
lTmp < iMsg.length; ++lTmp){
if( iMsg[ lTmp ] != '0' &&
iMsg[ lTmp ] != '1' &&
iMsg[ lTmp ] != '2' &&
iMsg[ lTmp ] != '3' &&
iMsg[ lTmp ] != '4' &&
iMsg[ lTmp ] != '5' &&
iMsg[ lTmp ] != '6' &&
iMsg[ lTmp ] != '7' &&
iMsg[ lTmp ] != '8' &&
iMsg[ lTmp ] != '9') {
//--lTmp;
break;
}
}
lIntMsg = new String( iMsg , 0 , lTmp );
return Integer.parseInt( lIntMsg );
}
// not needed any more
private static int readMsgSize( DatagramSocket iSocket ){
byte[] buf = new byte[ 10 ];
DatagramPacket packet = new DatagramPacket( buf,
buf.length);
try{
iSocket.receive(packet);
}
catch (Exception e){
}
return getMsgSizeFromByte( packet.getData() );
}
public boolean goToNextState( byte iFromState ){
boolean lRetValue = true;
if( iFromState == dataType ){
switch ( dataType ){
case INVOKE_IND:
dataType = INVOKE_RES;
break;
case INVOKE_RES:
dataType = RESULT_REQ;
break;
case RESULT_REQ:
dataType = RESULR_CNF;
break;
default:
System.out.println("ERROR BAD UDP transaction state :"+ dataType);
lRetValue = false;
}
}
else{
System.out.println("BAD transaction step {from,to}:{" + iFromState + ","+ dataType + "}");
lRetValue = false;
}
return lRetValue;
}
public int getId(){
return id;
}
public boolean compare( udpData iData ){
boolean lRetValue = false;
if( iData.id == this.id &&
iData.name == this.name &&
iData.data == this.data ){
lRetValue = true;
}
else{
}
return lRetValue;
}
public byte getDataType(){
return dataType;
}
public void setDataType( byte iDataType ){
dataType = iDataType;
}
public byte[] getByteToSend(){
String lNullMsg = "null";
int lLength = 3 ;
String lTmp;
if( data != null) {
lLength += data.length();
}
else {
lLength += lNullMsg.length();
}
if ( name != null ){
lLength += (int)((byte)name.length());
}
else{
lLength += lNullMsg.length();
}
int lBufferIndex = 0;
int lIndex;
int lNameLength;
byte[] lBuffer = new byte[ MSG_LENGTH ];
lBuffer[lBufferIndex] = dataType;
++lBufferIndex;
lBuffer[lBufferIndex] = (byte)id;
++lBufferIndex;
if( name != null ) {
lTmp = name;
}
else {
lTmp = lNullMsg;
}
if ( lTmp.length() < 125 ) {
lBuffer[lBufferIndex] = (byte)lTmp.length();
lNameLength = (int)( (byte)lTmp.length());
++lBufferIndex;
}
else
{
lBuffer[lBufferIndex] = (byte)125;
lNameLength = (int)( 125);
++lBufferIndex;
}
for ( lIndex =0; lIndex< lNameLength; ++lIndex ){
lBuffer[lBufferIndex] = (byte)lTmp.charAt( lIndex );
++lBufferIndex;
}
if( data != null ) {
lTmp = data;
}
else {
lTmp = lNullMsg;
}
lNameLength = (int)( (byte)lTmp.length());
for ( lIndex =0;
lIndex< lNameLength &&
++lIndex ){
lBuffer[lBufferIndex] = (byte)lTmp.charAt( lIndex );
++lBufferIndex;
}
//System.out.println( "-->>" + new String( lBuffer ) );
return lBuffer;
}
public boolean readFromByte( int iLength, byte[] iData ){
boolean lRetValue = true;
if( iLength > 0 ) {
dataType = iData[0];
if( iLength > 3 ){
id = (int)iData[1];
int lNameLength = (int)iData[2];
name = new String( iData, 3, lNameLength);
int lDataLength = iLength - lNameLength -3 ;
if( lDataLength > 0 ) {
data = new String( iData ,
lNameLength +3,
lDataLength );
}
else{
data = new String( "null");
}
}
else if( dataType != INVOKE_IND ) {
lRetValue = false;
}
}
else {
lRetValue = false;
}
return lRetValue;
}
public udpData( int iId,
String iName,
String iData ) {
dataType = INVOKE_IND;
id = iId;
name = new String( iName );
data = new String( iData );
}
public udpData( ) {
id = 0;
data = null;
name = null;
}
public udpData( int iMsgId ) {
id = iMsgId ;
data = null;
name = null;
}
public String getData( ){
return data;
}
public String getName( ){
return name;
}
public void copyData( int iId,
String iName,
String iData ){
id = iId;
name = new String( iName );
data = new String( iData );
}
public void setData( int iId,
String iName,
String iData ){
id = iId;
name = iName;
data = iData;
}
}
package se.ericsson.lmc.kd.wap.gateway.prototype.wapstack;
import java.io.*;
import java.net.*;
import java.util.*;
public class serverUdpData extends udpData {
private InetAddress address;
private int port;
public boolean compare( serverUdpData iData ){
boolean lRetValue = compare( (udpData)iData );
if( lRetValue == true &&
compareNetData( iData ) == true ){
lRetValue = true;
}
else{
lRetValue = false;
}
return lRetValue;
}
public boolean compareNetData( serverUdpData iData ){
boolean lRetValue = false;
if( iData.address.equals( this.address ) == true &&
iData.port == this.port &&
iData.getId() == this.getId() ){
lRetValue = true;
}
else{
lRetValue = false;
}
return lRetValue;
}
public int getPort(){
return port;
}
public InetAddress getAddress(){
return address;
}
public serverUdpData( DatagramPacket iPacket ) {
super();
address = iPacket.getAddress();
port = iPacket.getPort();
readFromByte( iPacket.getLength(), iPacket.getData() );
}
}
(Review ID: 47833)
======================================================================
Name: skT88420 Date: 09/23/99
A nonfatal internal JIT (3.00.078(x)) error 'GetRegisterA' has occurred in :
'Bank.transfer (III)V': Interpreting method.
Source Code:
class UnsyncBank{
public static void main(String [] arg){
Bank b = new Bank();
int i;
for(i=1;i<=Bank.NACCOUNTS;i++){
new TransactionSource(b,i).start();
}
}
}
class Bank
{
public Bank()
{
accounts = new long[NACCOUNTS];
int i;
for(i=1;i<NACCOUNTS;i++)
accounts[i]=INITIAL_BALANCE;
ntransacts=0;
test();
}
public void transfer(int from, int to, int amount)
{
while(accounts[from]<amount)
{ try {Thread.sleep(5);}
catch(InterruptedException e){}
accounts[from] -=amount;
accounts[to] +=amount;
ntransacts++;
if(ntransacts % 5000 ==0)test();
}
}
public void test(){
int i;
long sum=0;
for(i=0; i<NACCOUNTS ;i++) sum +=accounts[i];
System.out.println("Transactions: "+ntransacts +", Sum: "+sum);
}
public static final int INITIAL_BALANCE=10000;
public static final int NACCOUNTS=10;
private long[] accounts;
private int ntransacts;
}
class TransactionSource extends Thread{
public TransactionSource(Bank b, int i)
{
from=i-1;
bank=b;
}
public void run(){
while(true)
{
int to = (int)(Bank.NACCOUNTS *Math.random());
if(to==from) to = (to+1) % Bank.NACCOUNTS ;
int amount=(int)(Bank.INITIAL_BALANCE * Math.random());
bank.transfer(from, to, amount);
try{sleep(1);}catch(InterruptedException e){}
}
}
private Bank bank;
private int from;
}
(Review ID: 95622)
======================================================================
Name: krT82822 Date: 02/04/99
(dies in "report" contstructor)
Message received :
-------------------------------------------------------
A nonfatal internal JIT (3.00.078(x)) error 'GetRegisterA' has occurred in :
'se/ericsson/lmc/kd/wap/gateway/prototype/wapstack/udpdriver/report.<init> ([L
se/ericsson/lmc/kd/wap/gateway/prototype/wapstack/udpdriver/clientThread;III)V':
Interpreting method.
Please report this error in detail to http://java.sun.com/cgi-bin/bugreport.cgi
-----------------------------------------------------------------
in class :
----------------------------------------------------
package se.ericsson.lmc.kd.wap.gateway.prototype.wapstack.udpdriver;
public class report {
private long minSleep = 1000;
private long maxSleep = 0;
private long avrSleep;
private int nbFailedCalls =0;
private int nbLate=0;
private int nbThreads;
private int nbCalls;
private int nbSec;
public report(clientThread[] iThreawds, int iNbThreads,
int iNbCalls, int iNbSec ) {
long lThAvrSleep;
avrSleep =0;
nbCalls = iNbCalls;
nbSec = iNbSec;
nbThreads = iNbThreads;
for ( int i=0; i< iNbThreads; ++i){
nbFailedCalls += iThreawds[i].getNbFailedCalls();
nbLate += iThreawds[i].getNbLate();
lThAvrSleep = iThreawds[i].getAvrTime();
if( lThAvrSleep > 0 ) {
if( minSleep > lThAvrSleep){
minSleep = lThAvrSleep;
}
if( maxSleep < lThAvrSleep){
maxSleep = lThAvrSleep;
}
avrSleep += lThAvrSleep;
}
}
avrSleep = avrSleep/(long)(iNbThreads - nbFailedCalls );
}
public void print(){
System.out.println( "(ms) Avr = " + avrSleep + " min " + minSleep + " max " + maxSleep );
System.out.println( "Num. failed ="+ nbFailedCalls + " Num. timeout =" + nbLate );
System.out.println("");
int lfailed = (nbFailedCalls*1000)/(nbThreads* nbCalls*nbSec);
System.out.println(lfailed+" calls failed over 1000 . " );
}
}
package se.ericsson.lmc.kd.wap.gateway.prototype.wapstack.udpdriver;
import java.io.*;
import java.net.*;
import java.util.*;
public class clientThread extends Thread {
private InetAddress address;
private int nbCalls;
private int nbSec;
private long invokeTime;
private long totalTime = 0;
private int nbFailed =0;
private int nbLate=0;
private long sleepTime;
private boolean active = true;
private static final int TIMEOUT_TIME_MS = 3000;
public boolean isActive(){
return active;
}
public long getAvrTime(){
long lRetValue;
lRetValue = (totalTime/(long)(nbSec * nbCalls)) -
1000 ;
return lRetValue ;
}
public long getTotalTime(){
return totalTime;
}
public int getNbLate(){
return nbLate;
}
public int getNbFailedCalls(){
return nbFailed;
}
public clientThread( String iServerHostName ,
int iNbCalls ,
int iNbSec ,
long iSleep ) throws IOException {
address = InetAddress.getByName(iServerHostName);
nbCalls = iNbCalls;
nbSec = iNbSec;
totalTime =0;
sleepTime = iSleep;
}
public void run() {
try{
long lStartTime;
long lEndTime;
long lOneMsgTime;
udpData lData = makeMsg();
active = true;
// get a datagram socket
DatagramSocket socket = new DatagramSocket();
// send request
byte[] buf;
// 5 sec timeout
socket.setSoTimeout( TIMEOUT_TIME_MS );
for ( int lNbSec=0; lNbSec < nbSec; ++lNbSec){
DatagramPacket packet ;
lStartTime = System.currentTimeMillis();
for ( int lNbCalls=0; lNbCalls < nbCalls; ++lNbCalls){
lStartTime = System.currentTimeMillis();
lData.incId();
buf = lData.getByteToSend();
packet = new DatagramPacket( buf, buf.length,
address, 4445);
socket.send(packet);
// get response
packet = new DatagramPacket(buf, buf.length);
if( getResponce( socket , lData.getId() ) == false ){
++nbFailed;
}
else {
lEndTime = System.currentTimeMillis();
invokeTime = lEndTime - lStartTime;
totalTime += invokeTime ;
}
}
try {
java.lang.Thread.sleep ( sleepTime );
}
catch (Exception e){
}
}
socket.close();
active = false;
}
catch (IOException e) {
}
}
private boolean getResponce( DatagramSocket iSocket ,
int iMsgId ){
boolean lRetValue = true;
long lReadStartTime;
long lReadEndTime;
serverUdpData lData;
DatagramPacket packet = null;
int lMsgSize;
//System.out.println("Waiting for responce.");
// waite for InvokeResponce
lReadStartTime = System.currentTimeMillis();
try {
// get response
byte[] buf = new byte[ udpData.MSG_LENGTH ];
packet = new DatagramPacket(buf, buf.length);
iSocket.receive(packet);
lReadEndTime = System.currentTimeMillis();
lReadEndTime -= lReadStartTime;
if( lReadEndTime >= TIMEOUT_TIME_MS ) {
totalTime -= lReadEndTime;
++nbLate;
}
//checkMsg( packet );
}
catch (Exception e){
lRetValue = false;
}
if ( lRetValue == true && packet != null ){
lData = new serverUdpData( packet );
if( lData.getDataType() != udpData.INVOKE_RES ){
System.out.println("b" + (int)lData.getDataType() + "!="+ (int)udpData.INVOKE_RES+ "..");
lRetValue = false;
}
else{
lReadStartTime = System.currentTimeMillis();
try {
// get response
byte[] buf = new byte[ udpData.MSG_LENGTH ];
packet = new DatagramPacket(buf, buf.length);
iSocket.receive(packet);
lReadEndTime = System.currentTimeMillis();
lReadEndTime -= lReadStartTime;
if( lReadEndTime >= TIMEOUT_TIME_MS ) {
totalTime -= lReadEndTime;
++nbLate;
}
else{
}
//checkMsg( packet );
}
catch (Exception e){
lRetValue = false;
}
}
}
else {
}
if ( lRetValue == true ){
lData = new serverUdpData( packet );
if( lData.getDataType() != udpData.RESULT_REQ ){
lRetValue = false;
}
else{
}
}
else {
}
if( lRetValue == false ) {
System.out.println("Warning udp transaction "+ iMsgId + " canceled");
}
else{
}
// send Cnf any way to make sure we remove data..
sendResultCnf( iSocket , iMsgId );
return lRetValue;
}
public static void checkMsg( DatagramPacket iPacket ){
serverUdpData lData = new serverUdpData( iPacket );
System.out.print("Received data type :");
switch ( lData.getDataType() ){
case udpData.INVOKE_IND:
System.out.println("INVOKE_IND");
break;
case udpData.INVOKE_RES:
System.out.println("INVOKE_RES");
break;
case udpData.RESULR_CNF:
System.out.println("RESULR_CNF");
break;
case udpData.RESULT_REQ:
System.out.println("RESULT_REQ");
break;
default :
System.out.println("..BAD DATA..");
}
}
private udpData makeMsg( ){
String lName = "Testing";
String lStrData = makeString( '-' , 400 );
udpData lData = new udpData( 0, lName ,lStrData );
return lData ;
}
private String makeString( char iChar, int iNb){
char[] lData = new char[ iNb +1 ];
for (int i=0; i< iNb; ++i){
lData[i] = iChar;
}
lData[ iNb ] = '\0';
return new String( lData );
}
private void sendResultCnf( DatagramSocket iSocket ,
int iMsgId ){
DatagramPacket lPacket ;
byte[] buf;
udpData lData = new udpData( iMsgId );
lData.setDataType( udpData.RESULR_CNF );
buf = lData.getByteToSend();
lPacket = new DatagramPacket( buf, buf.length,
address, 4445);
//System.out.println("sending invoke:");
// waite for InvokeResponce
try {
iSocket.send(lPacket);
}
catch (Exception e){
}
}
}
package se.ericsson.lmc.kd.wap.gateway.prototype.wapstack;
import java.io.*;
import java.net.*;
import java.util.*;
public class udpData {
private String data;
private String name;
private int id;
private byte dataType;
// 500 UDP read fixe data length
public static final int MSG_LENGTH = 500 ;
public static final byte INVOKE_IND = 0;
public static final byte INVOKE_RES = 1;
public static final byte RESULT_REQ = 2;
public static final byte RESULR_CNF = 3;
public void incId(){
if( id < 125 ){ // writen to socket using byte sign
++id;
}
else{
id = 1;
}
}
// not needed any more
private void writeMsgSize( byte[] iOutBuffer ){
int lMsgLength = iOutBuffer.length - 10;
Integer lIntSize = new Integer( lMsgLength );
String lMsgSize = lIntSize.toString();
for ( int i=0 ; i< 10; ++i){
if( i< lMsgSize.length() ) {
iOutBuffer[i] = (byte)lMsgSize.charAt( i);
}
else{
iOutBuffer[i] = ' ';
}
}
}
// not needed any more
private static int getMsgSizeFromByte( byte[] iMsg ){
String lIntMsg;
int lTmp;
for ( lTmp =0 ;
lTmp < 10 &&
lTmp < iMsg.length; ++lTmp){
if( iMsg[ lTmp ] != '0' &&
iMsg[ lTmp ] != '1' &&
iMsg[ lTmp ] != '2' &&
iMsg[ lTmp ] != '3' &&
iMsg[ lTmp ] != '4' &&
iMsg[ lTmp ] != '5' &&
iMsg[ lTmp ] != '6' &&
iMsg[ lTmp ] != '7' &&
iMsg[ lTmp ] != '8' &&
iMsg[ lTmp ] != '9') {
//--lTmp;
break;
}
}
lIntMsg = new String( iMsg , 0 , lTmp );
return Integer.parseInt( lIntMsg );
}
// not needed any more
private static int readMsgSize( DatagramSocket iSocket ){
byte[] buf = new byte[ 10 ];
DatagramPacket packet = new DatagramPacket( buf,
buf.length);
try{
iSocket.receive(packet);
}
catch (Exception e){
}
return getMsgSizeFromByte( packet.getData() );
}
public boolean goToNextState( byte iFromState ){
boolean lRetValue = true;
if( iFromState == dataType ){
switch ( dataType ){
case INVOKE_IND:
dataType = INVOKE_RES;
break;
case INVOKE_RES:
dataType = RESULT_REQ;
break;
case RESULT_REQ:
dataType = RESULR_CNF;
break;
default:
System.out.println("ERROR BAD UDP transaction state :"+ dataType);
lRetValue = false;
}
}
else{
System.out.println("BAD transaction step {from,to}:{" + iFromState + ","+ dataType + "}");
lRetValue = false;
}
return lRetValue;
}
public int getId(){
return id;
}
public boolean compare( udpData iData ){
boolean lRetValue = false;
if( iData.id == this.id &&
iData.name == this.name &&
iData.data == this.data ){
lRetValue = true;
}
else{
}
return lRetValue;
}
public byte getDataType(){
return dataType;
}
public void setDataType( byte iDataType ){
dataType = iDataType;
}
public byte[] getByteToSend(){
String lNullMsg = "null";
int lLength = 3 ;
String lTmp;
if( data != null) {
lLength += data.length();
}
else {
lLength += lNullMsg.length();
}
if ( name != null ){
lLength += (int)((byte)name.length());
}
else{
lLength += lNullMsg.length();
}
int lBufferIndex = 0;
int lIndex;
int lNameLength;
byte[] lBuffer = new byte[ MSG_LENGTH ];
lBuffer[lBufferIndex] = dataType;
++lBufferIndex;
lBuffer[lBufferIndex] = (byte)id;
++lBufferIndex;
if( name != null ) {
lTmp = name;
}
else {
lTmp = lNullMsg;
}
if ( lTmp.length() < 125 ) {
lBuffer[lBufferIndex] = (byte)lTmp.length();
lNameLength = (int)( (byte)lTmp.length());
++lBufferIndex;
}
else
{
lBuffer[lBufferIndex] = (byte)125;
lNameLength = (int)( 125);
++lBufferIndex;
}
for ( lIndex =0; lIndex< lNameLength; ++lIndex ){
lBuffer[lBufferIndex] = (byte)lTmp.charAt( lIndex );
++lBufferIndex;
}
if( data != null ) {
lTmp = data;
}
else {
lTmp = lNullMsg;
}
lNameLength = (int)( (byte)lTmp.length());
for ( lIndex =0;
lIndex< lNameLength &&