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 / AEPOOL / POOLMGR.CLS < prev   
Encoding:
Visual Basic class definition  |  1996-12-04  |  25.9 KB  |  592 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "PoolMgr"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Attribute VB_Description = "Provides an interface for AEPoolMgr to be configured and administrated."
  11. Option Explicit
  12. '-------------------------------------------------------------------------
  13. 'This public multi-use class provides the OLE interface for the APE Manager
  14. 'or another application designed to be the Manager
  15. '-------------------------------------------------------------------------
  16.  
  17. '***********************
  18. 'Public Properties
  19. '***********************
  20.  
  21. Public Property Let ShowPool(ByVal bShow As Boolean)
  22. Attribute ShowPool.VB_Description = "Determines whether the AEPoolMgr shows a form."
  23.     '-------------------------------------------------------------------------
  24.     'Purpose:   Show property determines whether or not a form
  25.     '           is displayed while PoolMgr is loaded
  26.     'Effects:   [gbShow] becomes value of parameter
  27.     '           If parameter is true frmPoolMgr is show, else form
  28.     '           is Unloaded.
  29.     '-------------------------------------------------------------------------
  30.     If Not gbShow = bShow Then
  31.         gbShow = bShow
  32.         If bShow Then
  33.             With frmPoolMgr
  34.                 .Show
  35.                 .lblWorkers.Caption = gcWorkers.Count
  36.                 .lblSatisfied.Caption = CStr(glRequestsSatisfied)
  37.                 .lblRejected.Caption = CStr(glRequestsRejected)
  38.             End With
  39.         Else
  40.             Unload frmPoolMgr
  41.         End If
  42.     End If
  43. End Property
  44.  
  45. Public Property Get ShowPool() As Boolean
  46.     ShowPool = gbShow
  47. End Property
  48.  
  49. Public Property Let LogPool(ByVal bLog As Boolean)
  50. Attribute LogPool.VB_Description = "Determines if the AEPoolMgrr logs its events and errors to the AELogger.Logger object."
  51.     '-------------------------------------------------------------------------
  52.     'Purpose:   If log is true create logger class object and log Services
  53.     'Effects:   [gbLog] becomes value of parameter
  54.     '           [goLogger] is set to a new AELogger.Logger object if parameter
  55.     '                      is true.  If false goLogger is destroyed
  56.     '-------------------------------------------------------------------------
  57.     On Error GoTo LogPoolError
  58.     If Not gbLog = bLog Then
  59.         gbLog = bLog
  60.         If bLog Then
  61.             Set goLogger = New AELogger.Logger
  62.         Else
  63.             Set goLogger = Nothing
  64.         End If
  65.     End If
  66.     Exit Property
  67. LogPoolError:
  68.     Select Case Err.Number
  69.         Case ERR_CANT_FIND_KEY_IN_REGISTRY
  70.             'AEInstancer.Instancer is a work around for error
  71.             '-2147221166 which occurrs every time a client
  72.             'object creates an instance of a remote server,
  73.             'destroys it, registers it local, and tries to
  74.             'create a local instance.  The client can not
  75.             'create an object registered locally after it created
  76.             'an instance while it was registered remotely
  77.             'until it shuts down and restarts.  Therefore,
  78.             'it works to call another process to create the
  79.             'local instance and pass it back.
  80.             Dim oInstancer As AEInstancer.Instancer
  81.             Set oInstancer = New AEInstancer.Instancer
  82.             Set goLogger = oInstancer.Object("AELogger.Logger")
  83.             Set oInstancer = Nothing
  84.             Resume Next
  85.         Case Else
  86.             Err.Raise Err.Number, Err.Source, Err.Description
  87.     End Select
  88. End Property
  89.  
  90. Public Property Get LogPool() As Boolean
  91.     LogPool = gbLog
  92. End Property
  93.  
  94. '********************
  95. 'Worker Properties
  96. '********************
  97. Public Property Let LogWorkers(ByVal bLog As Boolean)
  98. Attribute LogWorkers.VB_Description = "Sets the value that is used to set the Log property of AEWorker.Worker objects."
  99.     '-------------------------------------------------------------------------
  100.     'Purpose:   To set the Log property of all the Workers
  101.     'Effects:
  102.     '   [gbLogWorkers]
  103.     '           becomes equal to the passed parameter
  104.     'Assumes:   There is a collection of one or more valid Worker objects
  105.     '-------------------------------------------------------------------------
  106.     'If the property setting actually
  107.     'changes the current property pass
  108.     'the property change to all the Workers
  109.     Dim oWork As clsWorker
  110.     If Not bLog = gbLogWorkers Then
  111.         For Each oWork In gcWorkers
  112.             oWork.Worker.Log = bLog
  113.         Next oWork
  114.         gbLogWorkers = bLog
  115.     End If
  116. End Property
  117.  
  118. Public Property Get LogWorkers() As Boolean
  119.     LogWorkers = gbLogWorkers
  120. End Property
  121.  
  122. Public Property Let PersistentServices(ByVal bPersistent As Boolean)
  123. Attribute PersistentServices.VB_Description = "Sets the value that is used to set the PersistentServices property of AEWorker.Worker objects."
  124.     '-------------------------------------------------------------------------
  125.     'Purpose:   To set the PersistentServices property of all the Workers
  126.     'Effects:
  127.     '   [gbPersistentServices]
  128.     '           becomes equal to the passed parameter
  129.     'Assumes:   There is a collection of one or more valid Worker objects
  130.     '-------------------------------------------------------------------------
  131.     'If the property setting actually
  132.     'changes the current property pass
  133.     'the property change to all the Workers
  134.     Dim oWork As clsWorker
  135.     If Not bPersistent = gbPersistentServices Then
  136.         For Each oWork In gcWorkers
  137.             oWork.Worker.PersistentServices = bPersistent
  138.         Next oWork
  139.         gbPersistentServices = bPersistent
  140.     End If
  141. End Property
  142.     
  143. Public Property Get PersistentServices() As Boolean
  144.     PersistentServices = gbPersistentServices
  145. End Property
  146.  
  147. Public Property Let EarlyBindServices(ByVal bEarlyBind As Boolean)
  148. Attribute EarlyBindServices.VB_Description = "Sets the value that is used to set the EarlyBindServices property of AEWorker.Worker objects."
  149.     '-------------------------------------------------------------------------
  150.     'Purpose:   To set the EarlyBindServices property of all the Workers
  151.     'Effects:
  152.     '   [gbEarlyBindServices]
  153.     '           becomes equal to the passed parameter
  154.     'Assumes:   There is a collection of one or more valid Worker objects
  155.     '-------------------------------------------------------------------------
  156.     'If the property setting actually
  157.     'changes the current property pass
  158.     'the property change to all the Workers
  159.     Dim oWork As clsWorker
  160.     If Not bEarlyBind = gbEarlyBindServices Then
  161.         For Each oWork In gcWorkers
  162.             oWork.Worker.EarlyBindServices = bEarlyBind
  163.         Next oWork
  164.         gbEarlyBindServices = bEarlyBind
  165.     End If
  166. End Property
  167.  
  168. Public Property Get EarlyBindServices() As Boolean
  169.     EarlyBindServices = gbEarlyBindServices
  170. End Property
  171.  
  172. '****************************
  173. 'Public Methods
  174. '****************************
  175.  
  176. Public Sub SetProperties(ByVal bShow As Boolean, Optional ByVal bLog As Variant)
  177. Attribute SetProperties.VB_Description = "Sets all of the AEPoolMgr.PoolMgr related properties in one method call."
  178.     '-------------------------------------------------------------------------
  179.     'Purpose:   To set the PoolMgr properties in one method call
  180.     'Effects:   Sets the following properties to parameter values
  181.     '           ShowPool, LogPool, WorkerQuantity
  182.     '-------------------------------------------------------------------------
  183.     With Me
  184.         .ShowPool = bShow
  185.         If Not IsMissing(bLog) Then .LogPool = bLog
  186.     End With
  187. End Sub
  188.  
  189. Public Sub SetWorkerProperties(ByVal bLog As Boolean, Optional ByVal bEarlyBindServices As Variant, _
  190.         Optional ByVal bPersistentServices As Variant)
  191. Attribute SetWorkerProperties.VB_Description = "Sets all of the AEWorker.Worker related properties on one method call."
  192.     '-------------------------------------------------------------------------
  193.     'Purpose:   To set the Worker properties in one method call
  194.     'Effects:   Sets the following properties to parameter values
  195.     '           ShowWorkers, LogWorkers, EarlyBindServices, PersistentServices
  196.     '-------------------------------------------------------------------------
  197.     Dim oWork As clsWorker
  198.     gbLogWorkers = bLog
  199.     If Not IsMissing(bEarlyBindServices) Then gbEarlyBindServices = bEarlyBindServices
  200.     If Not IsMissing(bPersistentServices) Then PersistentServices = bPersistentServices
  201.     For Each oWork In gcWorkers
  202.         oWork.Worker.SetProperties gbLogWorkers, gbEarlyBindServices, gbPersistentServices
  203.     Next oWork
  204. End Sub
  205.  
  206. Public Sub SetConnectionProperties(ByVal bUseDCOM As Boolean, Optional ByVal sProtocol As Variant, _
  207.                                     Optional ByVal lAuthentication As Variant)
  208. Attribute SetConnectionProperties.VB_Description = "Sets the connection parameters to be used when creating remote AEWorker.Worker objects."
  209.     '-------------------------------------------------------------------------
  210.     'Purpose:   To set the Connection Settings that the PoolMgr will use
  211.     '           to connect to remote Workers
  212.     'In:
  213.     '   [bUseDCOM]
  214.     '           If true workers will be created using DCOM instead of
  215.     '           Remote Automation.
  216.     '   [sProtocol]
  217.     '           Protocol sequence to use when connecting to remote objects
  218.     '   [lAuthentication]
  219.     '           Authentication level to use
  220.     'Effects:
  221.     '   [gbUseDCOM]
  222.     '           becomes equal to bUseDCOM parameter
  223.     '   [gsProtocol]
  224.     '           becomes equal to sProtocol parameter
  225.     '   [glAuthentication]
  226.     '           becomes equal to lAuthentication parameter
  227.     '-------------------------------------------------------------------------
  228.     Dim iVarType As Integer     'Variant type code of lAuthentication
  229.     gbUseDCOM = bUseDCOM
  230.     If Not IsMissing(sProtocol) Then
  231.         If VarType(sProtocol) = vbString Then gsProtocol = sProtocol
  232.     End If
  233.     If Not IsMissing(lAuthentication) Then
  234.         iVarType = VarType(lAuthentication)
  235.         If iVarType = vbLong Or iVarType = vbInteger Or iVarType = vbDouble Or iVarType = vbSingle Then
  236.             glAuthentication = lAuthentication
  237.         End If
  238.     End If
  239. End Sub
  240.  
  241. Public Function CreateWorkers(ByVal bRemoteWorkers As Boolean, Optional ByVal lWorkerQuantity As Variant, _
  242.                                     Optional ByVal lWorkersPerMachine As Variant, Optional ByVal vaMachineList As Variant, _
  243.                                     Optional ByVal bUseLocalMachine As Variant) As String
  244. Attribute CreateWorkers.VB_Description = "Creates AEWorker.Worker objects.  Returns a string that describes any errors that occurred."
  245.     '-------------------------------------------------------------------------
  246.     'Purpose:   Sets the settings for remote workers.  These settings provide
  247.     '           The PoolMgr the information needed to create Workers on several
  248.     '           remote machines rather than just the local one.
  249.     'IN:
  250.     '   [bRemoteWorkers]
  251.     '           If true, the PoolMgr will create Workers on remote machines.
  252.     '           If false, the PoolMgr will only create Workers on the local machine.
  253.     '   [lWorkerQuantity]
  254.     '           The total number of Workers to be created.
  255.     '   [lWorkersPerMachine]
  256.     '           A variant long specifing the maximum allowed number of Workers
  257.     '           to create on a single machine.
  258.     '   [vaMachineList]
  259.     '           A string array, providing the list of machine names
  260.     '           to create the workers on.  If this is not a valid
  261.     '           array of strings it will be treated like no machine
  262.     '           names were specified
  263.     '   [bUseLocalMachine]
  264.     '           If true, include local machine in list of remote machine names
  265.     'Return:    String to display to user and print to log file.  Will contain
  266.     '           any error information and the total number of workers created
  267.     '-------------------------------------------------------------------------
  268.                                     
  269.     Static stbUseDCOM As Boolean     'Last DCom automation setting used
  270.     Static stsProtocol As String     'Last Automation protocol setting used
  271.     Static stlAuthentication As Long 'Last Automation Authentication setting used
  272.     Dim sResult As String   'Result of SetWorkersOnMachine function
  273.     Dim sErrors As String   'String with error descriptions to return for
  274.                             'display to user
  275.     Dim oWorkerMachine As clsWorkerMachines 'Object in gcWorkerMachines collection
  276.                                             'that stores how many workers are instanciated
  277.                                             'on a particular machine
  278.     Dim lUB As Long         'Ubound of passed array
  279.     Dim bListExists As Boolean  'True if a array of machine names exists
  280.     Dim bInList As Boolean  'If true the Machine Name is in the passed array
  281.     Dim i As Integer        'For...Next loop counter
  282.     Dim lAdd As Long        'Number of Workers to add on machine
  283.     Dim lNumOnMach As Long  'Number of workers on a machine
  284.     Dim iVarType As Integer 'Variant data type of a parameter
  285.     
  286.     On Error GoTo CreateWorkersError
  287.     
  288.     'Validate the parameters
  289.     'validate lWorkerQuantity
  290.     iVarType = VarType(lWorkerQuantity)
  291.     If Not (iVarType = vbLong Or iVarType = vbInteger Or iVarType = vbSingle Or iVarType = vbDouble) Then
  292.         Err.Raise giINVALID_PARAMETER, , LoadResString(giINVALID_PARAMETER)
  293.     End If
  294.     If bRemoteWorkers Then
  295.         'validate vaMachineList
  296.         iVarType = VarType(vaMachineList)
  297.         If (iVarType = vbArray + vbString) Or (iVarType = vbArray + vbVariant) Then
  298.             On Error Resume Next
  299.             lUB = UBound(vaMachineList)
  300.             If Err.Number <> ERR_SUBSCRIPT_OUT_OF_RANGE Then
  301.                 bListExists = True
  302.             End If
  303.             On Error GoTo CreateWorkersError
  304.         End If
  305.         'validate lworkerspermachine
  306.         iVarType = VarType(lWorkersPerMachine)
  307.         If Not (iVarType = vbLong Or iVarType = vbInteger Or iVarType = vbSingle Or iVarType = vbDouble) Then
  308.             Err.Raise giINVALID_PARAMETER, , LoadResString(giINVALID_PARAMETER)
  309.         End If
  310.         'validate bUseLocalMachine
  311.         On Error Resume Next
  312.         bUseLocalMachine = CBool(bUseLocalMachine)
  313.         If Err.Number = ERR_TYPE_MISMATCH Then
  314.             On Error GoTo CreateWorkersError
  315.             Err.Raise giINVALID_PARAMETER, , LoadResString(giINVALID_PARAMETER)
  316.         Else
  317.             On Error GoTo CreateWorkersError
  318.         End If
  319.     End If
  320.     
  321.     'First destroy all workers that can not be used any more
  322.     'If connection settings have been changed or if bRemoteWorkers
  323.     'is false all Workers on remote machines must be destroyed
  324.     If (Not bRemoteWorkers) Or (stbUseDCOM <> gbUseDCOM) Or (stsProtocol <> gsProtocol) Or (stlAuthentication <> glAuthentication) Then
  325.         'Reset the Last Connection setting static variables
  326.         stbUseDCOM = gbUseDCOM
  327.         stsProtocol = gsProtocol
  328.         stlAuthentication = glAuthentication
  329.         'Destroy all remote Workers
  330.         For Each oWorkerMachine In gcWorkerMachines
  331.             If oWorkerMachine.Remote Then
  332.                 sResult = SetWorkersOnMachine(True, oWorkerMachine.MachineName, 0)
  333.                 sErrors = sErrors & sResult
  334.             End If
  335.         Next
  336.     Else
  337.         'If we did not destroy all workers on remote machines
  338.         'destroy workers that are on machines that are not
  339.         'in the passed list of remote worker machines
  340.         
  341.         'Check if the machine names currently in gcWorkerMachines
  342.         'are in the passed array
  343.         For Each oWorkerMachine In gcWorkerMachines
  344.             If oWorkerMachine.Remote Then
  345.                 bInList = False
  346.                 If bListExists Then
  347.                     For i = 0 To lUB
  348.                         If vaMachineList(i) = oWorkerMachine.MachineName Then
  349.                             bInList = True
  350.                             Exit For
  351.                         End If
  352.                     Next
  353.                 End If
  354.                 If Not bInList Then
  355.                     sResult = SetWorkersOnMachine(True, oWorkerMachine.MachineName, 0)
  356.                     sErrors = sErrors & sResult
  357.                 End If
  358.             End If
  359.         Next
  360.     End If
  361.     
  362.     'See if Workers on local machine need destroyed
  363.     If bRemoteWorkers Then
  364.         If Not bUseLocalMachine Then
  365.             sResult = SetWorkersOnMachine(False, "", 0)
  366.             sErrors = sErrors & sResult
  367.         End If
  368.     End If
  369.     
  370.     'Create Workers
  371.     If Not bRemoteWorkers Then
  372.         'Just create all workers on local machine
  373.         sResult = SetWorkersOnMachine(False, "", CLng(lWorkerQuantity))
  374.         sErrors = sErrors & sResult
  375.     Else
  376.         'Now loop through machine name list and add workers
  377.         'to each machine until giWorkerCount equals
  378.         'lWorkerQuantity or the end of the machine list is
  379.         'reached
  380.         If giWorkerCount <= lWorkerQuantity Then
  381.             'First create workers on local machine
  382.             If bUseLocalMachine Then
  383.                 'Get the number of workers currently on this machine
  384.                 lNumOnMach = gcWorkerMachines.Item(1).WorkerKeys.Count
  385.                 'Set number of Workers to be on current machine
  386.                 lAdd = lWorkersPerMachine
  387.                 If lAdd > (lWorkerQuantity + lNumOnMach) - giWorkerCount Then lAdd = (lWorkerQuantity + lNumOnMach) - giWorkerCount
  388.                 sResult = SetWorkersOnMachine(False, "", lAdd)
  389.                 sErrors = sErrors & sResult
  390.             End If
  391.             
  392.             If bListExists Then
  393.                 Do Until (i > lUB Or giWorkerCount = lWorkerQuantity)
  394.                     On Error Resume Next
  395.                     'Get the number of workers currently on this machine
  396.                     Set oWorkerMachine = gcWorkerMachines.Item(vaMachineList(i))
  397.                     If Err.Number = ERR_INVALID_PROCEDURE_CALL Then
  398.                         lNumOnMach = 0
  399.                     Else
  400.                         lNumOnMach = oWorkerMachine.WorkerKeys.Count
  401.                     End If
  402.                     On Error GoTo CreateWorkersError
  403.                     'Set number of Workers to be on current machine
  404.                     lAdd = lWorkersPerMachine
  405.                     If lAdd > (lWorkerQuantity + lNumOnMach) - giWorkerCount Then lAdd = (lWorkerQuantity + lNumOnMach) - giWorkerCount
  406.                     sResult = SetWorkersOnMachine(True, CStr(vaMachineList(i)), lAdd)
  407.                     sErrors = sErrors & sResult
  408.                     i = i + 1
  409.                 Loop
  410.             End If
  411.         Else
  412.             'There may be too many workers, so destroy workers to
  413.             'make the right count
  414.             If bListExists Then
  415.                 i = lUB
  416.                 Do While i >= 0
  417.                     On Error Resume Next
  418.                     'Get the number of workers currently on this machine
  419.                     Set oWorkerMachine = gcWorkerMachines.Item(vaMachineList(i))
  420.                     If Err.Number = ERR_INVALID_PROCEDURE_CALL Then
  421.                         lNumOnMach = 0
  422.                     Else
  423.                         lNumOnMach = oWorkerMachine.WorkerKeys.Count
  424.                     End If
  425.                     On Error GoTo CreateWorkersError
  426.                     If lNumOnMach > 0 Then
  427.                         lAdd = 0
  428.                         If lNumOnMach > (giWorkerCount - lWorkerQuantity) Then lAdd = lNumOnMach - (giWorkerCount - lWorkerQuantity)
  429.                         sResult = SetWorkersOnMachine(True, CStr(vaMachineList(i)), lAdd)
  430.                         sErrors = sErrors & sResult
  431.                     End If
  432.                     i = i - 1
  433.                 Loop
  434.             End If
  435.             
  436.             'if there are still too many workers
  437.             'reduce the number of workers on the local machine
  438.             If giWorkerCount > lWorkerQuantity Then
  439.                 lNumOnMach = gcWorkerMachines.Item(1).WorkerKeys.Count
  440.                 lAdd = 0
  441.                 If lNumOnMach > (giWorkerCount - lWorkerQuantity) Then lAdd = lNumOnMach - (giWorkerCount - lWorkerQuantity)
  442.                 sResult = SetWorkersOnMachine(False, "", lAdd)
  443.                 sErrors = sErrors & sResult
  444.             End If
  445.         End If
  446.     End If
  447.     
  448.     'Check if any workers were created and raise error if none were created
  449.     If giWorkerCount < lWorkerQuantity Then
  450.         If giWorkerCount = 0 Then
  451.             Err.Raise giNO_WORKERS_CREATED, , sErrors & vbCrLf & LoadResString(giNO_WORKERS_CREATED)
  452.         Else
  453.             sErrors = sErrors & vbCrLf & ReplaceString(LoadResString(giONLY_N_WORKERS_CREATED), gsNUMBER_TOKEN, CStr(giWorkerCount))
  454.         End If
  455.     Else
  456.         sErrors = sErrors & vbCrLf & LoadResString(giALL_WORKERS_CREATED)
  457.     End If
  458.     
  459.     CreateWorkers = sErrors
  460.     Exit Function
  461. CreateWorkersError:
  462.     Select Case Err.Number
  463.         Case Is > giERROR_THRESHOLD
  464.             Err.Raise Err.Number + vbObjectError, Err.Source, Err.Description
  465.         Case Else
  466.             Err.Raise Err.Number, Err.Source, Err.Description
  467.     End Select
  468. End Function
  469.  
  470. Public Function GetRemoteLoggerCollection() As Collection
  471. Attribute GetRemoteLoggerCollection.VB_Description = "Returns a collection of remote AELogger.Logger objects that were created by remote AEWorker.Worker objects."
  472.     '-------------------------------------------------------------------------
  473.     'Purpose:   Returnse the collection of loggers created on the same
  474.     '           machines as remote Workers
  475.     'Assumes:
  476.     '   [gcWorkerMachines]
  477.     '           a valid collection of clsWorkerMachines object
  478.     '   [clsWorkerMachines]
  479.     '           If .Remote is true .WorkerKeys.Count is > 0
  480.     '-------------------------------------------------------------------------
  481.     Dim cRemoteLoggers As Collection        'Collection to return
  482.     Dim oWorkerMachine As clsWorkerMachines 'Object representing each Worker machine
  483.     Dim oLogger As AELogger.Logger          'Valid logger object or nothing
  484.     
  485.     Set cRemoteLoggers = New Collection
  486.     
  487.     For Each oWorkerMachine In gcWorkerMachines
  488.         With oWorkerMachine
  489.             If .Remote Then
  490.                 Set oLogger = gcWorkers.Item(CStr(.WorkerKeys(1))).Worker.GetLogger
  491.                 If Not oLogger Is Nothing Then
  492.                     cRemoteLoggers.Add oLogger
  493.                 End If
  494.             End If
  495.         End With
  496.     Next
  497.     If cRemoteLoggers.Count = 0 Then Set cRemoteLoggers = Nothing
  498.     Set GetRemoteLoggerCollection = cRemoteLoggers
  499. End Function
  500.  
  501. Public Sub LoadServiceObject(ByVal ServiceLibClass As String)
  502. Attribute LoadServiceObject.VB_Description = "Causes all created AEWorker.Worker objects to create an object whose ProgID matches ServiceLibClass."
  503.     '-------------------------------------------------------------------------
  504.     'Purpose:   Purpose is to call LoadServiceObject method in each
  505.     '           instanciated worker.  It is ignored if gbPeristentServices
  506.     '           is false
  507.     'Assumes:
  508.     '   [gcWorkers]
  509.     '           Is a collection of valid AEWorker.Worker objects
  510.     '-------------------------------------------------------------------------
  511.     Dim oWork As clsWorker
  512.     If gbPersistentServices Then
  513.         For Each oWork In gcWorkers
  514.             oWork.Worker.LoadServiceObject ServiceLibClass
  515.         Next oWork
  516.     End If
  517. End Sub
  518.  
  519. Public Sub StopTest()
  520. Attribute StopTest.VB_Description = "Notifies AEPoolMgr that Worker requests and releases are being stopped."
  521.     '-------------------------------------------------------------------------
  522.     'Purpose:   Stops all Pool Managers processes
  523.     '   [gbStopTest]
  524.     '           Becomes true
  525.     '-------------------------------------------------------------------------
  526.     'Call this to halt the Pool Manager and the Expediter
  527.     gbStopTest = True
  528.     Exit Sub
  529. End Sub
  530.  
  531. Public Sub StartTest()
  532. Attribute StartTest.VB_Description = "Prepares the AEPoolMgr to manage AEWorker.Worker objects after StopTest has been called."
  533.     '-------------------------------------------------------------------------
  534.     'Purpose:   Call this to allow processing of GetWorker calls
  535.     'Effects:
  536.     '           Resets U/I to look like PoolMgr just started
  537.     '           Call Workers StartTest method to reset them
  538.     '   [gbStopTest]
  539.     '           Becomes False
  540.     '-------------------------------------------------------------------------
  541.     Dim oWork As clsWorker
  542.     Dim iRetry As Integer
  543.     
  544.     'Reset stats
  545.     gbStopTest = False
  546.     glRequestsSatisfied = 0
  547.     glRequestsRejected = 0
  548.     If gbShow Then
  549.         With frmPoolMgr
  550.             .lblStatus.Caption = ""
  551.             .lblWorkers.Caption = CStr(giWorkerCount)
  552.             .lblSatisfied.Caption = 0
  553.             .lblRejected.Caption = 0
  554.         End With
  555.     End If
  556.     Exit Sub
  557. StartTestError:
  558.     Select Case Err.Number
  559.         Case RPC_E_CALL_REJECTED
  560.             'Collision error, the OLE server is busy
  561.             Dim il As Integer
  562.             Dim ir As Integer
  563.             'First check for stop test
  564.             If iRetry < giMAX_ALLOWED_RETRIES Then
  565.                 iRetry = iRetry + 1
  566.                 ir = Int((giRETRY_WAIT_MAX - giRETRY_WAIT_MIN + 1) * Rnd + giRETRY_WAIT_MIN)
  567.                 For il = 0 To ir
  568.                     DoEvents
  569.                 Next il
  570.                 LogEvent giCALL_REJECTED_RETRY
  571.                 Resume
  572.             Else
  573.                 'We reached our max retries
  574.                 Resume Next
  575.             End If
  576.         Case Else
  577.             Err.Raise Err.Number, Err.Source, Err.Description
  578.     End Select
  579. End Sub
  580.  
  581. '********************
  582. 'Private Procedures
  583. '********************
  584.  
  585. Private Sub Class_Initialize()
  586.     CountInitialize
  587. End Sub
  588.     
  589. Private Sub Class_Terminate()
  590.     CountTerminate
  591. End Sub
  592.