First step to 2.0.*:
- Code cleanup, - Add message skip option "-ms", - Add message count option "-mc", - Add repeat count option "-rc", - Fix Java 1.4 compatibility.
This commit is contained in:
parent
f12bcae985
commit
bc2254cab8
189
MQSLoad.java
189
MQSLoad.java
@ -1,7 +1,7 @@
|
||||
// $RCSfile: MQSLoad.java,v $
|
||||
// $Revision: 1.13 $
|
||||
// $Revision: 1.14 $
|
||||
// $Name: $
|
||||
// $Date: 2008/11/14 00:00:51 $
|
||||
// $Date: 2008/12/04 10:45:06 $
|
||||
// $Author: agibert $
|
||||
|
||||
/*
|
||||
@ -25,9 +25,9 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
import com.ibm.mq.*;
|
||||
import java.io.*;
|
||||
import java.text.*;
|
||||
import com.ibm.mq.*;
|
||||
|
||||
|
||||
|
||||
@ -35,21 +35,24 @@ import java.text.*;
|
||||
|
||||
public class MQSLoad
|
||||
{
|
||||
private String MQSLoad_Revision = "$Revision: 1.14 $";
|
||||
private String MQSLoad_Tag = "$Name: $";
|
||||
private String MQSLoad_Date = "$Date: 2008/12/04 10:45:06 $";
|
||||
private String MQSLoad_Author = "$Author: agibert $";
|
||||
private MQQueueManager QMng = null;
|
||||
private String QMng_Name = "";
|
||||
private MQQueue MsgQ;
|
||||
private String MsgQ_Name;
|
||||
private int MsgQ_Open_Options = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING;
|
||||
private String File_Name;
|
||||
private int Sleep_Time = 0;
|
||||
private String Field_Break = "";
|
||||
private String Message_Break = "\r\n";
|
||||
private String Message_Tail = "";
|
||||
private int Message_Skip = 0;
|
||||
private int Message_Count = 0;
|
||||
private int Repeat_Count = 1;
|
||||
private boolean Keep_Message_Break = false;
|
||||
private String MQSLoad_Revision = "$Revision: 1.13 $";
|
||||
private String MQSLoad_Tag = "$Name: $";
|
||||
private String MQSLoad_Date = "$Date: 2008/11/14 00:00:51 $";
|
||||
private String MQSLoad_Author = "$Author: agibert $";
|
||||
private Integer Sleep_Time = 0;
|
||||
private String File_Name;
|
||||
|
||||
|
||||
|
||||
@ -264,6 +267,42 @@ public class MQSLoad
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
else if ( args[argc].equals( "-ms"))
|
||||
{
|
||||
if( argc < ( args.length + 1))
|
||||
{
|
||||
Message_Skip = Integer.parseInt( args[++argc]);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println( "Invalid number of command line options...");
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
else if ( args[argc].equals( "-mc"))
|
||||
{
|
||||
if( argc < ( args.length + 1))
|
||||
{
|
||||
Message_Count = Integer.parseInt( args[++argc]);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println( "Invalid number of command line options...");
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
else if ( args[argc].equals( "-rc"))
|
||||
{
|
||||
if( argc < ( args.length + 1))
|
||||
{
|
||||
Repeat_Count = Integer.parseInt( args[++argc]);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println( "Invalid number of command line options...");
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
else if ( args[argc].equals( "-kmb"))
|
||||
{
|
||||
Keep_Message_Break = true;
|
||||
@ -415,7 +454,7 @@ public class MQSLoad
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
private void Stand_By(int timer)
|
||||
private void Stand_By(int timer) throws Exception
|
||||
{
|
||||
if( timer > 0)
|
||||
{
|
||||
@ -441,13 +480,42 @@ public class MQSLoad
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
private int Load_File( BufferedInputStream Input_File) throws Exception
|
||||
private int Put_Msg( MQMessage Output_Msg, int Count_Nb, int Msg_Nb) throws Exception
|
||||
{
|
||||
if( Msg_Nb > Count_Nb)
|
||||
{
|
||||
// System.out.print( "#");
|
||||
}
|
||||
else
|
||||
{
|
||||
Output_Msg.messageId = MQC.MQMI_NONE;
|
||||
MQSPut_Msg( Output_Msg);
|
||||
Output_Msg.clearMessage();
|
||||
|
||||
Counter_Print( Msg_Nb++);
|
||||
|
||||
Stand_By( Sleep_Time);
|
||||
}
|
||||
|
||||
return( Msg_Nb);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
private int Load_File( RandomAccessFile Input_File, int Msg_Skip, int Msg_Count, int Msg_Nb) throws Exception
|
||||
{
|
||||
byte input_char;
|
||||
int msg_nb = 0;
|
||||
MQMessage output_msg = new MQMessage();
|
||||
int buffer_size, cur_buffer_size, window_size, cur_window_size, prefetch_size, buffer_offset, read_size;
|
||||
int cur_pos, end_pos, next_message, next_field;
|
||||
int skip_nb = 0;
|
||||
int count_nb = Msg_Nb + Msg_Count;
|
||||
byte[] buffer_byte;
|
||||
String buffer_string, out_string = null;
|
||||
|
||||
@ -541,15 +609,19 @@ public class MQSLoad
|
||||
output_msg.writeString( Message_Break);
|
||||
}
|
||||
|
||||
output_msg.messageId = MQC.MQMI_NONE;
|
||||
MQSPut_Msg( output_msg);
|
||||
output_msg.clearMessage();
|
||||
|
||||
if( skip_nb < Msg_Skip)
|
||||
{
|
||||
skip_nb++;
|
||||
// System.out.print( "*");
|
||||
}
|
||||
else
|
||||
{
|
||||
Msg_Nb = Put_Msg( output_msg, count_nb, Msg_Nb);
|
||||
}
|
||||
|
||||
out_string = null;
|
||||
cur_pos += Message_Break.length();
|
||||
|
||||
Counter_Print( msg_nb++);
|
||||
|
||||
Stand_By( Sleep_Time);
|
||||
}
|
||||
}
|
||||
|
||||
@ -567,16 +639,10 @@ public class MQSLoad
|
||||
if( out_string != null)
|
||||
{
|
||||
// System.out.println( "* Flushing Msg");
|
||||
output_msg.messageId = MQC.MQMI_NONE;
|
||||
MQSPut_Msg( output_msg);
|
||||
|
||||
Counter_Print( msg_nb++);
|
||||
|
||||
Stand_By( Sleep_Time);
|
||||
Msg_Nb = Put_Msg( output_msg, count_nb, Msg_Nb);
|
||||
}
|
||||
|
||||
System.out.println( "\n");
|
||||
return( msg_nb);
|
||||
return( Msg_Nb);
|
||||
}
|
||||
|
||||
catch( Exception Expt)
|
||||
@ -589,13 +655,42 @@ public class MQSLoad
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
private void Print_Usage( ) throws Exception
|
||||
{
|
||||
System.out.println( "Usage: MQSLoad [-qm \"Output_QueueMng_Name\"] [-st \"sleep_time\"] [-fb \"field_break\"] [-mb \"message_break\"] [-mt \"message_tail\"] [-kmb] [-ms \"message_skip\"] [-mc \"message_count\"] [-rc \"repeat_count\"] <Output_MsgQueue_Name> <Input_File_Name>");
|
||||
System.out.println( " Default: Output QueueMng Name: (" + QMng_Name + ") Sleep Time: (" + Sleep_Time + ") Field Break: (" + Str_UnFormat( Field_Break) + ") Message Break: (" + Str_UnFormat( Message_Break) + ") Message Tail: (" + Str_UnFormat( Message_Tail) + ") Keep Message Break: (" + Keep_Message_Break + ") Message Skip: (" + Message_Skip + ") Message Count: (" + Message_Count + ") Repeat Count: (" + Repeat_Count + ")");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
private void Print_Args( ) throws Exception
|
||||
{
|
||||
System.out.println( "Output QueueMng Name: (" + QMng_Name + ") Output MsgQueue Name: (" + MsgQ_Name + ") Input File Name: (" + File_Name + ")");
|
||||
System.out.println( "Sleep Time: (" + Sleep_Time + ") Field Break: (" + Str_UnFormat( Field_Break) + ") Message Break: (" + Str_UnFormat( Message_Break) + ") Message Tail: (" + Str_UnFormat( Message_Tail) + ") Keep Message Break: (" + Keep_Message_Break + ") Message Skip: (" + Message_Skip + ") Message Count: (" + Message_Count + ") Repeat Count: (" + Repeat_Count + ")");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public MQSLoad( String args[])
|
||||
{
|
||||
int msg_nb;
|
||||
int msg_nb = 0;
|
||||
int loop;
|
||||
long time_begin, time_end;
|
||||
double time_elapsed, speed;
|
||||
NumberFormat nf = NumberFormat.getInstance();
|
||||
@ -605,11 +700,9 @@ public class MQSLoad
|
||||
{
|
||||
System.out.println("MQSLoad: " + MQSLoad_Tag + " / " + MQSLoad_Date + " / " + MQSLoad_Author);
|
||||
|
||||
if( ( args.length < 2) || ( args.length > 8))
|
||||
if( ( args.length < 2) || ( args.length > 19))
|
||||
{
|
||||
System.out.println( "Usage: MQSLoad [-qm \"Output_QueueMng_Name\"] [-st \"sleep_time\"] [-fb \"field_break\"] [-mb \"message_break\"] [-mt \"message_tail\"] [-kmb] <Output_MsgQueue_Name> <Input_File_Name>");
|
||||
System.out.println( " Default: Output QueueMng Name: (" + QMng_Name + ") Sleep Time: (" + Sleep_Time + ") Field Break: (" + Str_UnFormat( Field_Break) + ") Message Break: (" + Str_UnFormat( Message_Break) + ") Message Tail: (" + Str_UnFormat( Message_Tail) + ") Keep Message Break: (" + Keep_Message_Break + ")");
|
||||
|
||||
Print_Usage();
|
||||
System.exit( 1);
|
||||
}
|
||||
else
|
||||
@ -618,21 +711,39 @@ public class MQSLoad
|
||||
|
||||
Arg_Parse( args);
|
||||
|
||||
System.out.println( "Output QueueMng Name: (" + QMng_Name + ") Output MsgQueue Name: (" + MsgQ_Name + ") Input File Name: (" + File_Name + ")");
|
||||
System.out.println( "Sleep Time: (" + Sleep_Time + ") Field Break: (" + Str_UnFormat( Field_Break) + ") Message Break: (" + Str_UnFormat( Message_Break) + ") Message Tail: (" + Str_UnFormat( Message_Tail) + ") Keep Message Break: (" + Keep_Message_Break + ")");
|
||||
Print_Args();
|
||||
|
||||
MQSInit();
|
||||
|
||||
try
|
||||
{
|
||||
BufferedInputStream input_file = new BufferedInputStream( new FileInputStream( File_Name));
|
||||
RandomAccessFile input_file = new RandomAccessFile( File_Name, "r");
|
||||
|
||||
try
|
||||
{
|
||||
// System.out.println("Input File Open: (" + input_file + ") !");
|
||||
|
||||
time_begin = System.currentTimeMillis();
|
||||
msg_nb = Load_File( input_file);
|
||||
|
||||
for( loop = 0; loop < Repeat_Count; loop++ )
|
||||
{
|
||||
try
|
||||
{
|
||||
input_file.seek(0);
|
||||
}
|
||||
|
||||
catch( Exception Expt)
|
||||
{
|
||||
if( Repeat_Count > 1)
|
||||
{
|
||||
System.out.println( "Repeat Count should be 1 for non seekable file !");
|
||||
throw Expt;
|
||||
}
|
||||
}
|
||||
|
||||
msg_nb = Load_File( input_file, Message_Skip, Message_Count, msg_nb);
|
||||
}
|
||||
|
||||
time_end = System.currentTimeMillis();
|
||||
|
||||
time_elapsed = ( time_end - time_begin) / 1000.0;
|
||||
@ -641,6 +752,7 @@ public class MQSLoad
|
||||
nf.setMinimumFractionDigits(2);
|
||||
nf.setMaximumFractionDigits(2);
|
||||
|
||||
System.out.println( "\n");
|
||||
System.out.println( "Loaded Message Nb: (" + msg_nb
|
||||
+ ") Elapsed Time: (" + nf.format(time_elapsed)
|
||||
+ ") s Speed: (" + nf.format(speed)
|
||||
@ -677,5 +789,10 @@ public class MQSLoad
|
||||
System.exit( 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,25 @@
|
||||
# $RCSfile: ReleaseNotes.txt,v $
|
||||
# $Revision: 1.11 $
|
||||
# $Revision: 1.12 $
|
||||
# $Name: $
|
||||
# $Date: 2008/11/14 00:00:51 $
|
||||
# $Date: 2008/12/04 10:45:06 $
|
||||
# $Author: agibert $
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
MQSLoad V 2.0.0 - A. Gibert - 2008/12/03
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
- Major code cleanup,
|
||||
- Add message skip option "-ms",
|
||||
- Add message count option "-mc",
|
||||
- Add repeat count option "-rc",
|
||||
- Fix Java 1.4 compatibility.
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
MQSLoad V 1.3.2 - A. Gibert - 2008/11/14
|
||||
--------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user