Compare commits

...

10 Commits

Author SHA1 Message Date
agibert
e461670367 - Add MQV7 support (Thanks to Yves MOYROUD !) 2013-11-08 17:17:12 +00:00
agibert
89c00936c2 Fix release date. 2009-01-05 17:41:42 +00:00
agibert
2d3d359d79 Document new options and add an example. 2009-01-05 17:40:17 +00:00
agibert
5904264927 Fix MQMessage character set handling,
Fix character set error handling.
2009-01-05 17:32:49 +00:00
agibert
c4d5a98daa Initial release. 2009-01-05 17:29:19 +00:00
agibert
f45cc9b0b1 - Fix usage print out. 2008-12-18 17:25:42 +00:00
agibert
94c2d94032 - Fix "-cc" usage print,
- Fix Java 1.4 compatibility,
- Add 2150 reason code handling in best effort mode.
2008-12-12 10:44:19 +00:00
agibert
0c88d68c22 - Add character convert option "-cc",
- Add best effort mode "-bem",
- Add error message count.
2008-12-12 00:08:11 +00:00
agibert
d53cbc6c99 - Major code rewrite and cleanup,
- Add binary data support,
- drop obsolete TI swift batch mode support,
- Add message skip option "-ms",
- Add message count option "-mc",
- Add repeat count option "-rc",
- Add character set option "-cs".
2008-12-11 13:52:05 +00:00
agibert
6c20aac629 Fix elapsed time computation ! 2008-11-10 01:52:00 +00:00
6 changed files with 817 additions and 833 deletions

View File

@ -1,12 +1,12 @@
// $RCSfile: MQSSave.java,v $ // $RCSfile: MQSSave.java,v $
// $Revision: 1.14 $ // $Revision: 1.21 $
// $Name: $ // $Name: $
// $Date: 2008/01/03 13:46:01 $ // $Date: 2013/11/08 17:17:12 $
// $Author: agibert $ // $Author: agibert $
/* /*
* MQSSave.java - MQ/Series queue to data file saver * MQSSave.java - MQ/Series queue to data file saver
* Copyright (C) 2001-2006 Arnaud G. Gibert * Copyright (C) 2001-2008 Arnaud G. Gibert
* mailto:arnaud@rx3.net * mailto:arnaud@rx3.net
* http://www.rx3.org/dvp/MQSLoad * http://www.rx3.org/dvp/MQSLoad
* *
@ -26,33 +26,41 @@
*/ */
import com.ibm.mq.*; import com.ibm.mq.*;
import com.ibm.mq.constants.*;
import java.io.*; import java.io.*;
import java.text.*; import java.text.*;
public class MQSSave public class MQSSave
{ {
private String MQSSave_Revision = "$Revision: 1.21 $";
private String MQSSave_Tag = "$Name: $";
private String MQSSave_Date = "$Date: 2013/11/08 17:17:12 $";
private String MQSSave_Author = "$Author: agibert $";
private MQQueueManager QMng = null; private MQQueueManager QMng = null;
private String QMng_Name = ""; private String QMng_Name = "";
private MQQueue MsgQ; private MQQueue MsgQ;
private String MsgQ_Name; private String MsgQ_Name;
private int MsgQ_Open_Options = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_FAIL_IF_QUIESCING | MQC.MQOO_BROWSE | MQC.MQOO_INQUIRE; private int MsgQ_Open_Options = CMQC.MQOO_INPUT_AS_Q_DEF | CMQC.MQOO_FAIL_IF_QUIESCING | CMQC.MQOO_BROWSE | CMQC.MQOO_INQUIRE;
private String Output_File_Name, Flush_File_Name = "flush.txt"; private boolean Character_Convert = false;
private int Character_Set = 1208;
private int Sleep_Time = 0;
private String Message_Break = "\r\n"; private String Message_Break = "\r\n";
private boolean TI_Swift_Batch_Mode = false; private int Message_Skip = 0;
private int Message_Count = 0;
private int Repeat_Count = 1;
private boolean Copy_Mode = false; private boolean Copy_Mode = false;
private boolean Trim_Mode = false; private boolean Trim_Mode = false;
private boolean MBTrailer_Mode = false; private boolean MBTrailer_Mode = false;
private int Total_Nb = 0, Moved_Nb = 0, Skiped_Nb = 0, Scaned_Nb = 0, Flushed_Nb = 0; private boolean Best_Effort_Mode = false;
private String MQSSave_Revision = "$Revision: 1.14 $"; private String Output_File_Name;
private String MQSSave_Tag = "$Name: $"; private int Msg_Counter = 0;
private String MQSSave_Date = "$Date: 2008/01/03 13:46:01 $"; private int Msg_Saved_Nb = 0;
private String MQSSave_Author = "$Author: agibert $"; private int Msg_Skiped_Nb = 0;
private Integer Sleep_Time = 0; private int Msg_Error_Nb = 0;
private boolean CC_Error = false;
@ -198,7 +206,7 @@ public class MQSSave
// //
//------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------
private void Arg_Parse( String args[]) throws Exception private void Args_Parse( String args[]) throws Exception
{ {
int argc = 0; int argc = 0;
@ -219,23 +227,15 @@ public class MQSSave
throw new Exception(); throw new Exception();
} }
} }
else if ( args[argc].equals( "-mb")) else if ( args[argc].equals( "-cc"))
{
Character_Convert = true;
}
else if ( args[argc].equals( "-cs"))
{ {
if( argc < ( args.length + 1)) if( argc < ( args.length + 1))
{ {
Message_Break = Str_Format( args[++argc]); Character_Set = Integer.parseInt( args[++argc]);
}
else
{
System.out.println( "Invalid number of command line options...");
throw new Exception();
}
}
else if ( args[argc].equals( "-ffn"))
{
if( argc < ( args.length + 1))
{
Flush_File_Name = args[++argc];
} }
else else
{ {
@ -255,30 +255,22 @@ public class MQSSave
throw new Exception(); throw new Exception();
} }
} }
else if ( args[argc].equals( "-tisbm")) else if ( args[argc].equals( "-mb"))
{ {
if( Copy_Mode == false) if( argc < ( args.length + 1))
{ {
TI_Swift_Batch_Mode = true; Message_Break = Str_Format( args[++argc]);
} }
else else
{ {
System.out.println( "Invalid command line option combination: -tisbm and -cm..."); System.out.println( "Invalid number of command line options...");
throw new Exception(); throw new Exception();
} }
} }
else if ( args[argc].equals( "-cm")) else if ( args[argc].equals( "-cm"))
{
if( TI_Swift_Batch_Mode == false)
{ {
Copy_Mode = true; Copy_Mode = true;
} }
else
{
System.out.println( "Invalid command line option combination: -tisbm and -cm...");
throw new Exception();
}
}
else if ( args[argc].equals( "-tm")) else if ( args[argc].equals( "-tm"))
{ {
Trim_Mode = true; Trim_Mode = true;
@ -287,6 +279,46 @@ public class MQSSave
{ {
MBTrailer_Mode = true; MBTrailer_Mode = true;
} }
else if ( args[argc].equals( "-bem"))
{
Best_Effort_Mode = true;
}
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 else
{ {
Output_File_Name = args[argc++]; Output_File_Name = args[argc++];
@ -328,7 +360,7 @@ public class MQSSave
try try
{ {
QMng = new MQQueueManager( QMng_Name); QMng = new MQQueueManager( QMng_Name);
// System.out.println( "QManager Open: (" + QMng + ") !"); // System.out.println( "QManager Open: (" + QMng + ") !");
} }
catch( Exception Expt) catch( Exception Expt)
@ -345,7 +377,7 @@ public class MQSSave
try try
{ {
MsgQ = QMng.accessQueue( MsgQ_Name, MsgQ_Open_Options, null, null, null); MsgQ = QMng.accessQueue( MsgQ_Name, MsgQ_Open_Options, null, null, null);
// System.out.println( "MsgQ Open: (" + MsgQ + ") !"); // System.out.println( "MsgQ Open: (" + MsgQ + ") !");
MQException.log = null; MQException.log = null;
} }
@ -353,7 +385,7 @@ public class MQSSave
catch( Exception Expt) catch( Exception Expt)
{ {
QMng.disconnect(); QMng.disconnect();
// System.out.println( "QManager Close: (" + QMng + ") !"); // System.out.println( "QManager Close: (" + QMng + ") !");
throw Expt; throw Expt;
} }
@ -372,9 +404,9 @@ public class MQSSave
try try
{ {
MsgQ.close(); MsgQ.close();
// System.out.println( "MsgQ Close: (" + MsgQ + ") !"); // System.out.println( "MsgQ Close: (" + MsgQ + ") !");
QMng.disconnect(); QMng.disconnect();
// System.out.println( "QManager Close: (" + QMng + ") !"); // System.out.println( "QManager Close: (" + QMng + ") !");
} }
catch( Exception Expt) catch( Exception Expt)
@ -400,14 +432,19 @@ public class MQSSave
{ {
if( First) if( First)
{ {
gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_BROWSE_FIRST | MQC.MQGMO_CONVERT; gmo.options = CMQC.MQGMO_NO_WAIT | CMQC.MQGMO_BROWSE_FIRST;
} }
else else
{ {
gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_BROWSE_NEXT | MQC.MQGMO_CONVERT; gmo.options = CMQC.MQGMO_NO_WAIT | CMQC.MQGMO_BROWSE_NEXT;
} }
gmo.matchOptions = MQC.MQMO_NONE; if( Character_Convert)
{
gmo.options = gmo.options | CMQC.MQGMO_CONVERT;
}
gmo.matchOptions = CMQC.MQMO_NONE;
MsgQ.get( Msg, gmo); MsgQ.get( Msg, gmo);
@ -416,15 +453,23 @@ public class MQSSave
catch( MQException Expt) catch( MQException Expt)
{ {
if( ( Expt.completionCode != 2) || (Expt.reasonCode != 2033)) if( ( Expt.completionCode == 2) && ( Expt.reasonCode == 2033))
{ {
//System.out.println("Exception: (" + Expt + ") !!!"); /* no more messages */
throw Expt; return( null);
} }
if( Best_Effort_Mode && ( Expt.completionCode == 1) && ( ( Expt.reasonCode == 2110) || ( Expt.reasonCode == 2150)))
{
/* caracter convertion error */
CC_Error = true;
return( null); return( null);
} }
throw Expt;
}
catch( Exception Expt) catch( Exception Expt)
{ {
//System.out.println("Exception: (" + Expt + ") !!!"); //System.out.println("Exception: (" + Expt + ") !!!");
@ -447,8 +492,8 @@ public class MQSSave
try try
{ {
gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_CONVERT; gmo.options = CMQC.MQGMO_NO_WAIT | CMQC.MQGMO_CONVERT;
gmo.matchOptions = MQC.MQMO_MATCH_MSG_ID; gmo.matchOptions = CMQC.MQMO_MATCH_MSG_ID;
MsgQ.get( Msg, gmo); MsgQ.get( Msg, gmo);
} }
@ -467,46 +512,21 @@ public class MQSSave
// //
//------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------
private void Counter_Print( int Msg_Nb, char Mark) private void Counter_Print( String Mark)
{ {
if( ( Msg_Nb % 50) == 0) if( ( Msg_Counter % 50) == 0)
{ {
System.out.print( "\n(" + Msg_Nb + ")\t"); System.out.print( "\n(" + Msg_Counter + ")\t");
} }
if( ( Msg_Nb % 10) == 0) if( ( Msg_Counter % 10) == 0)
{ {
System.out.print( " "); System.out.print( " ");
} }
System.out.print( Mark); System.out.print( Mark);
switch( Mark) Msg_Counter++;
{
case '.':
{
Moved_Nb++;
break;
}
case '*':
{
Flushed_Nb++;
break;
}
case '#':
{
Skiped_Nb++;
break;
}
case '~':
{
Scaned_Nb++;
break;
}
}
} }
@ -517,7 +537,7 @@ public class MQSSave
// //
//------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------
private void Stand_By(int timer) private void Stand_By(int timer) throws Exception
{ {
if( timer > 0) if( timer > 0)
{ {
@ -528,9 +548,9 @@ public class MQSSave
wait( timer); wait( timer);
} }
} }
catch(InterruptedException ie) catch(InterruptedException Expt)
{ {
ie.printStackTrace(); throw Expt;
} }
} }
} }
@ -543,287 +563,125 @@ public class MQSSave
// //
//------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------
private void Save_File( BufferedOutputStream Output_File, BufferedOutputStream Flush_File) throws Exception private boolean Msg_Get( MQMessage Input_Msg, int Msg_Id, int Msg_Skip, int Msg_Count, boolean Get_First) throws Exception
{
if( ( Msg_Count != 0) && ( Msg_Id >= ( Msg_Skip + Msg_Count)))
{
return(false);
}
else
{
Input_Msg = MQSGet_Msg( Input_Msg, Get_First);
if( Input_Msg != null)
{
if( Msg_Id < Msg_Skip)
{
Counter_Print( "#");
Msg_Skiped_Nb++;
}
else
{
Counter_Print( ".");
Msg_Saved_Nb++;
Stand_By( Sleep_Time);
}
return(true);
}
else
{
if( CC_Error)
{
Counter_Print( "*");
Msg_Error_Nb++;
return(true);
}
else
{
return(false);
}
}
}
}
//-------------------------------------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------------------------------
private void File_Save( BufferedOutputStream Output_File, int Msg_Skip, int Msg_Count, boolean Copy_Mode) throws Exception
{ {
MQMessage input_msg = new MQMessage(); MQMessage input_msg = new MQMessage();
byte[] buffer_byte; byte[] buffer;
short mode; int msg_id = 0;
final short MODE_FLUSH = 0; boolean get_first = true;
final short MODE_SCAN = 1;
final short MODE_MOVE = 2;
final short MODE_FULLMOVE = 3;
final short MSGTYPE_LEN = 10, FILLER_LEN = 128;
String msg_type;
final String TYPE_SWIFTBEGIN = "SWIFTBEGIN";
final String TYPE_SWIFTEND = "SWIFTEND ";
final String TYPE_SWIFTERROR = "SWIFTERROR";
final String TYPE_SWIFTOUT = "SWIFTOUT ";
boolean get_first = false;
boolean first_flush = true;
boolean first_scan = true;
try try
{ {
input_msg.format = MQC.MQFMT_STRING; // input_msg.format = CMQC.MQFMT_STRING;
input_msg.characterSet = Character_Set;
if( TI_Swift_Batch_Mode) /* Loop while Msg_Count not reatch */
while( Msg_Get( input_msg, msg_id, Msg_Skip, Msg_Count, get_first))
{ {
mode = MODE_SCAN; get_first = false;
}
else
{
mode = MODE_FULLMOVE;
}
do if( CC_Error == false)
{ {
input_msg = MQSGet_Msg( input_msg, get_first); /* This message is not in error */
if( input_msg != null) if( msg_id >= Msg_Skip)
{ {
if( mode == MODE_FULLMOVE) /* This message is not skiped */
{
Counter_Print( Total_Nb++, '.');
Stand_By( Sleep_Time); if( Msg_Saved_Nb > 1)
if( Moved_Nb > 1)
{ {
Output_File.write( Message_Break.getBytes()); Output_File.write( Message_Break.getBytes());
} }
buffer_byte = new byte[ input_msg.getMessageLength()]; buffer = new byte[ input_msg.getMessageLength()];
input_msg.readFully( buffer_byte); input_msg.readFully( buffer);
if( Trim_Mode) if( Trim_Mode)
{ {
String buffer_string = new String( buffer_byte).trim(); String buffer_string = new String( buffer).trim();
buffer_byte = buffer_string.getBytes(); buffer = buffer_string.getBytes();
} }
Output_File.write( buffer_byte, 0, buffer_byte.length); Output_File.write( buffer, 0, buffer.length);
if( Copy_Mode == false ) if( Copy_Mode == false )
{ {
MQSDelete_Msg( input_msg); MQSDelete_Msg( input_msg);
} }
} }
else
{
msg_type = input_msg.readString( MSGTYPE_LEN);
switch( mode)
{
case MODE_FLUSH:
{
if( msg_type.equals( TYPE_SWIFTBEGIN))
{
if( first_flush)
{
// System.out.print( "FB1 ");
Counter_Print( Total_Nb++, '#');
Stand_By( Sleep_Time);
MQSDelete_Msg( input_msg);
first_flush = false;
} }
else else
{ {
// System.out.print( "FB2 "); /* This message is in error */
mode = MODE_SCAN;
first_flush = true; CC_Error = false;
}
}
else if( msg_type.equals( TYPE_SWIFTEND) || msg_type.equals( TYPE_SWIFTERROR))
{
// System.out.print( "FEA ");
Counter_Print( Total_Nb++, '#');
Stand_By( Sleep_Time);
MQSDelete_Msg( input_msg);
}
else if( msg_type.equals( TYPE_SWIFTOUT))
{
// System.out.print( "FO ");
Counter_Print( Total_Nb++, '*');
Stand_By( Sleep_Time);
if( Flushed_Nb > 1)
{
Flush_File.write( Message_Break.getBytes());
} }
input_msg.readString( FILLER_LEN);
buffer_byte = new byte[ input_msg.getMessageLength() - MSGTYPE_LEN - FILLER_LEN];
input_msg.readFully( buffer_byte);
if( Trim_Mode) msg_id++;
{
String buffer_string = new String( buffer_byte).trim();
buffer_byte = buffer_string.getBytes();
} }
Flush_File.write( buffer_byte, 0, buffer_byte.length);
MQSDelete_Msg( input_msg);
}
else
{
System.out.println( "Invalid msg_type: (" + msg_type + ") !");
throw new Exception();
}
break;
}
case MODE_SCAN:
{
get_first = false;
if( first_scan)
{
if( msg_type.equals( TYPE_SWIFTBEGIN))
{
// System.out.print( "SB1 ");
first_scan = false;
}
else
{
// System.out.print( "SAEO ");
mode = MODE_FLUSH;
get_first = true;
first_scan = true;
}
}
else if( msg_type.equals( TYPE_SWIFTBEGIN))
{
// System.out.print( "SB2 ");
mode = MODE_FLUSH;
get_first = true;
first_scan = true;
}
else if( msg_type.equals( TYPE_SWIFTERROR))
{
// System.out.print( "SA ");
mode = MODE_FLUSH;
get_first = true;
first_scan = true;
}
else if( msg_type.equals( TYPE_SWIFTEND))
{
// System.out.print( "SE ");
mode = MODE_MOVE;
get_first = true;
first_scan = true;
}
else if( msg_type.equals( TYPE_SWIFTOUT))
{
// System.out.print( "SO ");
}
else
{
System.out.println( "Invalid msg_type: (" + msg_type + ") !");
throw new Exception();
}
Counter_Print( Total_Nb++, '~');
Stand_By( Sleep_Time);
break;
}
case MODE_MOVE:
{
if( msg_type.equals( TYPE_SWIFTBEGIN))
{
// System.out.print( "MB ");
Counter_Print( Total_Nb++, '#');
Stand_By( Sleep_Time);
MQSDelete_Msg( input_msg);
}
else if( msg_type.equals( TYPE_SWIFTEND))
{
// System.out.print( "ME ");
Counter_Print( Total_Nb++, '#');
Stand_By( Sleep_Time);
MQSDelete_Msg( input_msg);
mode = MODE_SCAN;
get_first = true;
}
else if( msg_type.equals( TYPE_SWIFTERROR))
{
System.out.println( "Internal error: (" + msg_type + ") found during Move!");
throw new Exception();
}
else if( msg_type.equals( TYPE_SWIFTOUT))
{
// System.out.print( "MO ");
Counter_Print( Total_Nb++, '.');
Stand_By( Sleep_Time);
if( Moved_Nb > 1)
{
Output_File.write( Message_Break.getBytes());
}
input_msg.readString( FILLER_LEN);
buffer_byte = new byte[ input_msg.getMessageLength() - MSGTYPE_LEN - FILLER_LEN];
input_msg.readFully( buffer_byte);
if( Trim_Mode)
{
String buffer_string = new String( buffer_byte).trim();
buffer_byte = buffer_string.getBytes();
}
Output_File.write( buffer_byte, 0, buffer_byte.length);
MQSDelete_Msg( input_msg);
}
else
{
System.out.println( "Invalid msg_type: (" + msg_type + ") !");
throw new Exception();
}
break;
}
}
}
}
}
while( input_msg != null);
if( MBTrailer_Mode) if( MBTrailer_Mode)
{ {
Output_File.write( Message_Break.getBytes()); Output_File.write( Message_Break.getBytes());
} }
System.out.println( "\n");
} }
catch( Exception Expt) catch( Exception Expt)
{ {
// System.out.println("Exception: (" + Expt + ") !!!");
throw Expt; throw Expt;
} }
} }
@ -832,99 +690,116 @@ public class MQSSave
//-------------------------------------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------------------------------
private void Usage_Print( ) throws Exception
{
System.out.println( "Usage: MQSSave [-qm \"Input_QueueMng_Name\"] [-cc] [-cs \"character_set\"] [-st \"sleep_time\"] [-mb \"message_break\"] [-cm] [-tm] [-mbtm] [-bem] [-ms \"message_skip\"] [-mc \"message_count\"] [-rc \"repeat_count\"] <Output_File_Name> <Input_MsgQueue_Name>");
System.out.println( "");
System.out.println( " Default: Input QueueMng Name: (" + QMng_Name + ") Character Convert: (" + Character_Convert + ") Character Set: (" + Character_Set + ") Sleep Time: (" + Sleep_Time + ") Message Break: (" + Str_UnFormat( Message_Break) + ") Copy Mode: (" + Copy_Mode + ") Trim Mode: (" + Trim_Mode + ") MsgBreak Trailer Mode: (" + MBTrailer_Mode + ") Best Effort Mode: (" + Best_Effort_Mode + ") Message Skip: (" + Message_Skip + ") Message Count: (" + Message_Count + ") Repeat Count: (" + Repeat_Count + ")");
}
//-------------------------------------------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------------------------------
private void Args_Print( ) throws Exception
{
System.out.println( "Output File Name: (" + Output_File_Name + ") Input QueueMng Name: (" + QMng_Name + ") Input MsgQue Name: (" + MsgQ_Name + ")");
System.out.println( "Character Convert: (" + Character_Convert + ") Character Set: (" + Character_Set + ") Sleep Time: (" + Sleep_Time + ") Message Break: (" + Str_UnFormat( Message_Break) + ") Copy Mode: (" + Copy_Mode + ") Trim Mode: (" + Trim_Mode + ") MsgBreak Trailer Mode: (" + MBTrailer_Mode + ") Best Effort Mode: (" + Best_Effort_Mode + ") Message Skip: (" + Message_Skip + ") Message Count: (" + Message_Count + ") Repeat Count: (" + Repeat_Count + ")");
}
//------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------
// //
//------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------
public MQSSave( String args[]) public MQSSave( String args[])
{ {
int loop;
long time_begin, time_end; long time_begin, time_end;
double time_elapsed, speed; double time_elapsed, speed;
NumberFormat nf = NumberFormat.getInstance(); NumberFormat nf = NumberFormat.getInstance();
BufferedOutputStream Output_File = null, Flush_File = null; BufferedOutputStream output_file = null;
try try
{ {
System.out.println("MQSSave: " + MQSSave_Tag + " / " + MQSSave_Date + " / " + MQSSave_Author); System.out.println("MQSSave: " + MQSSave_Tag + " / " + MQSSave_Date + " / " + MQSSave_Author);
if( ( args.length < 2) || ( args.length > 7)) if( ( args.length < 2) || ( args.length > 19))
{ {
System.out.println( "Usage: MQSSave [-qm \"Input_QueueMng_Name\"] [-st \"sleep_time\"] [-mb \"message_break\"] [-tisbm [-ffn <Flush_File_Name>] | -cm ] [-tm] [-mbtm] <Output_File_Name> <Input_MsgQueue_Name>");
System.out.println( " Default: Input QueueMng Name: (" + QMng_Name + ") Sleep Time: (" + Sleep_Time + ") Message Break: (" + Str_UnFormat( Message_Break) + ") TI Swift Batch Mode: (" + TI_Swift_Batch_Mode + ") Copy Mode: (" + Copy_Mode + ") Flush File Name: (" + Flush_File_Name + ") Trim Mode: (" + Trim_Mode + ") MsgBreak Trailer Mode: (" + MBTrailer_Mode + ")");
Usage_Print();
System.exit( 1); System.exit( 1);
} }
else else
{ {
System.out.println( "MQS Save Starting..."); System.out.println( "MQS Save Starting...");
Arg_Parse( args); Args_Parse( args);
Args_Print();
System.out.println( "Output File Name: (" + Output_File_Name + ") Input QueueMng Name: (" + QMng_Name + ") Input MsgQue Name: (" + MsgQ_Name + ") Flush File Name: (" + Flush_File_Name + ")");
System.out.println( "Sleep Time: (" + Sleep_Time + ") Message Break: (" + Str_UnFormat( Message_Break) + ") TI Swift Batch Mode: (" + TI_Swift_Batch_Mode + ") Copy Mode: (" + Copy_Mode + ") Trim Mode: (" + Trim_Mode + ") MsgBreak Trailer Mode: (" + MBTrailer_Mode + ")");
MQSInit(); MQSInit();
try try
{ {
Output_File = new BufferedOutputStream( new FileOutputStream( Output_File_Name)); output_file = new BufferedOutputStream( new FileOutputStream( Output_File_Name));
if( TI_Swift_Batch_Mode) System.out.println( "Legend: .: Saved #: Skiped *: Error");
{
System.out.println( "Legend: .: Saved *: Flushed #: Skiped ~: Scaned");
Flush_File = new BufferedOutputStream( new FileOutputStream( Flush_File_Name));
}
try try
{ {
// System.out.println("Output File Open: (" + Output_file + ") !"); // System.out.println( "Output File Open: (" + output_file + ") !");
time_begin = System.currentTimeMillis(); time_begin = System.currentTimeMillis();
Save_File( Output_File, Flush_File);
for( loop = 0; loop < Repeat_Count; loop++ )
{
if( loop < ( Repeat_Count - 1))
{
File_Save( output_file, Message_Skip, Message_Count, true);
}
else
{
File_Save( output_file, Message_Skip, Message_Count, Copy_Mode);
}
}
time_end = System.currentTimeMillis(); time_end = System.currentTimeMillis();
time_elapsed = ( time_end - time_begin) / 100.0; time_elapsed = ( time_end - time_begin) / 1000.0;
speed = Total_Nb / time_elapsed; speed = Msg_Saved_Nb / time_elapsed;
nf.setMinimumFractionDigits(2); nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2); nf.setMaximumFractionDigits(2);
if( TI_Swift_Batch_Mode) System.out.println( "");
{ System.out.println( "");
System.out.println( "Saved Message Nb: (" + Moved_Nb + ") Skiped Message Nb: (" + Skiped_Nb + ") Flushed Message Nb: (" + Flushed_Nb + ") Scaned Message Nb: (" + Scaned_Nb + ")"); System.out.println( "Saved Message Nb: (" + Msg_Saved_Nb
System.out.println( "Total Message Nb: (" + Total_Nb + ") Skiped Messages Nb: (" + Msg_Skiped_Nb
+ ") Error Messages Nb: (" + Msg_Error_Nb
+ ") Elapsed Time: (" + nf.format(time_elapsed) + ") Elapsed Time: (" + nf.format(time_elapsed)
+ ") s Speed: (" + nf.format(speed) + ") s Speed: (" + nf.format(speed)
+ ") msg/s"); + ") msg/s");
} }
else
{
System.out.println( "Saved Message Nb: (" + Total_Nb
+ ") Elapsed Time: (" + nf.format(time_elapsed)
+ ") s Speed: (" + nf.format(speed)
+ ") msg/s");
}
}
catch( Exception Expt) catch( Exception Expt)
{ {
Output_File.close(); output_file.close();
if( TI_Swift_Batch_Mode)
{
Flush_File.close();
}
throw Expt; throw Expt;
} }
Output_File.close(); output_file.close();
if( TI_Swift_Batch_Mode)
{
Flush_File.close();
}
} }
catch( Exception Expt) catch( Exception Expt)
@ -949,4 +824,6 @@ public class MQSSave
} }
} }
//-------------------------------------------------------------------------------------------------------------------------
} }

View File

@ -1,7 +1,7 @@
# $RCSfile: ReadMe.txt,v $ # $RCSfile: ReadMe.txt,v $
# $Revision: 1.5 $ # $Revision: 1.6 $
# $Name: $ # $Name: $
# $Date: 2007/12/11 16:50:50 $ # $Date: 2009/01/05 17:40:17 $
# $Author: agibert $ # $Author: agibert $
@ -10,6 +10,7 @@
Compilation: Compilation:
------------ ------------
- Just type: "javac MQSSave.java" ! - Just type: "javac MQSSave.java" !
@ -21,10 +22,42 @@ Installation:
Usage:
------
MQSSave [-qm "Input_QueueMng_Name"] [-cc] [-cs "character_set"] [-st "sleep_time"] [-mb "message_break"] [-cm] [-tm] [-mbtm] [-bem] [-ms "message_skip"] [-mc "message_count"] [-rc "repeat_count"] <Output_File_Name> <Input_MsgQueue_Name>
Default: Input QueueMng Name: () Character Convert: (false) Character Set: (1208) Sleep Time: (0) Message Break: (\r\n) Copy Mode: (false) Trim Mode: (false) MsgBreak Trailer Mode: (false) Best Effort Mode: (false) Message Skip: (0) Message Count: (0) Repeat Count: (1)
Arguments:
----------
- Optional arguments:
-qm "Input_QueueMng_Name": Name of the queue manager to use,
-cc "character_convert": Switch on the caracter conversion (Set the MQGetMessageOptions to MQC.MQGMO_CONVERT),
-cs "character_set": MQMessage character set,
-st "sleep_time": Delay between message sending,
-mb "message_break": String used as message separator,
-cm "copy_mode": Don't remove messages from queue,
-tm "trim_mode": Remove trailing spaces at the message end,
-mbtm "msg_break_trailer_mode": Add a message break at the end of the last message,
-bem "best effort mode": Skip errors and continue to save the next message,
-ms "message_skip": Number of message to skip before to start the saving,
-mc "message_count": Number of message to save,
-rc "repeat_count": Number of time the whole process (start of file + skip + save) should be repeated.
- Mandatory arguments:
<Output_File_Name>: Name of the output file to save to,
<Input_MsgQueue_Name>: Name of the input message queue to save from.
Notes: Notes:
------ ------
- MQSSave has been tested with MQ/Series 5.2, 5.2, 5.3 and WMQ 6.0. - MQSSave has been tested with WMQ 6.0.
- "-mb" argument accept a string with formated escape character: - "-mb" argument accept a string with formated escape character:
+ "\n" for newline, + "\n" for newline,
@ -37,12 +70,9 @@ Notes:
- Windows text files: newline is specified as "\r\n", - Windows text files: newline is specified as "\r\n",
- Unix text files: newline is specified as "\n". - Unix text files: newline is specified as "\n".
- The Flush File is only used when TI Swift Batch Mode is enabled (by setting "-tisbm" command line switch).
- When trim mode is enabled (by setting "-tm" command line switch), all the trailing spaces are removed. - When trim mode is enabled (by setting "-tm" command line switch), all the trailing spaces are removed.
- By default Message break is "\r\n", - By default Message break is "\r\n",
- By default Flush File Name is "flush.txt".
- This software is under the GNU General Public License. See GNU-GPL.txt. - This software is under the GNU General Public License. See GNU-GPL.txt.
@ -54,5 +84,5 @@ Usage Example:
- To save the messages of the MQ/Series "SWIFT-QUEUE" queue into a swift batch file "swift-batch.txt" with "---MESSAGE-BREAK---" message separator use: - To save the messages of the MQ/Series "SWIFT-QUEUE" queue into a swift batch file "swift-batch.txt" with "---MESSAGE-BREAK---" message separator use:
java MQSSave -mb "---MESSAGE-BREAK---\r\n" swift-batch.txt SWIFT-QUEUE java MQSSave -mb "---MESSAGE-BREAK---\r\n" swift-batch.txt SWIFT-QUEUE
- To save the messages of the MQ/Series "SWIFT-QUEUE" queue into a swift batch file "swift-batch.txt" with no message break message and by using the TI Swift Batch Mode, use: - To save 10 times the third message of the MQ/Series "SWIFT-QUEUE" queue into a swift batch file "swift-batch.txt" with "---MESSAGE-BREAK---" message separator without removing it from the queue use:
java MQSSave -mb "" -tisbm swift-batch.txt SWIFT-QUEUE java MQSSave -mb "---MESSAGE-BREAK---\r\n" -cm -ms 2 -mc 1 -rc 10 swift-batch.txt SWIFT-QUEUE

View File

@ -1,13 +1,39 @@
# $RCSfile: ReleaseNotes.txt,v $ # $RCSfile: ReleaseNotes.txt,v $
# $Revision: 1.11 $ # $Revision: 1.16 $
# $Name: $ # $Name: $
# $Date: 2008/01/03 13:46:01 $ # $Date: 2009/01/05 17:41:42 $
# $Author: agibert $ # $Author: agibert $
--------------------------------------------------------------------------------
MQSSave V 2.0.0 - A. Gibert - 2009/01/05
--------------------------------------------------------------------------------
- Major code rewrite and cleanup,
- Add binary data support,
- Drop obsolete TI swift batch mode support,
- Add message skip option "-ms",
- Add message count option "-mc",
- Add repeat count option "-rc",
- Add character convert option "-cc",
- Add character set option "-cs",
- Add best effort mode "-bem",
- Add error message count,
- Fix Java 1.4 compatibility.
--------------------------------------------------------------------------------
MQSSave V 1.3.2 - A. Gibert - 2008/11/10
--------------------------------------------------------------------------------
Fix elapsed time computation !
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
MQSSave V 1.3.1 - A. Gibert - 2008/01/03 MQSSave V 1.3.1 - A. Gibert - 2008/01/03
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

1
test-charset-in-iso Normal file
View File

@ -0,0 +1 @@
ISO [И]

1
test-charset-in-utf Normal file
View File

@ -0,0 +1 @@
UTF8 [é]

49
test-charset.sh Executable file
View File

@ -0,0 +1,49 @@
#!/bin/bash
function file_load
{
out="$1"
in="$2"
cc="$3"
cs="$4"
echo -n "CC: [$cc] CS: [$cs] $(cat $in)" >$$.tmp
mqsload -mb '\n---\n' $cc -cs $cs $out $$.tmp
\rm $$.tmp
}
function file_save
{
out="$1"
in="$2"
cc="$3"
cs="$4"
cm="$5"
mqssave -mb '\n---\n' $cc -cs $cs $cm -bem $out $in
}
file_load DLQ test-charset-in-utf "-cc" 1208
file_load DLQ test-charset-in-utf "-cc" 819
file_load DLQ test-charset-in-iso "-cc" 1208
file_load DLQ test-charset-in-iso "-cc" 819
file_load DLQ test-charset-in-utf " " 1208
file_load DLQ test-charset-in-utf " " 819
file_load DLQ test-charset-in-iso " " 1208
file_load DLQ test-charset-in-iso " " 819
\rm test-charset-out-cc-utf test-charset-out-cc-iso test-charset-out-__-utf test-charset-out-__-iso
file_save test-charset-out-cc-utf DLQ "-cc" 1208 "-cm"
file_save test-charset-out-cc-iso DLQ "-cc" 819 "-cm"
file_save test-charset-out-__-utf DLQ " " 1208 "-cm"
file_save test-charset-out-__-iso DLQ " " 819 " "