diff --git a/MQSSave.java b/MQSSave.java index adcf7fb..3f8fa20 100644 --- a/MQSSave.java +++ b/MQSSave.java @@ -1,7 +1,7 @@ // $RCSfile: MQSSave.java,v $ -// $Revision: 1.15 $ +// $Revision: 1.16 $ // $Name: $ -// $Date: 2008/11/10 01:52:00 $ +// $Date: 2008/12/11 13:52:05 $ // $Author: agibert $ /* @@ -35,918 +35,1067 @@ import java.text.*; public class MQSSave { - 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 String Output_File_Name, Flush_File_Name = "flush.txt"; - private String Message_Break = "\r\n"; - private boolean TI_Swift_Batch_Mode = false; - private boolean Copy_Mode = false; - private boolean Trim_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 String MQSSave_Revision = "$Revision: 1.15 $"; - private String MQSSave_Tag = "$Name: $"; - private String MQSSave_Date = "$Date: 2008/11/10 01:52:00 $"; - private String MQSSave_Author = "$Author: agibert $"; - private Integer Sleep_Time = 0; + private String MQSSave_Revision = "$Revision: 1.16 $"; + private String MQSSave_Tag = "$Name: $"; + private String MQSSave_Date = "$Date: 2008/12/11 13:52:05 $"; + 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 int Character_Set = 1208; + private Integer Sleep_Time = 0; + private String Message_Break = "\r\n"; + private int Message_Skip = 0; + private int Message_Count = 0; + private int Repeat_Count = 1; + private boolean Copy_Mode = false; + private boolean Trim_Mode = false; + private boolean MBTrailer_Mode = false; + private String Output_File_Name; + private int Msg_Counter = 0; + private int Msg_Saved_Nb = 0; + private int Msg_Skiped_Nb = 0; - - //------------------------------------------------------------------------------------------------------------------------- - // - //------------------------------------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- - public static void main( String args[]) - { - new MQSSave( args); - } + public static void main( String args[]) + { + new MQSSave( args); + } - //------------------------------------------------------------------------------------------------------------------------- - // - //------------------------------------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- - public static String Str_Format( String UnFmt) - { - int idx; - boolean esc = false; - String fmt = ""; + public static String Str_Format( String UnFmt) + { + int idx; + boolean esc = false; + String fmt = ""; - for( idx = 0; idx < UnFmt.length(); idx++) - { - if( esc) - { - switch( UnFmt.charAt( idx)) - { - case '\\': - { - fmt += "\\"; - break; - } + for( idx = 0; idx < UnFmt.length(); idx++) + { + if( esc) + { + switch( UnFmt.charAt( idx)) + { + case '\\': + { + fmt += "\\"; + break; + } - case 'n': - { - fmt += "\n"; - break; - } + case 'n': + { + fmt += "\n"; + break; + } - case 'r': - { - fmt += "\r"; - break; - } + case 'r': + { + fmt += "\r"; + break; + } - case 't': - { - fmt += "\t"; - break; - } + case 't': + { + fmt += "\t"; + break; + } - default: - { - fmt += "?"; - break; - } - } + default: + { + fmt += "?"; + break; + } + } - esc = false; - } - else - { - if( UnFmt.charAt( idx) == '\\') - { - esc = true; - } - else - { - fmt += UnFmt.charAt( idx); - } - } - } - - 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); - } - - - - - - //------------------------------------------------------------------------------------------------------------------------- - // - //------------------------------------------------------------------------------------------------------------------------- - - private void Arg_Parse( String args[]) throws Exception - { - int argc = 0; - - - try - { - while( argc < args.length) - { - if ( args[argc].equals( "-qm")) - { - if( argc < ( args.length + 1)) - { - QMng_Name = Str_Format( args[++argc]); - } - else - { - System.out.println( "Invalid number of command line options..."); - throw new Exception(); - } - } - else if ( args[argc].equals( "-mb")) - { - if( argc < ( args.length + 1)) - { - Message_Break = Str_Format( 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 - { - System.out.println( "Invalid number of command line options..."); - throw new Exception(); - } - } - else if ( args[argc].equals( "-st")) - { - if( argc < ( args.length + 1)) - { - Sleep_Time = Integer.parseInt( args[++argc]); - } - else - { - System.out.println( "Invalid number of command line options..."); - throw new Exception(); - } - } - else if ( args[argc].equals( "-tisbm")) - { - if( Copy_Mode == false) - { - TI_Swift_Batch_Mode = true; - } - else - { - System.out.println( "Invalid command line option combination: -tisbm and -cm..."); - throw new Exception(); - } - } - else if ( args[argc].equals( "-cm")) - { - if( TI_Swift_Batch_Mode == false) - { - Copy_Mode = true; - } - else - { - System.out.println( "Invalid command line option combination: -tisbm and -cm..."); - throw new Exception(); - } - } - else if ( args[argc].equals( "-tm")) - { - Trim_Mode = true; - } - else if ( args[argc].equals( "-mbtm")) - { - MBTrailer_Mode = true; - } - else - { - Output_File_Name = args[argc++]; - MsgQ_Name = args[argc++]; - - if( argc < args.length) - { - System.out.println( "Invalid number of command line options..."); - throw new Exception(); - } - } - - ++argc; - } - } - - catch( Exception Expt) - { - throw Expt; - } + esc = false; + } + else + { + if( UnFmt.charAt( idx) == '\\') + { + esc = true; + } + else + { + fmt += UnFmt.charAt( idx); + } + } } + + 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); + } + + + + + + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- + + private void Args_Parse( String args[]) throws Exception + { + int argc = 0; + + + try + { + while( argc < args.length) + { + if ( args[argc].equals( "-qm")) + { + if( argc < ( args.length + 1)) + { + QMng_Name = Str_Format( args[++argc]); + } + else + { + System.out.println( "Invalid number of command line options..."); + throw new Exception(); + } + } + else if ( args[argc].equals( "-cs")) + { + if( argc < ( args.length + 1)) + { + Character_Set = Integer.parseInt( args[++argc]); + } + else + { + System.out.println( "Invalid number of command line options..."); + throw new Exception(); + } + } + else if ( args[argc].equals( "-st")) + { + if( argc < ( args.length + 1)) + { + Sleep_Time = Integer.parseInt( args[++argc]); + } + else + { + System.out.println( "Invalid number of command line options..."); + throw new Exception(); + } + } + else if ( args[argc].equals( "-mb")) + { + if( argc < ( args.length + 1)) + { + Message_Break = Str_Format( args[++argc]); + } + else + { + System.out.println( "Invalid number of command line options..."); + throw new Exception(); + } + } + else if ( args[argc].equals( "-cm")) + { + Copy_Mode = true; + } + else if ( args[argc].equals( "-tm")) + { + Trim_Mode = true; + } + else if ( args[argc].equals( "-mbtm")) + { + MBTrailer_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 + { + Output_File_Name = args[argc++]; + MsgQ_Name = args[argc++]; + + if( argc < args.length) + { + System.out.println( "Invalid number of command line options..."); + throw new Exception(); + } + } + + ++argc; + } + } + + catch( Exception Expt) + { + throw Expt; + } + } - //------------------------------------------------------------------------------------------------------------------------- - // - //------------------------------------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- - private void MQSInit() throws Exception - { - short retry = 0; - final short RETRY_MAX = 10; + private void MQSInit() throws Exception + { + short retry = 0; + final short RETRY_MAX = 10; - while( QMng == null) - { - try - { - QMng = new MQQueueManager( QMng_Name); -// System.out.println( "QManager Open: (" + QMng + ") !"); - } + while( QMng == null) + { + try + { + QMng = new MQQueueManager( QMng_Name); + // System.out.println( "QManager Open: (" + QMng + ") !"); + } - catch( Exception Expt) - { - System.out.print("!"); + catch( Exception Expt) + { + System.out.print("!"); - if( retry++ > RETRY_MAX) - { - throw Expt; - } - } - } + if( retry++ > RETRY_MAX) + { + throw Expt; + } + } + } - try - { - MsgQ = QMng.accessQueue( MsgQ_Name, MsgQ_Open_Options, null, null, null); -// System.out.println( "MsgQ Open: (" + MsgQ + ") !"); + try + { + MsgQ = QMng.accessQueue( MsgQ_Name, MsgQ_Open_Options, null, null, null); + // System.out.println( "MsgQ Open: (" + MsgQ + ") !"); - MQException.log = null; - } + MQException.log = null; + } - catch( Exception Expt) - { - QMng.disconnect(); -// System.out.println( "QManager Close: (" + QMng + ") !"); + catch( Exception Expt) + { + QMng.disconnect(); + // System.out.println( "QManager Close: (" + QMng + ") !"); - throw Expt; - } - } + throw Expt; + } + } - //------------------------------------------------------------------------------------------------------------------------- - // - //------------------------------------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- - private void MQSDeInit() throws Exception - { - try - { - MsgQ.close(); -// System.out.println( "MsgQ Close: (" + MsgQ + ") !"); - QMng.disconnect(); -// System.out.println( "QManager Close: (" + QMng + ") !"); - } + private void MQSDeInit() throws Exception + { + try + { + MsgQ.close(); + // System.out.println( "MsgQ Close: (" + MsgQ + ") !"); + QMng.disconnect(); + // System.out.println( "QManager Close: (" + QMng + ") !"); + } - catch( Exception Expt) - { - throw Expt; - } - } + catch( Exception Expt) + { + throw Expt; + } + } - //------------------------------------------------------------------------------------------------------------------------- - // - //------------------------------------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- - private MQMessage MQSGet_Msg( MQMessage Msg, boolean First) throws Exception - { - MQGetMessageOptions gmo = new MQGetMessageOptions(); + private MQMessage MQSGet_Msg( MQMessage Msg, boolean First) throws Exception + { + MQGetMessageOptions gmo = new MQGetMessageOptions(); - try - { - if( First) - { - gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_BROWSE_FIRST | MQC.MQGMO_CONVERT; - } - else - { - gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_BROWSE_NEXT | MQC.MQGMO_CONVERT; - } + try + { + if( First) + { + gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_BROWSE_FIRST | MQC.MQGMO_CONVERT; + } + else + { + gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_BROWSE_NEXT | MQC.MQGMO_CONVERT; + } - gmo.matchOptions = MQC.MQMO_NONE; + gmo.matchOptions = MQC.MQMO_NONE; - MsgQ.get( Msg, gmo); + MsgQ.get( Msg, gmo); - return( Msg); - } + return( Msg); + } - catch( MQException Expt) - { - if( ( Expt.completionCode != 2) || (Expt.reasonCode != 2033)) - { - //System.out.println("Exception: (" + Expt + ") !!!"); - throw Expt; - } + catch( MQException Expt) + { + if( ( Expt.completionCode != 2) || (Expt.reasonCode != 2033)) + { + // System.out.println("Exception: (" + Expt + ") !!!"); + throw Expt; + } + + // System.out.println("Exception: (" + Expt + ") !!!"); - return( null); - } - - catch( Exception Expt) - { - //System.out.println("Exception: (" + Expt + ") !!!"); - throw Expt; - } - } - - - - - - //------------------------------------------------------------------------------------------------------------------------- - // - //------------------------------------------------------------------------------------------------------------------------- - - private void MQSDelete_Msg( MQMessage Msg) throws Exception - { - MQGetMessageOptions gmo = new MQGetMessageOptions(); - - - try - { - gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_CONVERT; - gmo.matchOptions = MQC.MQMO_MATCH_MSG_ID; - - MsgQ.get( Msg, gmo); - } - - catch( Exception Expt) - { - throw Expt; - } - } - - - - - - //------------------------------------------------------------------------------------------------------------------------- - // - //------------------------------------------------------------------------------------------------------------------------- - - private void Counter_Print( int Msg_Nb, char Mark) - { - if( ( Msg_Nb % 50) == 0) - { - System.out.print( "\n(" + Msg_Nb + ")\t"); - } - - if( ( Msg_Nb % 10) == 0) - { - System.out.print( " "); - } - - System.out.print( Mark); - - switch( Mark) - { - case '.': - { - Moved_Nb++; - break; - } - - case '*': - { - Flushed_Nb++; - break; - } - - case '#': - { - Skiped_Nb++; - break; - } - - case '~': - { - Scaned_Nb++; - break; - } - } + return( null); } - - - - - - //------------------------------------------------------------------------------------------------------------------------- - // - //------------------------------------------------------------------------------------------------------------------------- - - private void Stand_By(int timer) + + catch( Exception Expt) { - if( timer > 0) - { - try - { - synchronized( this) - { - wait( timer); - } - } - catch(InterruptedException ie) - { - ie.printStackTrace(); - } - } + //System.out.println("Exception: (" + Expt + ") !!!"); + throw Expt; + } + } + + + + + + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- + + private void MQSDelete_Msg( MQMessage Msg) throws Exception + { + MQGetMessageOptions gmo = new MQGetMessageOptions(); + + + try + { + gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_CONVERT; + gmo.matchOptions = MQC.MQMO_MATCH_MSG_ID; + + MsgQ.get( Msg, gmo); + } + + catch( Exception Expt) + { + throw Expt; + } + } + + + + + + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- + + private void Counter_Print( String Mark) + { + if( ( Msg_Counter % 50) == 0) + { + System.out.print( "\n(" + Msg_Counter + ")\t"); } - - - - - //------------------------------------------------------------------------------------------------------------------------- - // - //------------------------------------------------------------------------------------------------------------------------- + if( ( Msg_Counter % 10) == 0) + { + System.out.print( " "); + } + + System.out.print( Mark); - 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; + Msg_Counter++; - - try - { - input_msg.format = MQC.MQFMT_STRING; - - if( TI_Swift_Batch_Mode) - { - mode = MODE_SCAN; - } - else - { - mode = MODE_FULLMOVE; - } + /* + switch( Mark) + { + case '.': + { + Moved_Nb++; + break; + } - do - { - input_msg = MQSGet_Msg( input_msg, get_first); + case '*': + { + Flushed_Nb++; + break; + } + + case '#': + { + Skiped_Nb++; + break; + } + + case '~': + { + Scaned_Nb++; + break; + } + } + */ + } + + + + + + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- - if( input_msg != null) - { - if( mode == MODE_FULLMOVE) - { - Counter_Print( Total_Nb++, '.'); + private void Stand_By(int timer) throws Exception + { + if( timer > 0) + { + try + { + synchronized( this) + { + wait( timer); + } + } + catch(InterruptedException Expt) + { + throw Expt; + } + } + } - Stand_By( Sleep_Time); + + + + + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- + + // 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()); - } + // if( Moved_Nb > 1) + // { + // Output_File.write( Message_Break.getBytes()); + // } - buffer_byte = new byte[ input_msg.getMessageLength()]; - input_msg.readFully( buffer_byte); + // 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(); - } + // 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); + // 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); + // 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++, '#'); + // 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); + // Stand_By( Sleep_Time); - MQSDelete_Msg( input_msg); + // MQSDelete_Msg( input_msg); - first_flush = false; - } - else - { -// System.out.print( "FB2 "); - mode = MODE_SCAN; + // 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++, '#'); + // 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); + // Stand_By( Sleep_Time); - MQSDelete_Msg( input_msg); - } - else if( msg_type.equals( TYPE_SWIFTOUT)) - { -// System.out.print( "FO "); - Counter_Print( Total_Nb++, '*'); + // MQSDelete_Msg( input_msg); + // } + // else if( msg_type.equals( TYPE_SWIFTOUT)) + // { + // // System.out.print( "FO "); + // Counter_Print( Total_Nb++, '*'); - Stand_By( Sleep_Time); + // Stand_By( Sleep_Time); - if( Flushed_Nb > 1) - { - Flush_File.write( Message_Break.getBytes()); - } + // 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); + // 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(); - } + // 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); + // 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(); - } + // MQSDelete_Msg( input_msg); + // } + // else + // { + // System.out.println( "Invalid msg_type: (" + msg_type + ") !"); + // throw new Exception(); + // } - break; - } + // break; + // } - case MODE_SCAN: - { - get_first = false; + // 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 "); + // 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; + // mode = MODE_FLUSH; + // get_first = true; + // first_scan = true; - } - } - else if( msg_type.equals( TYPE_SWIFTBEGIN)) - { -// System.out.print( "SB2 "); + // } + // } + // 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_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_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(); - } + // 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++, '~'); + // Counter_Print( Total_Nb++, '~'); - Stand_By( Sleep_Time); + // Stand_By( Sleep_Time); - break; - } + // break; + // } - case MODE_MOVE: - { - if( msg_type.equals( TYPE_SWIFTBEGIN)) - { -// System.out.print( "MB "); - Counter_Print( Total_Nb++, '#'); + // case MODE_MOVE: + // { + // if( msg_type.equals( TYPE_SWIFTBEGIN)) + // { + // // System.out.print( "MB "); + // Counter_Print( Total_Nb++, '#'); - Stand_By( Sleep_Time); + // Stand_By( Sleep_Time); - MQSDelete_Msg( input_msg); - } - else if( msg_type.equals( TYPE_SWIFTEND)) - { -// System.out.print( "ME "); - Counter_Print( Total_Nb++, '#'); + // MQSDelete_Msg( input_msg); + // } + // else if( msg_type.equals( TYPE_SWIFTEND)) + // { + // // System.out.print( "ME "); + // Counter_Print( Total_Nb++, '#'); - Stand_By( Sleep_Time); + // Stand_By( Sleep_Time); - MQSDelete_Msg( input_msg); + // 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++, '.'); + // 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); + // Stand_By( Sleep_Time); - if( Moved_Nb > 1) - { - Output_File.write( Message_Break.getBytes()); - } + // 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); + // 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(); - } + // 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); + // 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(); - } + // MQSDelete_Msg( input_msg); + // } + // else + // { + // System.out.println( "Invalid msg_type: (" + msg_type + ") !"); + // throw new Exception(); + // } - break; - } - } - } - } + // break; + // } + // } + // } + // } - } - while( input_msg != null); + // } + // while( input_msg != null); - if( MBTrailer_Mode) - { - Output_File.write( Message_Break.getBytes()); - } + // if( MBTrailer_Mode) + // { + // Output_File.write( Message_Break.getBytes()); + // } - System.out.println( "\n"); - } + // System.out.println( "\n"); + // } - catch( Exception Expt) - { -// System.out.println("Exception: (" + Expt + ") !!!"); - throw Expt; - } - } + // catch( Exception Expt) + // { + // // System.out.println("Exception: (" + Expt + ") !!!"); + // throw Expt; + // } + // } - //------------------------------------------------------------------------------------------------------------------------- - // - //------------------------------------------------------------------------------------------------------------------------- + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- + + 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 + { + return(false); + } + } + } + + + + + + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- - public MQSSave( String args[]) - { - long time_begin, time_end; - double time_elapsed, speed; - NumberFormat nf = NumberFormat.getInstance(); - BufferedOutputStream Output_File = null, Flush_File = null; + private void File_Save( BufferedOutputStream Output_File, int Msg_Skip, int Msg_Count, boolean Copy_Mode) throws Exception + { + MQMessage input_msg = new MQMessage(); + byte[] buffer; + int msg_id = 0; + boolean get_first = true; + + + try + { + 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)) + { + get_first = false; + + if( msg_id >= Msg_Skip) + { + if( Msg_Saved_Nb > 0) + { + Output_File.write( Message_Break.getBytes()); + } + + buffer = new byte[ input_msg.getMessageLength()]; + input_msg.readFully( buffer); + + if( Trim_Mode) + { + String buffer_string = new String( buffer).trim(); + buffer = buffer_string.getBytes(); + } + + Output_File.write( buffer, 0, buffer.length); + + if( Copy_Mode == false ) + { + MQSDelete_Msg( input_msg); + } + } + + msg_id++; + } + + if( MBTrailer_Mode) + { + Output_File.write( Message_Break.getBytes()); + } + } + + catch( Exception Expt) + { + throw Expt; + } + } + + + + + + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- + + 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 + ")"); + } + + + + + + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- + + 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 + ")"); + } + + + + + + //------------------------------------------------------------------------------------------------------------------------- + // + //------------------------------------------------------------------------------------------------------------------------- + + public MQSSave( String args[]) + { + int loop; + long time_begin, time_end; + double time_elapsed, speed; + NumberFormat nf = NumberFormat.getInstance(); + BufferedOutputStream output_file = null; - try - { - System.out.println("MQSSave: " + MQSSave_Tag + " / " + MQSSave_Date + " / " + MQSSave_Author); + try + { + System.out.println("MQSSave: " + MQSSave_Tag + " / " + MQSSave_Date + " / " + MQSSave_Author); - if( ( args.length < 2) || ( args.length > 7)) - { - System.out.println( "Usage: MQSSave [-qm \"Input_QueueMng_Name\"] [-st \"sleep_time\"] [-mb \"message_break\"] [-tisbm [-ffn ] | -cm ] [-tm] [-mbtm] "); - 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 + ")"); + if( ( args.length < 2) || ( args.length > 19)) + { - System.exit( 1); - } - else - { - System.out.println( "MQS Save Starting..."); + Usage_Print(); + System.exit( 1); + } + else + { + System.out.println( "MQS Save Starting..."); - Arg_Parse( args); - - 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 + ")"); + Args_Parse( args); + Args_Print(); - MQSInit(); + MQSInit(); - try - { - Output_File = new BufferedOutputStream( new FileOutputStream( Output_File_Name)); + try + { + output_file = new BufferedOutputStream( new FileOutputStream( Output_File_Name)); - if( TI_Swift_Batch_Mode) - { - System.out.println( "Legend: .: Saved *: Flushed #: Skiped ~: Scaned"); - Flush_File = new BufferedOutputStream( new FileOutputStream( Flush_File_Name)); - } + System.out.println( "Legend: .: Saved #: Skiped"); - try - { -// System.out.println("Output File Open: (" + Output_file + ") !"); + try + { + // System.out.println( "Output File Open: (" + output_file + ") !"); - time_begin = System.currentTimeMillis(); - Save_File( Output_File, Flush_File); - time_end = System.currentTimeMillis(); + time_begin = System.currentTimeMillis(); - time_elapsed = ( time_end - time_begin) / 1000.0; - speed = Total_Nb / time_elapsed; + 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_elapsed = ( time_end - time_begin) / 1000.0; + speed = Msg_Saved_Nb / time_elapsed; - nf.setMinimumFractionDigits(2); - nf.setMaximumFractionDigits(2); + nf.setMinimumFractionDigits(2); + nf.setMaximumFractionDigits(2); - if( TI_Swift_Batch_Mode) - { - 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( "Total Message Nb: (" + Total_Nb - + ") Elapsed Time: (" + nf.format(time_elapsed) - + ") s Speed: (" + nf.format(speed) - + ") msg/s"); - } - else - { - System.out.println( "Saved Message Nb: (" + Total_Nb - + ") Elapsed Time: (" + nf.format(time_elapsed) - + ") s Speed: (" + nf.format(speed) - + ") msg/s"); - } - } + System.out.println( ""); + System.out.println( ""); + System.out.println( "Saved Message Nb: (" + Msg_Saved_Nb + + ") Skiped Messages Nb: (" + Msg_Skiped_Nb + + ") Elapsed Time: (" + nf.format(time_elapsed) + + ") s Speed: (" + nf.format(speed) + + ") msg/s"); + } - catch( Exception Expt) - { - Output_File.close(); + catch( Exception Expt) + { + output_file.close(); + throw Expt; + } - if( TI_Swift_Batch_Mode) - { - Flush_File.close(); - } - - throw Expt; - } - - Output_File.close(); - - if( TI_Swift_Batch_Mode) - { - Flush_File.close(); - } - } + output_file.close(); + } - catch( Exception Expt) - { - MQSDeInit(); - throw Expt; - } + catch( Exception Expt) + { + MQSDeInit(); + throw Expt; + } - MQSDeInit(); - System.out.println( "MQS Save Completed !"); + MQSDeInit(); + System.out.println( "MQS Save Completed !"); - System.exit( 0); - } - } + System.exit( 0); + } + } - catch( Exception Expt) - { - System.out.println("Exception: (" + Expt + ") !"); - Expt.printStackTrace(); + catch( Exception Expt) + { + System.out.println("Exception: (" + Expt + ") !"); + Expt.printStackTrace(); - System.exit( 1); - } - } + System.exit( 1); + } + } + + //------------------------------------------------------------------------------------------------------------------------- } diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index 9a8fa31..e964e81 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -1,13 +1,27 @@ # $RCSfile: ReleaseNotes.txt,v $ -# $Revision: 1.12 $ +# $Revision: 1.13 $ # $Name: $ -# $Date: 2008/11/10 01:52:00 $ +# $Date: 2008/12/11 13:52:05 $ # $Author: agibert $ +-------------------------------------------------------------------------------- +MQSSave V 2.0.0 - A. Gibert - 2008/12/11 +-------------------------------------------------------------------------------- + +- 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". + + + -------------------------------------------------------------------------------- MQSSave V 1.3.2 - A. Gibert - 2008/11/10 --------------------------------------------------------------------------------