From 0c88d68c228507876f113bf62f31168c54490475 Mon Sep 17 00:00:00 2001 From: agibert Date: Fri, 12 Dec 2008 00:08:11 +0000 Subject: [PATCH] - Add character convert option "-cc", - Add best effort mode "-bem", - Add error message count. --- MQSSave.java | 400 +++++++---------------------------------------- ReleaseNotes.txt | 11 +- 2 files changed, 65 insertions(+), 346 deletions(-) diff --git a/MQSSave.java b/MQSSave.java index 3f8fa20..e699c96 100644 --- a/MQSSave.java +++ b/MQSSave.java @@ -1,7 +1,7 @@ // $RCSfile: MQSSave.java,v $ -// $Revision: 1.16 $ +// $Revision: 1.17 $ // $Name: $ -// $Date: 2008/12/11 13:52:05 $ +// $Date: 2008/12/12 00:08:11 $ // $Author: agibert $ /* @@ -35,15 +35,16 @@ import java.text.*; public class MQSSave { - private String MQSSave_Revision = "$Revision: 1.16 $"; + private String MQSSave_Revision = "$Revision: 1.17 $"; private String MQSSave_Tag = "$Name: $"; - private String MQSSave_Date = "$Date: 2008/12/11 13:52:05 $"; + private String MQSSave_Date = "$Date: 2008/12/12 00:08:11 $"; private String MQSSave_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_INPUT_AS_Q_DEF | MQC.MQOO_FAIL_IF_QUIESCING | MQC.MQOO_BROWSE | MQC.MQOO_INQUIRE; + private boolean Character_Convert = false; private int Character_Set = 1208; private Integer Sleep_Time = 0; private String Message_Break = "\r\n"; @@ -53,10 +54,13 @@ public class MQSSave private boolean Copy_Mode = false; private boolean Trim_Mode = false; private boolean MBTrailer_Mode = false; + private boolean Best_Effort_Mode = false; private String Output_File_Name; private int Msg_Counter = 0; private int Msg_Saved_Nb = 0; private int Msg_Skiped_Nb = 0; + private int Msg_Error_Nb = 0; + private boolean CC_Error = false; @@ -223,6 +227,10 @@ public class MQSSave throw new Exception(); } } + else if ( args[argc].equals( "-cc")) + { + Character_Convert = true; + } else if ( args[argc].equals( "-cs")) { if( argc < ( args.length + 1)) @@ -271,6 +279,10 @@ public class MQSSave { MBTrailer_Mode = true; } + else if ( args[argc].equals( "-bem")) + { + Best_Effort_Mode = true; + } else if ( args[argc].equals( "-ms")) { if( argc < ( args.length + 1)) @@ -420,13 +432,18 @@ public class MQSSave { if( First) { - gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_BROWSE_FIRST | MQC.MQGMO_CONVERT; + gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_BROWSE_FIRST; } else { - gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_BROWSE_NEXT | MQC.MQGMO_CONVERT; + gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_BROWSE_NEXT; } - + + if( Character_Convert) + { + gmo.options = gmo.options | MQC.MQGMO_CONVERT; + } + gmo.matchOptions = MQC.MQMO_NONE; MsgQ.get( Msg, gmo); @@ -436,15 +453,21 @@ public class MQSSave catch( MQException Expt) { - if( ( Expt.completionCode != 2) || (Expt.reasonCode != 2033)) + if( ( Expt.completionCode == 2) && (Expt.reasonCode == 2033)) { - // System.out.println("Exception: (" + Expt + ") !!!"); - throw Expt; + /* no more messages */ + return( null); } - // System.out.println("Exception: (" + Expt + ") !!!"); - - return( null); + if( Best_Effort_Mode && ( Expt.completionCode == 1) && (Expt.reasonCode == 2110)) + { + /* caracter convertion error */ + CC_Error = true; + + return( null); + } + + throw Expt; } catch( Exception Expt) @@ -504,35 +527,6 @@ public class MQSSave System.out.print( Mark); Msg_Counter++; - - /* - switch( Mark) - { - case '.': - { - Moved_Nb++; - break; - } - - case '*': - { - Flushed_Nb++; - break; - } - - case '#': - { - Skiped_Nb++; - break; - } - - case '~': - { - Scaned_Nb++; - break; - } - } - */ } @@ -565,299 +559,6 @@ public class MQSSave - //------------------------------------------------------------------------------------------------------------------------- - // - //------------------------------------------------------------------------------------------------------------------------- - - // private void Save_File( BufferedOutputStream Output_File, BufferedOutputStream Flush_File) throws Exception - // { - // MQMessage input_msg = new MQMessage(); - // byte[] buffer_byte; - // short mode; - // final short MODE_FLUSH = 0; - // 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 - // { - // input_msg.format = MQC.MQFMT_STRING; - - // if( TI_Swift_Batch_Mode) - // { - // mode = MODE_SCAN; - // } - // else - // { - // mode = MODE_FULLMOVE; - // } - - // do - // { - // input_msg = MQSGet_Msg( input_msg, get_first); - - // if( input_msg != null) - // { - // if( mode == MODE_FULLMOVE) - // { - // Counter_Print( Total_Nb++, '.'); - - // Stand_By( Sleep_Time); - - // if( Moved_Nb > 1) - // { - // Output_File.write( Message_Break.getBytes()); - // } - - // buffer_byte = new byte[ input_msg.getMessageLength()]; - // 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); - - // if( Copy_Mode == false ) - // { - // 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 - // { - // // System.out.print( "FB2 "); - // mode = MODE_SCAN; - - // first_flush = true; - // } - // } - // 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) - // { - // 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) - // { - // Output_File.write( Message_Break.getBytes()); - // } - - // System.out.println( "\n"); - // } - - // catch( Exception Expt) - // { - // // System.out.println("Exception: (" + Expt + ") !!!"); - // throw Expt; - // } - // } - - - - - //------------------------------------------------------------------------------------------------------------------------- // //------------------------------------------------------------------------------------------------------------------------- @@ -891,7 +592,19 @@ public class MQSSave } else { - return(false); + if( CC_Error) + { + CC_Error = false; + + Counter_Print( "*"); + Msg_Error_Nb++; + + return(true); + } + else + { + return(false); + } } } } @@ -914,7 +627,7 @@ public class MQSSave try { - input_msg.format = MQC.MQFMT_STRING; + // input_msg.format = MQC.MQFMT_STRING; /* Loop while Msg_Count not reatch */ while( Msg_Get( input_msg, msg_id, Msg_Skip, Msg_Count, get_first)) @@ -923,7 +636,9 @@ public class MQSSave if( msg_id >= Msg_Skip) { - if( Msg_Saved_Nb > 0) + /* This message is not skiped */ + + if( Msg_Saved_Nb > 1) { Output_File.write( Message_Break.getBytes()); } @@ -970,8 +685,8 @@ public class MQSSave private void Usage_Print( ) throws Exception { - System.out.println( "Usage: MQSSave [-qm \"Input_QueueMng_Name\"] [-cs \"character_set\"] [-st \"sleep_time\"] [-mb \"message_break\"] [-cm] [-tm] [-mbtm] [-ms \"message_skip\"] [-mc \"message_count\"] [-rc \"repeat_count\"] "); - System.out.println( " Default: Input QueueMng Name: (" + QMng_Name + ") 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 + ") Message Skip: (" + Message_Skip + ") Message Count: (" + Message_Count + ") Repeat Count: (" + Repeat_Count + ")"); + System.out.println( "Usage: MQSSave [-qm \"Input_QueueMng_Name\"] [-cc \"character_convert\"] [-cs \"character_set\"] [-st \"sleep_time\"] [-mb \"message_break\"] [-cm] [-tm] [-mbtm] [-bem] [-ms \"message_skip\"] [-mc \"message_count\"] [-rc \"repeat_count\"] "); + 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 + ")"); } @@ -985,7 +700,7 @@ public class MQSSave 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 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 + ")) Message Skip: (" + Message_Skip + ") Message Count: (" + Message_Count + ") Repeat Count: (" + Repeat_Count + ")"); + 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 + ")"); } @@ -1028,7 +743,7 @@ public class MQSSave { output_file = new BufferedOutputStream( new FileOutputStream( Output_File_Name)); - System.out.println( "Legend: .: Saved #: Skiped"); + System.out.println( "Legend: .: Saved #: Skiped *: Error"); try { @@ -1060,6 +775,7 @@ public class MQSSave System.out.println( ""); System.out.println( "Saved Message Nb: (" + Msg_Saved_Nb + ") Skiped Messages Nb: (" + Msg_Skiped_Nb + + ") Error Messages Nb: (" + Msg_Error_Nb + ") Elapsed Time: (" + nf.format(time_elapsed) + ") s Speed: (" + nf.format(speed) + ") msg/s"); diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index e964e81..3f2c6b4 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -1,7 +1,7 @@ # $RCSfile: ReleaseNotes.txt,v $ -# $Revision: 1.13 $ +# $Revision: 1.14 $ # $Name: $ -# $Date: 2008/12/11 13:52:05 $ +# $Date: 2008/12/12 00:08:11 $ # $Author: agibert $ @@ -9,7 +9,7 @@ -------------------------------------------------------------------------------- -MQSSave V 2.0.0 - A. Gibert - 2008/12/11 +MQSSave V 2.0.0 - A. Gibert - 2008/12/12 -------------------------------------------------------------------------------- - Major code rewrite and cleanup, @@ -18,7 +18,10 @@ MQSSave V 2.0.0 - A. Gibert - 2008/12/11 - Add message skip option "-ms", - Add message count option "-mc", - Add repeat count option "-rc", -- Add character set option "-cs". +- Add character convert option "-cc", +- Add character set option "-cs", +- Add best effort mode "-bem", +- Add error message count.