2002-03-18 10:24:46 +01:00
|
|
|
// $RCSfile: MQSSave.java,v $
|
2003-09-04 17:42:41 +02:00
|
|
|
// $Revision: 1.11 $
|
2002-03-18 10:24:46 +01:00
|
|
|
// $Name: $
|
2003-09-04 17:42:41 +02:00
|
|
|
// $Date: 2003/09/04 15:42:41 $
|
2002-03-18 10:24:46 +01:00
|
|
|
// $Author: giberta1 $
|
|
|
|
|
|
|
|
/*
|
2003-09-04 17:42:41 +02:00
|
|
|
* MQSSave.java - MQ/Series queue to data file saver
|
2002-03-18 10:24:46 +01:00
|
|
|
* Copyright (C) 2002 Arnaud G. Gibert
|
|
|
|
* arnaud.gibert@misys.com
|
|
|
|
* www.misys.com
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import com.ibm.mq.*;
|
|
|
|
import java.io.*;
|
2002-04-23 16:41:38 +02:00
|
|
|
import java.text.*;
|
2002-03-18 10:24:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class MQSSave
|
|
|
|
{
|
2002-05-21 17:36:28 +02:00
|
|
|
private MQQueueManager QMng = null;
|
2002-04-23 16:41:38 +02:00
|
|
|
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;
|
2002-05-03 19:12:58 +02:00
|
|
|
private String Output_File_Name, Flush_File_Name = "flush.txt";
|
2002-04-23 16:41:38 +02:00
|
|
|
private String Message_Break = "\r\n";
|
2002-05-03 19:12:58 +02:00
|
|
|
private boolean TI_Swift_Batch_Mode = false;
|
2003-09-04 17:42:41 +02:00
|
|
|
private boolean Copy_Mode = false;
|
2002-05-21 17:36:28 +02:00
|
|
|
private boolean Trim_Mode = false;
|
2002-11-14 14:40:24 +01:00
|
|
|
private boolean MBTrailer_Mode = false;
|
2002-05-03 19:12:58 +02:00
|
|
|
private int Total_Nb = 0, Moved_Nb = 0, Skiped_Nb = 0, Scaned_Nb = 0, Flushed_Nb = 0;
|
2003-09-04 17:42:41 +02:00
|
|
|
private String MQSSave_Revision = "$Revision: 1.11 $";
|
2002-05-21 17:44:45 +02:00
|
|
|
private String MQSSave_Tag = "$Name: $";
|
2003-09-04 17:42:41 +02:00
|
|
|
private String MQSSave_Date = "$Date: 2003/09/04 15:42:41 $";
|
2002-05-21 17:44:45 +02:00
|
|
|
private String MQSSave_Author = "$Author: giberta1 $";
|
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
public static void main( String args[])
|
|
|
|
{
|
|
|
|
new MQSSave( args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
{
|
|
|
|
fmt += "\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
{
|
|
|
|
fmt += "\r";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 't':
|
|
|
|
{
|
|
|
|
fmt += "\t";
|
|
|
|
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( "-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();
|
|
|
|
}
|
|
|
|
}
|
2002-05-03 19:12:58 +02:00
|
|
|
else if ( args[argc].equals( "-ffn"))
|
|
|
|
{
|
|
|
|
if( argc < ( args.length + 1))
|
|
|
|
{
|
2002-05-21 17:36:28 +02:00
|
|
|
Flush_File_Name = args[++argc];
|
2002-05-03 19:12:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
System.out.println( "Invalid number of command line options...");
|
|
|
|
throw new Exception();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( args[argc].equals( "-tisbm"))
|
|
|
|
{
|
2003-09-04 17:42:41 +02:00
|
|
|
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();
|
|
|
|
}
|
2002-05-03 19:12:58 +02:00
|
|
|
}
|
2002-05-21 17:36:28 +02:00
|
|
|
else if ( args[argc].equals( "-tm"))
|
|
|
|
{
|
|
|
|
Trim_Mode = true;
|
|
|
|
}
|
2002-11-14 14:40:24 +01:00
|
|
|
else if ( args[argc].equals( "-mbtm"))
|
|
|
|
{
|
|
|
|
MBTrailer_Mode = true;
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
else
|
|
|
|
{
|
2002-05-03 19:12:58 +02:00
|
|
|
Output_File_Name = args[argc++];
|
2002-04-23 16:41:38 +02:00
|
|
|
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
|
|
|
|
{
|
2002-05-21 17:36:28 +02:00
|
|
|
short retry = 0;
|
|
|
|
final short RETRY_MAX = 10;
|
|
|
|
|
|
|
|
|
|
|
|
while( QMng == null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
QMng = new MQQueueManager( QMng_Name);
|
|
|
|
// System.out.println( "QManager Open: (" + QMng + ") !");
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2002-05-21 17:36:28 +02:00
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
System.out.print("!");
|
|
|
|
|
|
|
|
if( retry++ > RETRY_MAX)
|
|
|
|
{
|
|
|
|
throw Expt;
|
|
|
|
}
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
}
|
2002-05-21 17:36:28 +02:00
|
|
|
|
2002-04-23 16:41:38 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
MsgQ = QMng.accessQueue( MsgQ_Name, MsgQ_Open_Options, null, null, null);
|
|
|
|
// System.out.println( "MsgQ Open: (" + MsgQ + ") !");
|
2002-05-03 19:12:58 +02:00
|
|
|
|
|
|
|
MQException.log = null;
|
2002-04-23 16:41:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
QMng.disconnect();
|
|
|
|
// System.out.println( "QManager Close: (" + QMng + ") !");
|
|
|
|
|
|
|
|
throw Expt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
private MQMessage MQSGet_Msg( MQMessage Msg, boolean First) throws Exception
|
2002-04-23 16:41:38 +02:00
|
|
|
{
|
|
|
|
MQGetMessageOptions gmo = new MQGetMessageOptions();
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2002-05-03 19:12:58 +02:00
|
|
|
if( First)
|
2002-04-23 16:41:38 +02:00
|
|
|
{
|
|
|
|
gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_BROWSE_FIRST | MQC.MQGMO_CONVERT;
|
2002-05-03 19:12:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_BROWSE_NEXT | MQC.MQGMO_CONVERT;
|
|
|
|
}
|
|
|
|
|
|
|
|
gmo.matchOptions = MQC.MQMO_NONE;
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
MsgQ.get( Msg, gmo);
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
return( Msg);
|
|
|
|
}
|
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
catch( MQException Expt)
|
|
|
|
{
|
|
|
|
if( ( Expt.completionCode != 2) || (Expt.reasonCode != 2033))
|
|
|
|
{
|
|
|
|
//System.out.println("Exception: (" + Expt + ") !!!");
|
|
|
|
throw Expt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return( null);
|
|
|
|
}
|
|
|
|
|
2002-04-23 16:41:38 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
private void Counter_Print( int Msg_Nb, char Mark)
|
2002-04-23 16:41:38 +02:00
|
|
|
{
|
|
|
|
if( ( Msg_Nb % 50) == 0)
|
|
|
|
{
|
|
|
|
System.out.print( "\n(" + Msg_Nb + ")\t");
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( Msg_Nb % 10) == 0)
|
|
|
|
{
|
|
|
|
System.out.print( " ");
|
|
|
|
}
|
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
System.out.print( Mark);
|
|
|
|
|
|
|
|
switch( Mark)
|
|
|
|
{
|
|
|
|
case '.':
|
|
|
|
{
|
|
|
|
Moved_Nb++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case '*':
|
|
|
|
{
|
|
|
|
Flushed_Nb++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case '#':
|
|
|
|
{
|
|
|
|
Skiped_Nb++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case '~':
|
|
|
|
{
|
|
|
|
Scaned_Nb++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
private void Save_File( BufferedOutputStream Output_File, BufferedOutputStream Flush_File) throws Exception
|
2002-04-23 16:41:38 +02:00
|
|
|
{
|
2002-05-03 19:12:58 +02:00
|
|
|
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 ";
|
2002-05-13 18:28:02 +02:00
|
|
|
final String TYPE_SWIFTERROR = "SWIFTERROR";
|
2002-05-03 19:12:58 +02:00
|
|
|
final String TYPE_SWIFTOUT = "SWIFTOUT ";
|
|
|
|
boolean get_first = false;
|
|
|
|
boolean first_flush = true;
|
|
|
|
boolean first_scan = true;
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
input_msg.format = MQC.MQFMT_STRING;
|
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
if( TI_Swift_Batch_Mode)
|
|
|
|
{
|
|
|
|
mode = MODE_SCAN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mode = MODE_FULLMOVE;
|
|
|
|
}
|
|
|
|
|
2002-04-23 16:41:38 +02:00
|
|
|
do
|
|
|
|
{
|
2002-05-03 19:12:58 +02:00
|
|
|
input_msg = MQSGet_Msg( input_msg, get_first);
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
if( input_msg != null)
|
|
|
|
{
|
2002-05-03 19:12:58 +02:00
|
|
|
if( mode == MODE_FULLMOVE)
|
|
|
|
{
|
|
|
|
Counter_Print( Total_Nb++, '.');
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
if( Moved_Nb > 1)
|
|
|
|
{
|
|
|
|
Output_File.write( Message_Break.getBytes());
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
buffer_byte = new byte[ input_msg.getMessageLength()];
|
|
|
|
input_msg.readFully( buffer_byte);
|
|
|
|
|
2002-07-29 11:56:18 +02:00
|
|
|
if( Trim_Mode)
|
|
|
|
{
|
|
|
|
String buffer_string = new String( buffer_byte).trim();
|
|
|
|
buffer_byte = buffer_string.getBytes();
|
|
|
|
}
|
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
Output_File.write( buffer_byte, 0, buffer_byte.length);
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2003-09-04 17:42:41 +02:00
|
|
|
if( Copy_Mode == false )
|
|
|
|
{
|
|
|
|
MQSDelete_Msg( input_msg);
|
|
|
|
}
|
2002-05-03 19:12:58 +02:00
|
|
|
}
|
|
|
|
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++, '#');
|
|
|
|
|
|
|
|
MQSDelete_Msg( input_msg);
|
2003-09-04 17:42:41 +02:00
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
first_flush = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// System.out.print( "FB2 ");
|
|
|
|
mode = MODE_SCAN;
|
|
|
|
|
|
|
|
first_flush = true;
|
|
|
|
}
|
|
|
|
}
|
2002-05-13 18:28:02 +02:00
|
|
|
else if( msg_type.equals( TYPE_SWIFTEND) || msg_type.equals( TYPE_SWIFTERROR))
|
2002-05-03 19:12:58 +02:00
|
|
|
{
|
|
|
|
// System.out.print( "FEA ");
|
|
|
|
Counter_Print( Total_Nb++, '#');
|
|
|
|
|
|
|
|
MQSDelete_Msg( input_msg);
|
|
|
|
}
|
|
|
|
else if( msg_type.equals( TYPE_SWIFTOUT))
|
|
|
|
{
|
|
|
|
// System.out.print( "FO ");
|
|
|
|
Counter_Print( Total_Nb++, '*');
|
|
|
|
|
|
|
|
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);
|
2002-05-21 17:36:28 +02:00
|
|
|
|
|
|
|
if( Trim_Mode)
|
|
|
|
{
|
|
|
|
String buffer_string = new String( buffer_byte).trim();
|
|
|
|
buffer_byte = buffer_string.getBytes();
|
|
|
|
}
|
2002-05-03 19:12:58 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2002-05-13 18:28:02 +02:00
|
|
|
else if( msg_type.equals( TYPE_SWIFTERROR))
|
2002-05-03 19:12:58 +02:00
|
|
|
{
|
|
|
|
// 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++, '~');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case MODE_MOVE:
|
|
|
|
{
|
|
|
|
if( msg_type.equals( TYPE_SWIFTBEGIN))
|
|
|
|
{
|
|
|
|
// System.out.print( "MB ");
|
|
|
|
Counter_Print( Total_Nb++, '#');
|
|
|
|
|
|
|
|
MQSDelete_Msg( input_msg);
|
|
|
|
}
|
|
|
|
else if( msg_type.equals( TYPE_SWIFTEND))
|
|
|
|
{
|
|
|
|
// System.out.print( "ME ");
|
|
|
|
Counter_Print( Total_Nb++, '#');
|
|
|
|
|
|
|
|
MQSDelete_Msg( input_msg);
|
|
|
|
|
|
|
|
mode = MODE_SCAN;
|
|
|
|
get_first = true;
|
|
|
|
}
|
2002-05-13 18:28:02 +02:00
|
|
|
else if( msg_type.equals( TYPE_SWIFTERROR))
|
2002-05-03 19:12:58 +02:00
|
|
|
{
|
|
|
|
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++, '.');
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2002-05-21 17:36:28 +02:00
|
|
|
if( Trim_Mode)
|
|
|
|
{
|
|
|
|
String buffer_string = new String( buffer_byte).trim();
|
|
|
|
buffer_byte = buffer_string.getBytes();
|
|
|
|
}
|
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
Output_File.write( buffer_byte, 0, buffer_byte.length);
|
|
|
|
|
2003-09-04 17:42:41 +02:00
|
|
|
MQSDelete_Msg( input_msg);
|
2002-05-03 19:12:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
System.out.println( "Invalid msg_type: (" + msg_type + ") !");
|
|
|
|
throw new Exception();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
while( input_msg != null);
|
|
|
|
|
2002-11-14 14:40:24 +01:00
|
|
|
if( MBTrailer_Mode)
|
|
|
|
{
|
|
|
|
Output_File.write( Message_Break.getBytes());
|
|
|
|
}
|
|
|
|
|
2002-04-23 16:41:38 +02:00
|
|
|
System.out.println( "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
// System.out.println("Exception: (" + Expt + ") !!!");
|
|
|
|
throw Expt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
public MQSSave( String args[])
|
|
|
|
{
|
2002-05-03 19:12:58 +02:00
|
|
|
long time_begin, time_end;
|
|
|
|
double time_elapsed, speed;
|
|
|
|
NumberFormat nf = NumberFormat.getInstance();
|
|
|
|
BufferedOutputStream Output_File = null, Flush_File = null;
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2002-05-21 17:44:45 +02:00
|
|
|
|
2002-04-23 16:41:38 +02:00
|
|
|
try
|
|
|
|
{
|
2002-05-21 17:44:45 +02:00
|
|
|
System.out.println("MQSSave: " + MQSSave_Tag + " / " + MQSSave_Date + " / " + MQSSave_Author);
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
if( ( args.length < 2) || ( args.length > 7))
|
2002-04-23 16:41:38 +02:00
|
|
|
{
|
2003-09-04 17:42:41 +02:00
|
|
|
System.out.println( "Usage: MQSSave [-mb \"message_break\"] [-tisbm [-ffn <Flush_File_Name>] | -cm ] [-tm] [-mbtm] <Output_File_Name> <Input_MsgQueue_Name>");
|
|
|
|
System.out.println( " Default: 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 + ")");
|
2002-05-06 11:51:49 +02:00
|
|
|
|
|
|
|
System.exit( 1);
|
2002-04-23 16:41:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
System.out.println( "MQS Save Starting...");
|
|
|
|
|
|
|
|
Arg_Parse( args);
|
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
System.out.println( "Output File Name: (" + Output_File_Name + ") Input MsgQue Name: (" + MsgQ_Name + ") Flush File Name: (" + Flush_File_Name + ")");
|
2003-09-04 17:42:41 +02:00
|
|
|
System.out.println( "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 + ")");
|
2002-05-21 17:36:28 +02:00
|
|
|
|
2002-04-23 16:41:38 +02:00
|
|
|
MQSInit();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2002-05-03 19:12:58 +02:00
|
|
|
Output_File = new BufferedOutputStream( new FileOutputStream( Output_File_Name));
|
|
|
|
|
|
|
|
if( TI_Swift_Batch_Mode)
|
|
|
|
{
|
2002-05-13 18:28:02 +02:00
|
|
|
System.out.println( "Legend: .: Saved *: Flushed #: Skiped ~: Scaned");
|
2002-05-03 19:12:58 +02:00
|
|
|
Flush_File = new BufferedOutputStream( new FileOutputStream( Flush_File_Name));
|
|
|
|
}
|
|
|
|
|
2002-04-23 16:41:38 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// System.out.println("Output File Open: (" + Output_file + ") !");
|
|
|
|
|
|
|
|
time_begin = System.currentTimeMillis();
|
2002-05-03 19:12:58 +02:00
|
|
|
Save_File( Output_File, Flush_File);
|
2002-04-23 16:41:38 +02:00
|
|
|
time_end = System.currentTimeMillis();
|
2002-05-03 19:12:58 +02:00
|
|
|
|
2002-04-23 16:41:38 +02:00
|
|
|
time_elapsed = ( time_end - time_begin) / 100.0;
|
2002-05-03 19:12:58 +02:00
|
|
|
speed = Total_Nb / time_elapsed;
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
nf.setMinimumFractionDigits(2);
|
|
|
|
nf.setMaximumFractionDigits(2);
|
2002-05-03 19:12:58 +02:00
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
2002-05-03 19:12:58 +02:00
|
|
|
Output_File.close();
|
|
|
|
|
|
|
|
if( TI_Swift_Batch_Mode)
|
|
|
|
{
|
|
|
|
Flush_File.close();
|
|
|
|
}
|
|
|
|
|
2002-04-23 16:41:38 +02:00
|
|
|
throw Expt;
|
|
|
|
}
|
|
|
|
|
2002-05-03 19:12:58 +02:00
|
|
|
Output_File.close();
|
|
|
|
|
|
|
|
if( TI_Swift_Batch_Mode)
|
|
|
|
{
|
|
|
|
Flush_File.close();
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
MQSDeInit();
|
|
|
|
throw Expt;
|
|
|
|
}
|
|
|
|
|
|
|
|
MQSDeInit();
|
|
|
|
System.out.println( "MQS Save Completed !");
|
2002-05-06 11:51:49 +02:00
|
|
|
|
|
|
|
System.exit( 0);
|
2002-04-23 16:41:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
System.out.println("Exception: (" + Expt + ") !");
|
|
|
|
Expt.printStackTrace();
|
2002-05-06 11:51:49 +02:00
|
|
|
|
|
|
|
System.exit( 1);
|
2002-04-23 16:41:38 +02:00
|
|
|
}
|
|
|
|
}
|
2002-03-18 10:24:46 +01:00
|
|
|
|
|
|
|
}
|