[Toc][Index]

Check if a queue exists



There is no function to check if a queue exists. To do this, you can use 
either the procedure shown below or the function RxProcQueueExists from 
the RXPROC.DLL from the SRE2003 Internet Interface package.   

 
/* sample code to extend the RXQUEUE function with code               */
/*                                                                    */
/*   - to check if a queue exists                                     */
/*   - to test if a queue is working                            v3.60 */
/*                                                                    */

                        /* stem with the names of the test queues     */
  testQueue.0 = 2
  testQueue.1 = "QUEUEA"
  testQueue.2 = "QUEUEB"

                        /* install some error handlers to ensure the  */
                        /* deletion of the test queues at program     */
                        /* end if the program is aborted due to an    */
                        /* error!                                     */
  SIGNAL ON SYNTAX  Name ProgramEnd
  SIGNAL ON ERROR   Name ProgramEnd
  SIGNAL ON HALT    Name ProgramEnd

                        /* create the test queues                     */
  say "Creating some queues for testing ..."

  do i = 1 to TestQueue.0
    call CharOut, " Creating the queue """ || testQueue.i || """ ..."
    if rxQueue( "CREATE", testQueue.i ) = testQueue.i then
      call LineOut, " done."
    else
      call LineOut, " failed."
  end /* do i = 1 to TestQueue.0 */
  say ''

  do until myInput = ""
    say "Enter the parameter for rxqueue (RETURN to exit): "
    say "Examples: ""QUERY queuea"" ""TEST queuec"" ""CREATE"""
    myInput = strip( lineIn() )

    if myInput <> "" then
    do
      parse var myInput queuefunction queueName
      if queueName <> "" then
      do
        say " -->> calling rxqueue( " || queueFunction || "," || queueName || " )"
        testResult = rxqueue( queueFunction, queueName )
      end /* if */
      else
      do
        say " -->> calling rxqueue( " || queueFunction || " )"
        testResult = rxqueue( queueFunction )
      end /* else */

      say "The result is """ || testResult || """"
      if testResult <> 0 then
      do
        say "The error message for " || testResult || " is "
        say "    " || GetQueueErrorMessage( testResult )
      end /* if */
    end /* if myInput <> "" then */
  end /* do until myInput = "" */

ProgramEnd:
                        /* delete the test queues                     */
  say "Deleting the queues for testing ..."

  do i = 1 to TestQueue.0
    say " Deleting the queue """ || testQueue.i || """ ..."

                        /* use the _original_ function to avoid       */
                        /* endless loops if the new RXQUEUE function  */
                        /* is buggy!                                  */
    call "RXQUEUE"  "DELETE", testQueue.i
  end /* do i = 1 to TestQueue.0 */

exit 0

/* ------------------------------------------------------------------ */
/* function: Extended RXQUEUE function                                */
/*                                                                    */
/* usage:    RXQUEUE action {,queue_name}                             */
/*                                                                    */
/* where:    action                                                   */
/*             - QUERY - check if the queue "queue_name" exists       */
/*                                                                    */
/*               syntax: RXQUEUE query , queuename                    */
/*                                                                    */
/*             - TEST - check if the queue "queue_name" is usable     */
/*                                                                    */
/*               syntax: RXQUEUE test {, queuename}                   */
/*                       default for queuename is the current queue   */
/*                                                                    */
/*             All other values for action are processed by the       */
/*             original RXQUEUE function.                             */
/*                                                                    */
/* returns:  if action = "QUERY":                                     */
/*             1 - the queue exists                                   */
/*             0 - the queue does not exist                           */
/*            40 - syntax error                                       */
/*             else                                                   */
/*               error code of the original RXQUEUE function          */
/*                                                                    */
/*           if action = "TEST":                                v3.60 */
/*             0 - the queue is working                               */
/*             1 - the queue does not work                            */
/*            40 - syntax error                                       */
/*             else                                                   */
/*               error description (e.g SYNTAX ERROR)                 */
/*                                                                    */
/*           if action <> "QUERY" and <> "TEST":                      */
/*             return code of the original RXQUEUE function           */
/*                                                                    */
/* history                                                            */
/*   RXTT v3.60 - added the function TEST                             */
/*                                                                    */
RXQUEUE: PROCEDURE
  parse arg action, queue_name

                        /* init the return code (40 = incorrect call) */
  rc = 40

  currentQueue = ""

                        /* install local error handler                */
  SIGNAL ON SYNTAX NAME RxQueueError
  SIGNAL ON FAILURE NAME RxQueueError
  SIGNAL ON ERROR NAME RxQueueError

  curAction = translate( action )
  curQueue = translate( strip( queue_name ) )

  select

    when curAction = "QUERY" then
    do

      if curQueue <> "" then
      do

                        /* try to create the queue ...                */
        tempQueue = "RXQUEUE"( "CREATE", curQueue )

                        /* ... and delete the just created queue      */
        call "RXQUEUE" "DELETE", tempQueue

                        /* set the return code                        */
        rc = ( tempQueue <> curQueue )
      end /* if curQueue <> "" then */
    end /* when curAction = "QUERY" then */

    when curAction = "TEST" then
    do
       rc = 1

                        /* save the current queue name                */
      if queue_name <> "" then
        currentQueue = "RXQUEUE"( "SET", queue_name )

                        /* The current queue is restored a the end    */
                        /* of the routine                             */

      queue_teststring = "rxqueue test function"
      queue queue_teststring
      if queued() <> 0 then
      do
        curString = lineIn( 'QUEUE:' )
        if curString <> queue_testString then
          queue curString
        else
          rc = 0
      end /* if */

    end /* when curAction = "TEST" then */

    otherwise
    do
                        /* call the original RXQUEUE function         */
      if queue_name <> "" then
        rc = "RXQUEUE"( action, queue_name )
      else
        rc = "RXQUEUE"( action )
    end /* otherwise */

 end /* select */


RxQueueError:
                        /* restore the current queue if necessary     */
  if currentQueue <> "" then
    call "RXQUEUE" 'set', currentQueue

RETURN rc


/* ------------------------------------------------------------------ */
/* function: Get the error message for an error code                  */
/*                                                                    */
/* usage:    GetQueueErrorMessage( errorNumber )                      */
/*                                                                    */
/* where:    errorNumber - error number                               */
/*                                                                    */
/* returns:  the error message                                        */
/*                                                                    */
GetQueueErrorMessage: PROCEDURE
  parse arg errorCode

  errorMessages. = "Unknown error code"

  errorMessages.0 = "Operation successfull."
  errorMessages.5 = "Not a valid queue name or tried to delete queue named 'SESSION'."
  errorMessages.9 = "Queue named does not exist."
  errorMessages.10 = "Queue is busy; wait is active."
  errorMessages.12 = "A memory failure has occurred."
  errorMessages.40 = "Incorrect call (invalid or missing queue name)."
  errorMessages.48 = "Failure in system service (the queue does not exist)."

  errorMessages.1000 = "Initialization error; check file OS2.INI."

  if errorCode = "" then
    return "Parameter for GetQueueErrorMessage missing"
  else
    return errorMessages.errorCode

  

Created using Inf-PHP v.2 (c) 2003 Yuri Prokushev
Created using Inf-HTML v.0.9b (c) 1995 Peter Childs