2002-03-18 10:24:46 +01:00
|
|
|
// $RCSfile: MQSSave.java,v $
|
2008-12-18 18:25:42 +01:00
|
|
|
// $Revision: 1.19 $
|
2002-03-18 10:24:46 +01:00
|
|
|
// $Name: $
|
2008-12-18 18:25:42 +01:00
|
|
|
// $Date: 2008/12/18 17:25:42 $
|
2007-06-05 11:27:44 +02:00
|
|
|
// $Author: agibert $
|
2002-03-18 10:24:46 +01:00
|
|
|
|
|
|
|
/*
|
2003-09-04 17:42:41 +02:00
|
|
|
* MQSSave.java - MQ/Series queue to data file saver
|
2008-12-12 11:44:19 +01:00
|
|
|
* Copyright (C) 2001-2008 Arnaud G. Gibert
|
2007-06-05 11:27:44 +02:00
|
|
|
* mailto:arnaud@rx3.net
|
|
|
|
* http://www.rx3.org/dvp/MQSLoad
|
2002-03-18 10:24:46 +01:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
{
|
2008-12-18 18:25:42 +01:00
|
|
|
private String MQSSave_Revision = "$Revision: 1.19 $";
|
2008-12-11 14:52:05 +01:00
|
|
|
private String MQSSave_Tag = "$Name: $";
|
2008-12-18 18:25:42 +01:00
|
|
|
private String MQSSave_Date = "$Date: 2008/12/18 17:25:42 $";
|
2008-12-11 14:52:05 +01:00
|
|
|
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;
|
2008-12-12 01:08:11 +01:00
|
|
|
private boolean Character_Convert = false;
|
2008-12-11 14:52:05 +01:00
|
|
|
private int Character_Set = 1208;
|
2008-12-12 11:44:19 +01:00
|
|
|
private int Sleep_Time = 0;
|
2008-12-11 14:52:05 +01:00
|
|
|
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;
|
2008-12-12 01:08:11 +01:00
|
|
|
private boolean Best_Effort_Mode = false;
|
2008-12-11 14:52:05 +01:00
|
|
|
private String Output_File_Name;
|
|
|
|
private int Msg_Counter = 0;
|
|
|
|
private int Msg_Saved_Nb = 0;
|
|
|
|
private int Msg_Skiped_Nb = 0;
|
2008-12-12 01:08:11 +01:00
|
|
|
private int Msg_Error_Nb = 0;
|
|
|
|
private boolean CC_Error = false;
|
2008-12-11 14:52:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
public static void main( String args[])
|
|
|
|
{
|
|
|
|
new MQSSave( args);
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
public static String Str_Format( String UnFmt)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
boolean esc = false;
|
|
|
|
String fmt = "";
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
for( idx = 0; idx < UnFmt.length(); idx++)
|
|
|
|
{
|
|
|
|
if( esc)
|
|
|
|
{
|
|
|
|
switch( UnFmt.charAt( idx))
|
|
|
|
{
|
|
|
|
case '\\':
|
|
|
|
{
|
|
|
|
fmt += "\\";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
{
|
|
|
|
fmt += "\n";
|
|
|
|
break;
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
case 'r':
|
|
|
|
{
|
|
|
|
fmt += "\r";
|
|
|
|
break;
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
case 't':
|
|
|
|
{
|
|
|
|
fmt += "\t";
|
|
|
|
break;
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
fmt += "?";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
esc = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( UnFmt.charAt( idx) == '\\')
|
|
|
|
{
|
|
|
|
esc = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fmt += UnFmt.charAt( idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
return( fmt);
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
public static String Str_UnFormat( String Fmt)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
String unfmt = "";
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
for( idx = 0; idx < Fmt.length(); idx++)
|
|
|
|
{
|
|
|
|
switch( Fmt.charAt( idx))
|
|
|
|
{
|
|
|
|
case '\\':
|
|
|
|
{
|
|
|
|
unfmt += "\\\\";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case '\n':
|
|
|
|
{
|
|
|
|
unfmt += "\\n";
|
|
|
|
break;
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
case '\r':
|
|
|
|
{
|
|
|
|
unfmt += "\\r";
|
|
|
|
break;
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
case '\t':
|
|
|
|
{
|
|
|
|
unfmt += "\\t";
|
|
|
|
break;
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
unfmt += Fmt.charAt( idx);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
return( unfmt);
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
private void Args_Parse( String args[]) throws Exception
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2008-12-12 01:08:11 +01:00
|
|
|
else if ( args[argc].equals( "-cc"))
|
|
|
|
{
|
|
|
|
Character_Convert = true;
|
|
|
|
}
|
2008-12-11 14:52:05 +01:00
|
|
|
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;
|
|
|
|
}
|
2008-12-12 01:08:11 +01:00
|
|
|
else if ( args[argc].equals( "-bem"))
|
|
|
|
{
|
|
|
|
Best_Effort_Mode = true;
|
|
|
|
}
|
2008-12-11 14:52:05 +01:00
|
|
|
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++];
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
if( argc < args.length)
|
|
|
|
{
|
|
|
|
System.out.println( "Invalid number of command line options...");
|
|
|
|
throw new Exception();
|
|
|
|
}
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
++argc;
|
|
|
|
}
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
throw Expt;
|
2002-04-23 16:41:38 +02:00
|
|
|
}
|
2008-12-11 14:52:05 +01:00
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
private void MQSInit() throws Exception
|
|
|
|
{
|
|
|
|
short retry = 0;
|
|
|
|
final short RETRY_MAX = 10;
|
2002-05-21 17:36:28 +02:00
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
while( QMng == null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
QMng = new MQQueueManager( QMng_Name);
|
|
|
|
// System.out.println( "QManager Open: (" + QMng + ") !");
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
System.out.print("!");
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
if( retry++ > RETRY_MAX)
|
|
|
|
{
|
|
|
|
throw Expt;
|
2002-04-23 16:41:38 +02:00
|
|
|
}
|
2008-12-11 14:52:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
MsgQ = QMng.accessQueue( MsgQ_Name, MsgQ_Open_Options, null, null, null);
|
|
|
|
// System.out.println( "MsgQ Open: (" + MsgQ + ") !");
|
|
|
|
|
|
|
|
MQException.log = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
QMng.disconnect();
|
|
|
|
// System.out.println( "QManager Close: (" + QMng + ") !");
|
|
|
|
|
|
|
|
throw Expt;
|
|
|
|
}
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
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-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
private MQMessage MQSGet_Msg( MQMessage Msg, boolean First) throws Exception
|
|
|
|
{
|
|
|
|
MQGetMessageOptions gmo = new MQGetMessageOptions();
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if( First)
|
|
|
|
{
|
2008-12-12 01:08:11 +01:00
|
|
|
gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_BROWSE_FIRST;
|
2008-12-11 14:52:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-12 01:08:11 +01:00
|
|
|
gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_BROWSE_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Character_Convert)
|
|
|
|
{
|
|
|
|
gmo.options = gmo.options | MQC.MQGMO_CONVERT;
|
2008-12-11 14:52:05 +01:00
|
|
|
}
|
2008-12-12 01:08:11 +01:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
gmo.matchOptions = MQC.MQMO_NONE;
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
MsgQ.get( Msg, gmo);
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
return( Msg);
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
catch( MQException Expt)
|
|
|
|
{
|
2008-12-12 11:44:19 +01:00
|
|
|
if( ( Expt.completionCode == 2) && ( Expt.reasonCode == 2033))
|
2008-12-11 14:52:05 +01:00
|
|
|
{
|
2008-12-12 01:08:11 +01:00
|
|
|
/* no more messages */
|
|
|
|
return( null);
|
|
|
|
}
|
|
|
|
|
2008-12-12 11:44:19 +01:00
|
|
|
if( Best_Effort_Mode && ( Expt.completionCode == 1) && ( ( Expt.reasonCode == 2110) || ( Expt.reasonCode == 2150)))
|
2008-12-12 01:08:11 +01:00
|
|
|
{
|
|
|
|
/* caracter convertion error */
|
|
|
|
CC_Error = true;
|
|
|
|
|
|
|
|
return( null);
|
2008-12-11 14:52:05 +01:00
|
|
|
}
|
|
|
|
|
2008-12-12 01:08:11 +01:00
|
|
|
throw Expt;
|
2008-12-11 14:52:05 +01:00
|
|
|
}
|
2002-05-03 19:12:58 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
//System.out.println("Exception: (" + Expt + ") !!!");
|
|
|
|
throw Expt;
|
|
|
|
}
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
private void MQSDelete_Msg( MQMessage Msg) throws Exception
|
|
|
|
{
|
|
|
|
MQGetMessageOptions gmo = new MQGetMessageOptions();
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
gmo.options = MQC.MQGMO_NO_WAIT | MQC.MQGMO_CONVERT;
|
|
|
|
gmo.matchOptions = MQC.MQMO_MATCH_MSG_ID;
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
MsgQ.get( Msg, gmo);
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
throw Expt;
|
|
|
|
}
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
private void Counter_Print( String Mark)
|
|
|
|
{
|
|
|
|
if( ( Msg_Counter % 50) == 0)
|
2002-04-23 16:41:38 +02:00
|
|
|
{
|
2008-12-11 14:52:05 +01:00
|
|
|
System.out.print( "\n(" + Msg_Counter + ")\t");
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
if( ( Msg_Counter % 10) == 0)
|
|
|
|
{
|
|
|
|
System.out.print( " ");
|
|
|
|
}
|
2002-05-03 19:12:58 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
System.out.print( Mark);
|
|
|
|
|
|
|
|
Msg_Counter++;
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
2007-12-11 17:50:50 +01:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
private void Stand_By(int timer) throws Exception
|
|
|
|
{
|
|
|
|
if( timer > 0)
|
2007-12-11 17:50:50 +01:00
|
|
|
{
|
2008-12-11 14:52:05 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
synchronized( this)
|
|
|
|
{
|
|
|
|
wait( timer);
|
2007-12-11 17:50:50 +01:00
|
|
|
}
|
2008-12-11 14:52:05 +01:00
|
|
|
}
|
|
|
|
catch(InterruptedException Expt)
|
|
|
|
{
|
|
|
|
throw Expt;
|
|
|
|
}
|
2007-12-11 17:50:50 +01:00
|
|
|
}
|
2008-12-11 14:52:05 +01:00
|
|
|
}
|
2007-12-11 17:50:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-12 01:08:11 +01:00
|
|
|
if( CC_Error)
|
|
|
|
{
|
|
|
|
CC_Error = false;
|
|
|
|
|
|
|
|
Counter_Print( "*");
|
|
|
|
Msg_Error_Nb++;
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return(false);
|
|
|
|
}
|
2008-12-11 14:52:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-05-21 17:44:45 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2008-12-12 01:08:11 +01:00
|
|
|
// input_msg.format = MQC.MQFMT_STRING;
|
2008-12-11 14:52:05 +01:00
|
|
|
|
|
|
|
/* 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)
|
2002-04-23 16:41:38 +02:00
|
|
|
{
|
2008-12-12 01:08:11 +01:00
|
|
|
/* This message is not skiped */
|
|
|
|
|
|
|
|
if( Msg_Saved_Nb > 1)
|
2008-12-11 14:52:05 +01:00
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
2008-12-12 11:44:19 +01:00
|
|
|
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>");
|
2008-12-18 18:25:42 +01:00
|
|
|
System.out.println( "");
|
2008-12-12 01:08:11 +01:00
|
|
|
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 + ")");
|
2008-12-11 14:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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 + ")");
|
2008-12-12 01:08:11 +01:00
|
|
|
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 + ")");
|
2008-12-11 14:52:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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);
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
if( ( args.length < 2) || ( args.length > 19))
|
|
|
|
{
|
2002-05-06 11:51:49 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
Usage_Print();
|
|
|
|
System.exit( 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
System.out.println( "MQS Save Starting...");
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
Args_Parse( args);
|
|
|
|
Args_Print();
|
|
|
|
|
|
|
|
MQSInit();
|
2002-05-21 17:36:28 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
output_file = new BufferedOutputStream( new FileOutputStream( Output_File_Name));
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-12 01:08:11 +01:00
|
|
|
System.out.println( "Legend: .: Saved #: Skiped *: Error");
|
2002-05-03 19:12:58 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// System.out.println( "Output File Open: (" + output_file + ") !");
|
2002-05-03 19:12:58 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
time_begin = System.currentTimeMillis();
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2002-05-03 19:12:58 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
time_end = System.currentTimeMillis();
|
|
|
|
|
|
|
|
time_elapsed = ( time_end - time_begin) / 1000.0;
|
|
|
|
speed = Msg_Saved_Nb / time_elapsed;
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
nf.setMinimumFractionDigits(2);
|
|
|
|
nf.setMaximumFractionDigits(2);
|
|
|
|
|
|
|
|
System.out.println( "");
|
|
|
|
System.out.println( "");
|
|
|
|
System.out.println( "Saved Message Nb: (" + Msg_Saved_Nb
|
|
|
|
+ ") Skiped Messages Nb: (" + Msg_Skiped_Nb
|
2008-12-12 01:08:11 +01:00
|
|
|
+ ") Error Messages Nb: (" + Msg_Error_Nb
|
2008-12-11 14:52:05 +01:00
|
|
|
+ ") Elapsed Time: (" + nf.format(time_elapsed)
|
|
|
|
+ ") s Speed: (" + nf.format(speed)
|
|
|
|
+ ") msg/s");
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
output_file.close();
|
|
|
|
throw Expt;
|
|
|
|
}
|
|
|
|
|
|
|
|
output_file.close();
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
MQSDeInit();
|
|
|
|
throw Expt;
|
|
|
|
}
|
2002-04-23 16:41:38 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
MQSDeInit();
|
|
|
|
System.out.println( "MQS Save Completed !");
|
2002-05-06 11:51:49 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
System.exit( 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
System.out.println("Exception: (" + Expt + ") !");
|
|
|
|
Expt.printStackTrace();
|
2002-05-06 11:51:49 +02:00
|
|
|
|
2008-12-11 14:52:05 +01:00
|
|
|
System.exit( 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------------------------------------
|
2002-03-18 10:24:46 +01:00
|
|
|
|
|
|
|
}
|