From fa0a1f8f73dd98fa9da26d1422984d6d17529fb1 Mon Sep 17 00:00:00 2001 From: giberta1 Date: Tue, 23 Apr 2002 15:07:47 +0000 Subject: [PATCH] Add statistics reporting, Add Str_UnFormat() method, Remove some debug print-out. --- MQSLoad.java | 127 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 101 insertions(+), 26 deletions(-) diff --git a/MQSLoad.java b/MQSLoad.java index 26486e5..c32f720 100644 --- a/MQSLoad.java +++ b/MQSLoad.java @@ -1,7 +1,7 @@ // $RCSfile: MQSLoad.java,v $ -// $Revision: 1.3 $ +// $Revision: 1.4 $ // $Name: $ -// $Date: 2002/04/19 15:22:14 $ +// $Date: 2002/04/23 15:07:47 $ // $Author: giberta1 $ /* @@ -27,6 +27,7 @@ import com.ibm.mq.*; import java.io.*; +import java.text.*; @@ -41,7 +42,7 @@ public class MQSLoad private int MsgQ_Open_Options = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING; private String File_Name; private String Field_Break = ""; - private String Message_Break = "\n"; + private String Message_Break = "\r\n"; @@ -64,46 +65,47 @@ public class MQSLoad // //------------------------------------------------------------------------------------------------------------------------- - public static String Str_Format( String Fmt) + public static String Str_Format( String UnFmt) { int idx; boolean esc = false; - String result = ""; + String fmt = ""; - for( idx = 0; idx < Fmt.length(); idx++) + for( idx = 0; idx < UnFmt.length(); idx++) { if( esc) { - switch( Fmt.charAt( idx)) + switch( UnFmt.charAt( idx)) { - case '/': + case '\\': { - result = result + "\\"; + fmt += "\\"; break; } case 'n': { - result = result + "\n"; + fmt += "\n"; break; } case 'r': { - result = result + "\r"; + fmt += "\r"; break; } case 't': { - result = result + "\t"; + fmt += "\t"; break; } default: { - result = result + "?"; + fmt += "?"; + break; } } @@ -111,18 +113,71 @@ public class MQSLoad } else { - if( Fmt.charAt( idx) == '\\') + if( UnFmt.charAt( idx) == '\\') { esc = true; } else { - result = result + Fmt.charAt( idx); + fmt += UnFmt.charAt( idx); } } } - return( result); + return( fmt); + } + + + + + + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- + + public static String Str_UnFormat( String Fmt) + { + int idx; + String unfmt = ""; + + + for( idx = 0; idx < Fmt.length(); idx++) + { + switch( Fmt.charAt( idx)) + { + case '\\': + { + unfmt += "\\\\"; + break; + } + + case '\n': + { + unfmt += "\\n"; + break; + } + + case '\r': + { + unfmt += "\\r"; + break; + } + + case '\t': + { + unfmt += "\\t"; + break; + } + + default: + { + unfmt += Fmt.charAt( idx); + break; + } + } + } + + return( unfmt); } @@ -201,7 +256,7 @@ public class MQSLoad try { QMng = new MQQueueManager( QMng_Name); - System.out.println( "QManager Open: (" + QMng + ") !"); +// System.out.println( "QManager Open: (" + QMng + ") !"); } catch( Exception Expt) @@ -212,13 +267,13 @@ public class MQSLoad try { MsgQ = QMng.accessQueue( MsgQ_Name, MsgQ_Open_Options, null, null, null); - System.out.println( "MsgQ Open: (" + MsgQ + ") !"); +// System.out.println( "MsgQ Open: (" + MsgQ + ") !"); } catch( Exception Expt) { QMng.disconnect(); - System.out.println( "QManager Close: (" + QMng + ") !"); +// System.out.println( "QManager Close: (" + QMng + ") !"); throw Expt; } @@ -237,9 +292,9 @@ public class MQSLoad try { MsgQ.close(); - System.out.println( "MsgQ Close: (" + MsgQ + ") !"); +// System.out.println( "MsgQ Close: (" + MsgQ + ") !"); QMng.disconnect(); - System.out.println( "QManager Close: (" + QMng + ") !"); +// System.out.println( "QManager Close: (" + QMng + ") !"); } catch( Exception Expt) @@ -301,7 +356,7 @@ public class MQSLoad // //------------------------------------------------------------------------------------------------------------------------- - private void Load_File( BufferedInputStream Input_File) throws Exception + private int Load_File( BufferedInputStream Input_File) throws Exception { byte input_char; int msg_nb = 0; @@ -413,6 +468,7 @@ public class MQSLoad } System.out.println( "\n"); + return( msg_nb); } catch( Exception Expt) @@ -431,12 +487,19 @@ public class MQSLoad public MQSLoad( String args[]) { + int msg_nb; + long time_begin, time_end; + double time_elapsed, speed; + NumberFormat nf = NumberFormat.getInstance(); + + try { if( ( args.length < 2) || ( args.length > 6)) { System.out.println( "Usage: MQSLoad [-fb \"field_break\"] [-mb \"message_break\"] "); + System.out.println( " Default: Field Break: (" + Str_UnFormat( Field_Break) + ") Message Break: (" + Str_UnFormat( Message_Break) + ")"); } else { @@ -445,7 +508,7 @@ public class MQSLoad Arg_Parse( args); System.out.println( "Output MsgQueue Name: (" + MsgQ_Name + ") Input File Name: (" + File_Name + ")"); - System.out.println( "Field Break: (" + Field_Break + ") Message_Break: (" + Message_Break + ")"); + System.out.println( "Field Break: (" + Str_UnFormat( Field_Break) + ") Message Break: (" + Str_UnFormat( Message_Break) + ")"); MQSInit(); @@ -455,10 +518,22 @@ public class MQSLoad try { - System.out.println("Input File Open: (" + input_file + ") !"); +// System.out.println("Input File Open: (" + input_file + ") !"); + + time_begin = System.currentTimeMillis(); + msg_nb = Load_File( input_file); + time_end = System.currentTimeMillis(); - Load_File( input_file); - + time_elapsed = ( time_end - time_begin) / 100.0; + speed = msg_nb / time_elapsed; + + nf.setMinimumFractionDigits(2); + nf.setMaximumFractionDigits(2); + + System.out.println( "Loaded Message Nb: (" + msg_nb + + ") Elapsed Time: (" + nf.format(time_elapsed) + + ") s Speed: (" + nf.format(speed) + + ") msg/s"); } catch( Exception Expt)