home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / rex22emx.zip / demo / extqueue.rexx < prev    next >
OS/2 REXX Batch file  |  2000-08-12  |  3KB  |  95 lines

  1. #!/usr/local/bin/rexx
  2. /*
  3.  * This program tests the external queue interface of Regina
  4.  * It runs num_clients instances of itself, each instance will create a
  5.  * named queued. For even numbered instances, lines will be queued
  6.  * FIFO; odd numbered instances will be queued LIFO.
  7.  * Once each instance queues its lines, it will read lines off
  8.  * another stack; created by its opposite instance.
  9.  * Opposite instances are eg. instance 1 and num_clients, 2 and 48, etc
  10.  */
  11. Trace o
  12. num_clients = 50 /* 50 */
  13. num_lines = 10   /* 100 */
  14. If Arg() = 0 Then
  15.    Do
  16.       Do i = 1 To num_clients
  17.          Address System './rexx extqueue.rexx' i '&'
  18.       End
  19.    End
  20. Else
  21.    Do
  22.       /*
  23.        * Set up the list of opposites...
  24.        */
  25.       Do i = 1 To num_clients
  26.          opposite.i = 1+(num_clients-i)
  27.       End
  28.       Parse Arg instance
  29.       If instance // 2 = 0 Then order = 'fifo'
  30.       Else order = 'lifo'
  31.       Call Rxqueue 'Create', 'QUEUE'instance 
  32.       /* Say '***Creating queue' Rxqueue('Create', 'QUEUE'instance ) */
  33.       /*
  34.        * push or queue num_lines lines onto our queue
  35.        */
  36.       Do i = 1 To num_lines
  37.          line = 'line'i 'from instance' instance
  38.          /* Say '***Going to put <'line'> on queue:' order */
  39.          If order = 'fifo' Then Queue line
  40.          Else Push line
  41.       End
  42.       /*
  43.        * Sleep for 10 seconds, then find our opposite, and
  44.        * set our default queue to its queue, and read off
  45.        * the the lines, checking they are in the correct
  46.        * order and the correct contents
  47.        */
  48.       Call Sleep(10)
  49. /*
  50.       Say '***Setting queue. Previous was:' rxqueue('Set', 'QUEUE'opposite.instance)
  51.       Say '***Getting queue. Now:' rxqueue('Get')
  52. */
  53.       Call rxqueue 'Set', 'QUEUE'opposite.instance
  54.       /*
  55.        * The order of the lines is the opposite to
  56.        * the order in which we put our lines on our queue
  57.        */
  58.       If order = 'lifo' Then
  59.          Do
  60.             /*
  61.              * PULL the lines off the stack, and check them
  62.              * they should be in FIFO order,
  63.              */
  64.             Do i = 1 To num_lines
  65.                Parse Pull line
  66.                exp = 'line'i 'from instance' opposite.instance
  67.                If line \=  exp Then Call Abort line, exp
  68.             End
  69.          End
  70.       Else
  71.          Do
  72.             /*
  73.              * PULL the lines off the stack, and check them
  74.              * they should be in LIFO order,
  75.              */
  76.             Do i = num_lines To 1 By -1
  77.                Parse Pull line
  78.                exp = 'line'i 'from instance' opposite.instance
  79.                If line \= exp Then Call Abort line, exp
  80.             End
  81.          End
  82.       /*
  83.        * Cleanup up our opposite's queue
  84.        */
  85.       Call Rxqueue 'Delete', 'QUEUE'opposite.instance
  86.       Say 'Instance' instance 'finished.'
  87.    End
  88. Return 0
  89.  
  90. Abort: Procedure Expose instance
  91. Parse Arg line, exp
  92. Say 'Error validating instance' instance'. Got <'line'> Expecting <'exp'>'
  93. Call Rxqueue 'Delete', 'QUEUE'opposite.instance
  94. Exit 1
  95.