ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » [MVS last message]

Post new topic  Reply to topic
 [MVS last message] « View previous topic :: View next topic » 
Author Message
lucimast
PostPosted: Thu Jan 12, 2006 9:14 am    Post subject: [MVS last message] Reply with quote

Novice

Joined: 12 Nov 2003
Posts: 15

Hello, (Sorry for my english!)

I'm doing a request "DISPLAY CHSTATUS(*) all" with JAVA on a z/OS but I've got a problem. I don't know if I'm really getting all the response messages.

I'm testing if the currentDepth is > 0 but I'm not sure that all the messages are arrived !!

How to do that ?

Can you help me ?

here is my code :
Code:

package asyst.monitoringmq.mq;

import java.util.ArrayList;
import java.util.Iterator;

import usinor.utils.AppService;
import asyst.monitoringmq.Category;
import asyst.monitoringmq.beans.Constantes;
import asyst.monitoringmq.beans.QueueElement;

import com.ibm.mq.MQC;
import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
/**
 * MQ Command Processor executed from OMVS
 *
*/

public class OS390Info {
   String errMsg = "";
   String ip = "";
   String channel = "";
   int port = 0;
   String queueMgr = "";
   String qName = "";

   public OS390Info(
      String ip,
      String channel,
      int port,
      String queueMgr,
      String qName) {
      super();
      this.ip = ip;
      this.channel = channel;
      this.port = port;
      this.queueMgr = queueMgr;
      this.qName = qName;

   }

   public OS390Info(String ip, String channel, int port, String queueMgr) {
      super();
      this.ip = ip;
      this.channel = channel;
      this.port = port;
      this.queueMgr = queueMgr;
   }

   public ArrayList getOS390Info(String commandToExecute, String source)
      throws Exception {
      String qmgr = null;
      String mqcommand = null;
      boolean qmgr_specified = false;
      boolean mqcommand_specified = false;
      String queue;
      String commandQ = "SYSTEM.COMMAND.INPUT";
      String modelQ = "SYSTEM.COMMAND.REPLY.MODEL";
      String dynamicQ = "CSQ.*";
      int msglen;
      int qdepth = 0;
      int sleeptime = 1000;
      int time_out = 60;
      String nextline = null;
      MQQueueManager qMgr = null;

      ArrayList list = new ArrayList();

      try {

         MQEnvironment.hostname = ip;
         MQEnvironment.channel = channel;
         MQEnvironment.port = port;

         qMgr = new MQQueueManager(queueMgr);
         /*********************************************************************/
         /*                                                                   */
         /*  Create a temporary dynamic queue to receive reply messages       */
         /*                                                                   */
         /*********************************************************************/
         int openOptions = MQC.MQOO_INPUT_SHARED;

         MQQueue tempQ =
            qMgr.accessQueue(
               modelQ,
               MQC.MQOO_INPUT_SHARED,
               qmgr,
               dynamicQ,
               null);

         /*********************************************************************/
         /*                                                                   */
         /*  Open command queue and put the command on to it                  */
         /*                                                                   */
         /*********************************************************************/
         openOptions = MQC.MQOO_OUTPUT;

         MQQueue q = qMgr.accessQueue(commandQ, openOptions);

         MQPutMessageOptions pmo = new MQPutMessageOptions();
         MQMessage outputMessage = new MQMessage();
         outputMessage.replyToQueueName = tempQ.name;
         outputMessage.messageType = MQC.MQMT_REQUEST;
         outputMessage.format = MQC.MQFMT_STRING;
      
         outputMessage.writeString(commandToExecute);
         q.put(outputMessage, pmo);
         q.close();

         /*********************************************************************/
         /*                                                                   */
         /*  Check the temporary queue to see if the reply messages           */
         /*  ready on the queue. If not, pause for a second then retry        */
         /*                                                                   */
         /*********************************************************************/

         openOptions = MQC.MQOO_INQUIRE;

         q = qMgr.accessQueue(tempQ.name, openOptions);

         MQGetMessageOptions gmo = new MQGetMessageOptions();

         int qtype = q.getQueueType();
         int loop = 0;

         do {
            

            qdepth = q.getCurrentDepth();
            java.lang.Thread.sleep(sleeptime);

            if (loop > time_out) {
               AppService.getLogger().logError(
                  Category.GENERAL,
                  "Erreur Timeout occurred, no reply messages are available on temporary Q -> "
                     + tempQ.name
                     + "\nafter "
                     + time_out
                     + " seconds");
               System.exit(-1);
            }
            loop++;
         } while (qdepth == 0);

         /*********************************************************************/
         /*                                                                   */
         /*  The reply messages are now available on the temporary queue and  */
         /*  we can open it and read the reply messages and display them      */
         /*                                                                   */
         /*********************************************************************/

         openOptions = MQC.MQOO_INPUT_AS_Q_DEF;

         q = qMgr.accessQueue(tempQ.name, openOptions);
         gmo = new MQGetMessageOptions();
         int options = MQC.MQGMO_ACCEPT_TRUNCATED_MSG | MQC.MQGMO_CONVERT;
         gmo.options = options;

         /*********************************************************************/
         /*                                                                   */
         /*  Keep reading the reply messages until the temporary queue is     */
         /*  empty                                                            */
         /*                                                                   */
         /*********************************************************************/

         for (int i = 0; i < qdepth; i++) {
            int index0 = 0;
            int index1 = 0;
            int num = 0;
            int numchar;
            boolean noLeftParenthesis = true;
            boolean specialmsg = false;
            boolean stage1 = true;
            boolean stage2 = false;
            boolean skip = true;

            MQMessage retrieveMessage = new MQMessage();
            q.get(retrieveMessage, gmo);

            msglen = retrieveMessage.getMessageLength();

            String msgtext = retrieveMessage.readString(msglen);
            StringBuffer outbuff = new StringBuffer(msglen);

            /*********************************************************************/
            /*                                                                   */
            /*  Each reply message is a character string of text messages with   */
            /*  a lot of embedded blank spaces and we should remove the          */
            /*  redundant blank spaces and format the message in such a way that */
            /*  each line only contains an individual parameter.                 */
            /*                                                                   */
            /*********************************************************************/
            for (int j = 0; j < msglen; j++) {
               outbuff.append(msgtext.charAt(j));

               if (msgtext.charAt(j) == '(') {
                  noLeftParenthesis = false;
                  num++;
               }
            }

            if (num <= 2)
               specialmsg = true;
            /*********************************************************************/
            /*  For a short message, just display it without any modifications   */
            /*********************************************************************/

            if (noLeftParenthesis) {
               nextline = outbuff.toString();
               list.add(nextline);
               continue;
            }
            /*********************************************************************/
            /*                                                                   */
            /*  A special message is a message that contains 1 or 2 parameters   */
            /*  with parenthesis                                                 */
            /*                                                                   */
            /*********************************************************************/

            if (specialmsg) {

               outbuff = new StringBuffer(msglen);
               for (int j = index0; j < msglen; j++) {
                  if (stage1)
                     outbuff.append(msgtext.charAt(j));
                  if (msgtext.charAt(j) == '(') {
                     stage1 = false;
                     stage2 = true;
                     continue;
                  }

                  if (stage1)
                     continue;
                  if (msgtext.charAt(j) == ' ' && stage2)
                     continue;
                  if (msgtext.charAt(j) == ')') {
                     stage1 = true;
                     stage2 = false;
                  }
                  outbuff.append(msgtext.charAt(j));
               }
               nextline = outbuff.toString();
               list.add(nextline);
               continue;
            }
            /*********************************************************************/
            /*                                                                   */
            /*  A long message is a message that contains more than 2 parameters */
            /*  with parenthesis                                                 */
            /*                                                                   */
            /*********************************************************************/

            outbuff = new StringBuffer(msglen);
            for (int j = index0; j < msglen; j++) {
               if (stage1)
                  outbuff.append(msgtext.charAt(j));

               if (msgtext.charAt(j) == '(') {
                  stage1 = false;
                  stage2 = true;
                  continue;
               }

               if (stage1)
                  continue;
               if (msgtext.charAt(j) == ' ' && stage2)
                  continue;

               outbuff.append(msgtext.charAt(j));

               if (msgtext.charAt(j) == ')') {
                  nextline = outbuff.toString();
                  list.add(nextline);
                  index1 = j + 2;
                  break;
               }
            }

            outbuff = new StringBuffer(msglen);

            for (int j = index1; j < msglen; j++) {

               if (msgtext.charAt(j) == ' '
                  && msgtext.charAt(j + 1) != ' ') {
                  nextline = outbuff.toString();
                  list.add(nextline);
                  outbuff = new StringBuffer(msglen);
                  continue;
               }
               outbuff.append(msgtext.charAt(j));
               skip = true;
               if (msgtext.charAt(j) == '(') {

                  for (int k = j + 1; k < msglen; k++) {
                     if (msgtext.charAt(k) == ',')
                        skip = false;
                     if (!skip
                        && msgtext.charAt(k) == ' '
                        && msgtext.charAt(k + 1) == ' ')
                        skip = true;
                     if (msgtext.charAt(k) == ' ' && skip)
                        continue;
                     outbuff.append(msgtext.charAt(k));
                     if (msgtext.charAt(k) == ')') {
                        nextline = outbuff.toString();
                        list.add(nextline);
                        j = k + 1;
                        outbuff = new StringBuffer(msglen);
                        break;
                     }
                  }
               }
            }
         }
         /*********************************************************************/
         /*                                                                   */
         /*  Close and delete the temporary queue                             */
         /*                                                                   */
         /*********************************************************************/
         tempQ.closeOptions = MQC.MQCO_DELETE_PURGE;
         tempQ.close();
         q.close();

         //qMgr.disconnect();

         return list;

      } catch (MQException ex) {
         AppService.getLogger().logError(
            Category.MQ,
            "Erreur MQ dans parseQueueInformation = " + ex.getMessage());
         //System.out.println("An error occurred: " + ex);
         errMsg = ex.getMessage();

         throw ex;
      } catch (java.io.IOException ex) {
         AppService.getLogger().logError(
            Category.GENERAL,
            "Erreur io dans parseQueueInformation : An error occurred while writing to the message buffer: "
               + ex);
         //System.out.println(
         //   "An error occurred while writing to the message buffer: " + ex);
         //return null;
         throw ex;
      } catch (InterruptedException ex) {
         AppService.getLogger().logError(
            Category.GENERAL,
            "Erreur dans parseQueueInformation : An interrupt occurred on sleep  "
               + ex);
         //System.out.println("An interrupt occurred on sleep  " + ex);
         //return null;
         throw ex;
      }

      //System.exit(0);

      finally {
         qMgr.disconnect();
      }

   }




Thanks
Back to top
View user's profile Send private message
wschutz
PostPosted: Thu Jan 12, 2006 9:48 am    Post subject: Reply with quote

Jedi Knight

Joined: 02 Jun 2005
Posts: 3316
Location: IBM (retired)

There is a chapter called "Writing Programs to Administer WMQ" in the zOS System Admin Guide, it does a good job of explaining how to process replies from "plain text" commands on zOS.
_________________
-wayne
Back to top
View user's profile Send private message Send e-mail AIM Address
lucimast
PostPosted: Mon Jan 16, 2006 2:15 am    Post subject: Reply with quote

Novice

Joined: 12 Nov 2003
Posts: 15

Thank you for the answer.

I read in this book that if the RETURN= value is 00000000 and the REASON= value is 00000004, the set of reply messages is incomplete. But I don't how to do to get the RETURN and the REASON!!

Can you help me ?
Back to top
View user's profile Send private message
wschutz
PostPosted: Mon Jan 16, 2006 4:11 am    Post subject: Reply with quote

Jedi Knight

Joined: 02 Jun 2005
Posts: 3316
Location: IBM (retired)

Quote:
The first user message, CSQN205I, always contains:
v A count of the replies (in decimal), which you can use as a counter in a loop to
get the rest of the replies. The count includes this first message.
v The return code from the command preprocessor.
v A reason code, which is the return code from the command processor.

_________________
-wayne
Back to top
View user's profile Send private message Send e-mail AIM Address
lucimast
PostPosted: Mon Jan 16, 2006 5:11 am    Post subject: Reply with quote

Novice

Joined: 12 Nov 2003
Posts: 15

Do you mean that with Java it is impossible to get the REASON and the RETURN CODE whithout parsing the replies ?
Back to top
View user's profile Send private message
Mr Butcher
PostPosted: Mon Jan 16, 2006 5:14 am    Post subject: Reply with quote

Padawan

Joined: 23 May 2005
Posts: 1716

try to think asynchronous!
_________________
Regards, Butcher
Back to top
View user's profile Send private message
lucimast
PostPosted: Mon Jan 16, 2006 5:16 am    Post subject: Reply with quote

Novice

Joined: 12 Nov 2003
Posts: 15

Sorry, but I don't understand!
Back to top
View user's profile Send private message
Mr Butcher
PostPosted: Mon Jan 16, 2006 5:28 am    Post subject: Reply with quote

Padawan

Joined: 23 May 2005
Posts: 1716

i see

your program just issues the request to mqseries to process a command by putting a messages into the SYSTEM.COMMAND.INPUT queue.
the command is processed while your program is waiting for the reply messages.
for the put of the command and the get of the reply messages you get returncodes, but they are related only to the mqput and mqget operations. because the command is issued while you rprogram is waiting it is asynchronous, and there is no way to tell your application program directly about the returncode of the command, it is put into the message data.

there is no difference in this scenario between the command processor answering your command request or an application somewhere answering a request message. it is asynchronous and you will never get a returncode directly.
_________________
Regards, Butcher
Back to top
View user's profile Send private message
wschutz
PostPosted: Mon Jan 16, 2006 5:29 am    Post subject: Reply with quote

Jedi Knight

Joined: 02 Jun 2005
Posts: 3316
Location: IBM (retired)

Tje manual is saying that you must read the first message you get back from the zOS command server to get the record count, the reason and return codes.
_________________
-wayne
Back to top
View user's profile Send private message Send e-mail AIM Address
lucimast
PostPosted: Mon Jan 16, 2006 6:41 am    Post subject: Reply with quote

Novice

Joined: 12 Nov 2003
Posts: 15

Ok, It works !!
Thanks a lot!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » [MVS last message]
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.