Check if a queue exists

[Autolink] Menu

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                                                     */

                        /* 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 name of the queue to check (RETURN to exit): "
    myInput = strip( lineIn() )
    if myInput <> "" then
    do
      queueExist = rxqueue( "QUERY", myInput )

      select
        when queueExist = 0 then
          say "The queue """ || myInput || """ does not exist."

        when queueExist = 1 then
          say "The queue """ || myInput || """ exist."

        otherwise
          say "Error """ || queueExist || """ executing RXQUEUE!"

      end /* select */

    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       */
/*             All other values for action are processed by the       */
/*             original RXQUEUE function.                             */
/*                                                                    */
/* returns:  if action = "QUERY":                                     */
/*             1 - the queue exist                                    */
/*             0 - the queue does not exist                           */
/*             else                                                   */
/*               error code of the original RXQUEUE function          */
/*           if action <> "QUERY":                                    */
/*             return code of the original RXQUEUE function           */
/*             or "SYNTAX ERROR" if called with invalid parameter(s)  */
/*                                                                    */
RXQUEUE: PROCEDURE
  parse arg action, queue_name

                        /* init the return code                       */
  rc = "SYNTAX ERROR"

                        /* install a local error handler              */
  SIGNAL ON SYNTAX NAME RxQueueError

  if translate( action ) = "QUERY" then
  do
    if queue_name <> "" then
    do
      queue_name = translate( strip( queue_name ) )
                        /* try to create the queue ...                */
      tempQueue = "RXQUEUE"( "CREATE", queue_name )

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

                        /* set the return code                        */
      rc = ( tempQueue <> translate( queue_name ) )
    end /* if queue_name <> "" then */
  end /* if translate( action ) = "QUERY" then */
  else
  do
                        /* call the original RXQUEUE function         */
    if queue_name <> "" then
      rc = "RXQUEUE"( action, queue_name )
    else
      rc = "RXQUEUE"( action )
  end /* else */

RxQueueError:

RETURN rc


[Back: Checking a queue]
[Next: Flushing a queue]