home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / ENTRPRIS / APE / AECLIENT / CLSPOOTL.CLS < prev    next >
Encoding:
Visual Basic class definition  |  1996-11-16  |  10.7 KB  |  251 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "clsPoolTestTool"
  6. Attribute VB_GlobalNameSpace = True
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11. '-------------------------------------------------------------------------
  12. 'This class provides a RunTest method to be called to run a Pool
  13. 'Management model test.
  14. '-------------------------------------------------------------------------
  15.  
  16. Public Sub RunTest()
  17.     '-------------------------------------------------------------------------
  18.     'Purpose:   Executes a loop for glNumberOfCalls each time calling
  19.     '           AEWorker.Worker.DoActivity.  Before each call a Worker
  20.     '           is Requested from AEPoolMgr.Pool after each call the
  21.     '           Worker is released and PoolMgr is called again to
  22.     '           notify of release.  This method actually runs
  23.     '           a test according to set properties
  24.     'Assumes:   All Client properties have been set.
  25.     'Effects:
  26.     '           Calls CompleteTest when finished calling Worker
  27.     '   [gbRunning]
  28.     '           Is true during procedure
  29.     '   [glFirstServiceTick]
  30.     '           becomes the tick count of when the test is started
  31.     '   [glLastCallbackTick]
  32.     '           becomes the tick count of when the last call is made
  33.     '   [glCallsMade]
  34.     '           is incremented every time the Worker is called
  35.     '-------------------------------------------------------------------------
  36.     
  37.     'Called by tmrStartTest so that the StartTest method can release
  38.     'the calling program.
  39.     
  40.     Const lMAX_COUNT = 2147483647
  41.     Dim s As String         'Error message
  42.     Dim lServiceID As Long  'Service Request ID
  43.     Dim lTicks As Long      'Tick Count
  44.     Dim lEndTick As Long    'DoEvents loop until this Tick Count
  45.     Dim lCallNumber As Long 'Number of calls to Worker
  46.     Dim lNumberOfCalls As Long      'Test duration in number of calls
  47.     Dim iDurationMode As Integer    'Test duration mode
  48.     Dim lDurationTicksEnd As Long   'Tick that test should end on
  49.     Dim bPostingServices As Boolean 'In main loop of procedure
  50.     Dim iRetry As Integer           'Number of call reties made by error handling resume
  51.     Dim vSendData As Variant        'Data to send with Service request
  52.     Dim bRandomSendData As Boolean  'If true vSendData needs generated before each new request
  53.     Dim sSendCommand As String      'Command string to be sent with Service Request
  54.     Dim bRandomCommand As Boolean   'If true sSendCommand needs generated before each new request
  55.     Dim lCallWait As Long           'Number of ticks to wait between calls
  56.     Dim bRandomWait As Boolean      'If true lCallWait needs generated before each new request
  57.     Dim bSendSomething As Boolean    'If true data needs passed with request
  58.     Dim bReceiveSomething As Boolean 'If true data is expected back from request
  59.     Dim oWorker As AEWorker.Worker  'Local reference to the Worker
  60.     Dim oPool As AEPoolMgr.Pool
  61.     Dim bLog As Boolean             'If true log records
  62.     Dim bShow As Boolean            'If true update display
  63.     Dim iPoolWaitRetryCount As Integer  'Number of times retry is need for each call loop
  64.     
  65.     On Error GoTo RunTestError
  66.     'If there is reentry by a timer click exit sub
  67.     If gbRunning Then Exit Sub
  68.     gbRunning = True
  69.     
  70.     'Set the local variables to direct the testing
  71.     Set oPool = New AEPoolMgr.Pool
  72.     
  73.     bRandomSendData = GetTestData(bSendSomething, bReceiveSomething, vSendData)
  74.     lCallWait = GetValueFromRange(gudtWaitPeriod, bRandomWait)
  75.     sSendCommand = GetServiceCommand(bRandomCommand)
  76.     bLog = gbLog
  77.     bShow = gbShow
  78.     
  79.     s = LoadResString(giTEST_STARTED)
  80.     If bLog Then AddLogRecord 0, s, GetTickCount(), False
  81.     DisplayStatus s
  82.     glFirstServiceTick = GetTickCount()
  83.     
  84.     'Test duration variables
  85.     iDurationMode = giTestDurationMode
  86.     If iDurationMode = giTEST_DURATION_CALLS Then
  87.         lNumberOfCalls = glNumberOfCalls
  88.     ElseIf iDurationMode = giTEST_DURATION_TICKS Then
  89.         lDurationTicksEnd = glFirstServiceTick + glTestDurationInTicks
  90.     End If
  91.     
  92.     bPostingServices = True
  93.     Do While Not gbStopping
  94.         'Check if new data needs generated because of randomization
  95.         If bRandomSendData Then bRandomSendData = GetTestData(bSendSomething, bReceiveSomething, vSendData)
  96.         If bRandomWait Then lCallWait = GetValueFromRange(gudtWaitPeriod, bRandomWait)
  97.         If bRandomCommand Then sSendCommand = GetServiceCommand(bRandomCommand)
  98.         
  99.         'Increment number of calls made
  100.         lCallNumber = glCallsMade + 1
  101.         'Get a Worker from the PoolMgr
  102.         'Post the service to a worker
  103.         'Post a synchronous service
  104.         iRetry = 0
  105.         iPoolWaitRetryCount = 0
  106. RunTest_GetWorkerRetry:
  107.         Set oWorker = oPool.GetWorker
  108.         'Pool Manager may reject request for worker
  109.         'If it does wait sometime and retry
  110.         If oWorker Is Nothing Then GoTo RunTest_WaitForPool
  111.         iRetry = 0
  112.         If bSendSomething Then
  113.             oWorker.DoService lServiceID, sSendCommand, vSendData
  114.         Else
  115.             oWorker.DoService lServiceID, sSendCommand
  116.         End If
  117.         Set oWorker = Nothing
  118.         oPool.ReleaseWorker
  119.         
  120.         'Display CallsMade
  121.         If bShow Then
  122.             With frmClient
  123.                 .lblCallsMade = lCallNumber
  124.                 .lblCallsReturned = lCallNumber
  125.                 .lblCallsMade.Refresh
  126.                 .lblCallsReturned.Refresh
  127.             End With
  128.         End If
  129.         'If gbStopping Then Exit Do
  130.         'Go into an idle loop util the next call.
  131.         If lCallWait > 0 Then
  132.             lEndTick = GetTickCount + lCallWait
  133.             Do While GetTickCount() < lEndTick And Not gbStopping
  134.                 DoEvents
  135.             Loop
  136.         End If
  137.         glCallsMade = lCallNumber
  138.         
  139.         'See if it is time to stop the test
  140.         If iDurationMode = giTEST_DURATION_CALLS Then
  141.             If lCallNumber >= lNumberOfCalls Then Exit Do
  142.         ElseIf iDurationMode = giTEST_DURATION_TICKS Then
  143.             If GetTickCount >= lDurationTicksEnd Then Exit Do
  144.         End If
  145.     Loop
  146. StopTestNow:
  147.     bPostingServices = False
  148.     glLastCallbackTick = GetTickCount()
  149.     gbRunning = False
  150.     Set oWorker = Nothing
  151.     If gbStopping Then
  152.         'Someone hit the stop button on the Explorer.
  153.         gStopTest
  154.         Exit Sub
  155.     End If
  156.     If bLog Then AddLogRecord 0, LoadResString(giSERVICES_POSTED), GetTickCount(), False
  157.     CompleteTest
  158.     Exit Sub
  159. RunTest_WaitForPool:
  160.     If iPoolWaitRetryCount <= giMAX_ALLOWED_RETRIES Then
  161.         iPoolWaitRetryCount = iPoolWaitRetryCount + 1
  162.         lEndTick = GetTickCount + lCallWait + giPOOL_WAIT_RETRY_MIN
  163.         Do While GetTickCount() < lEndTick And Not gbStopping
  164.             DoEvents
  165.         Loop
  166.         GoTo RunTest_GetWorkerRetry
  167.     Else
  168.         'We reached our max retries
  169.         s = LoadResString(giPOOL_MGR_REJECTION_WAITS_EXHAUSTED)
  170.         If bLog Then AddLogRecord 0, s, GetTickCount(), False
  171.         DisplayStatus s
  172.         StopOnError s
  173.         Exit Sub
  174.     End If
  175.     Exit Sub
  176. RunTestError:
  177.     Select Case Err.Number
  178.         Case RPC_E_CALL_REJECTED
  179.             'Collision error, the OLE server is busy
  180.             Dim il As Integer
  181.             Dim ir As Integer
  182.             'First check if stopping test
  183.             If gbStopping Then GoTo StopTestNow
  184.             If bLog Then AddLogRecord 0, LoadResString(giQUEUE_SERVICE_COLLISION_RETRY), GetTickCount(), False
  185.             If iRetry < giMAX_ALLOWED_RETRIES Then
  186.                 iRetry = iRetry + 1
  187.                 ir = Int((giRETRY_WAIT_MAX - giRETRY_WAIT_MIN + 1) * Rnd + giRETRY_WAIT_MIN)
  188.                 For il = 0 To ir
  189.                     DoEvents
  190.                 Next il
  191.                 If gbStopping Then Resume Next Else Resume
  192.             Else
  193.                 'We reached our max retries
  194.                 s = LoadResString(giCOLLISION_ERROR)
  195.                 If bLog Then AddLogRecord 0, s, GetTickCount(), False
  196.                 DisplayStatus s
  197.                 StopOnError s
  198.                 Exit Sub
  199.             End If
  200.         Case ERR_OBJECT_VARIABLE_NOT_SET
  201.             'Worker was not successfully created
  202.             s = LoadResString(giQUEUE_SERVICE_ERROR) & CStr(Err.Number) & gsSEPERATOR & Err.Source & gsSEPERATOR & Err.Description
  203.             DisplayStatus Err.Description
  204.             If gbLog Then AddLogRecord 0, s, GetTickCount(), False
  205.             StopOnError s
  206.             Exit Sub
  207.         Case ERR_CANT_FIND_KEY_IN_REGISTRY
  208.             'AEInstancer.Instancer is a work around for error
  209.             '-2147221166 which occurrs every time a client
  210.             'object creates an instance of a remote server,
  211.             'destroys it, registers it local, and tries to
  212.             'create a local instance.  The client can not
  213.             'create an object registered locally after it created
  214.             'an instance while it was registered remotely
  215.             'until it shuts down and restarts.  Therefore,
  216.             'it works to call another process to create the
  217.             'local instance and pass it back.
  218.             Dim oInstancer As AEInstancer.Instancer
  219.             Set oInstancer = New AEInstancer.Instancer
  220.             Set oWorker = oInstancer.object("AEWorker.Worker")
  221.             Set oInstancer = Nothing
  222.             Resume Next
  223.         Case RPC_S_UNKNOWN_AUTHN_TYPE
  224.             'Tried to connect to a server that does not support
  225.             'specified authentication level.  Display message and
  226.             'switch to no authentication and try again
  227.             Dim iResult As Integer
  228.             s = LoadResString(giUSING_NO_AUTHENTICATION)
  229.             DisplayStatus s
  230.             AddLogRecord 0, s, 0, False
  231.             glConnectionAuthentication = RPC_C_AUTHN_LEVEL_NONE
  232.             iResult = goRegClass.SetAutoServerSettings(True, "AEPoolMgr.Pool", , gsConnectionAddress, gsConnectionProtocol, glConnectionAuthentication)
  233.             Resume
  234.         Case ERR_OVER_FLOW
  235.             s = CStr(Err.Number) & gsSEPERATOR & Err.Source & gsSEPERATOR & Err.Description
  236.             lCallNumber = 0
  237.             If gbLog Then AddLogRecord 0, s, GetTickCount(), False
  238.         Case Else
  239.             s = LoadResString(giQUEUE_SERVICE_ERROR) & CStr(Err.Number) & gsSEPERATOR & Err.Source & gsSEPERATOR & Err.Description
  240.             DisplayStatus Err.Description
  241.             If gbLog Then AddLogRecord 0, s, GetTickCount(), False
  242.             If bPostingServices Then
  243.                 StopOnError s
  244.                 Exit Sub
  245.             Else
  246.                 Resume Next
  247.             End If
  248.     End Select
  249. End Sub
  250.  
  251.