project BLF > class ComponentPool > method StartComponentInPool

Description

Returns the handle to a business component, as it is needed by instance procedures to add to their super procedure stack.
The component pool keeps a list of all components running persistently in memory. It will first look for a component that is not in use by other instance procedures. When found it will return that handle, otherwise it will run the business component.


Parameters


icProcListinputcharacter
icUserDefinedContextinputcharacter
ohProchoutputhandle
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program1/componentpool.p)

if oiReturnStatus = 0
then oiReturnStatus = -98.

assign vcProcName = entry(num-entries(icProcList),icProcList).

if vcProcName = "bcustom"
then assign vcProcName = vcProcName + "[" + icUserDefinedContext + "]".

find first bsCPool where
           bsCPool.tcName = vcProcName and
           bsCPool.tlIsInUse = no and
           bsCPool.tlIsInMemory = yes
           no-error.
if available bsCPool
then assign bsCPool.tlIsInUse = yes
            ohProch = bsCPool.thProc.
else do:
    do viFcCount1 = 1 to num-entries(icProcList):
        if viFcCount1 > 1
        then assign vcProcList = vcProcList + ",".

        assign vcProcListEntry = entry(viFcCount1, icProcList)
               vcProcList      = vcProcList + "program/" + vcProcListEntry + ".p"
               vhFcComponent   = vhCustomizationController.

        if <M-7 IsCustomized
              (input  vcProcListEntry (icComponentName), 
               input  icUserDefinedContext (icUserDefinedContext)) in CustomizationController>
        then assign vcProcList = vcProcList + ",custprogram/" + vcProcListEntry + ".p".
    end.
    
    /* check top level (not included in icProcList) */
    vhFcComponent = vhCustomizationController.
    if <M-8 IsCustomized
          (input  'business' (icComponentName), 
           input  '' (icUserDefinedContext)) in CustomizationController>
    then vcProcList = "custprogram/business.p," + vcProcList.
    
    run program/business.p persistent set vhBusiness (input ?, output viFcReturnSuper).
    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.

    run StartComponentWorker in vhBusiness (input vcProclist, output ohProch, output viFcReturnSuper).
    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.

    run MainBlock in ohProch (output viFcReturnSuper).
    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.

    /*start customization*/
    assign vhFcComponent = vhCustomizationController.
    <M-6 run StartCustomization
       (input  ohProch (ihProgram), 
        input  icUserDefinedContext (icUserDefinedContext), 
        output viFcReturnSuper (oiReturnStatus)) in CustomizationController>
    if viFcReturnSuper <> 0
    then oiReturnStatus = viFcReturnSuper.
    if viFcReturnSuper < 0
    then return.

    vlROC = can-find (first tComponentPool where
                            tComponentPool.tcName = vcProcName and
                            tComponentPool.tlIsInUse = yes).

    find first bsCPool where
               bsCPool.tcName = vcProcName and
               bsCPool.tlIsInUse = no and
               bsCPool.tlIsInMemory = no
               no-error.
    if not available bsCPool
    then create bsCPool.
    
    assign bsCPool.tcName = vcProcName
           bsCPool.thProc = ohProch
           bsCPool.tlIsInUse = yes
           bsCPool.tlIsInMemory = yes
           bsCPool.tlRemoveOnClose = vlROC.

    run gipr_ComponentSize in ohProch (output bsCPool.tiComponentSize).
    run gipr_CreateState in ohProch.

    viComponentCount = viComponentCount + 1.
end.

assign bsCPool.tiRequestCount = bsCPool.tiRequestCount + 1.

if viComponentLimit = 0
then do:
    assign vcProcName = search ("server.xml":U)
           viComponentLimit = 20.

    if vcProcName <> ?
    then do:
        assign vhFcComponent = ?.
        <M-1 run MainBlock () in XML>
        assign vhXMLhandle = vhFcComponent.

        <M-2 run ReadXMLNodeValue
           (input  vcProcName (icXMLFile), 
            input  'components':U (icStartTag), 
            input  'swaplimit':U (icNodeTag), 
            output vcSwapLimit (ocNodeValue), 
            output viFcReturnSuper (oiReturnStatus)) in XML>
        run gipr_DeleteProcedure in vhXMLhandle.
        delete procedure vhXMLHandle.
        if viFcReturnSuper <> 0
        then assign oiReturnStatus = viFcReturnSuper.
        if viFcReturnSuper < 0
        then return.
    
        if vcSwapLimit <> ""
        then assign viComponentLimit = integer(vcSwapLimit) no-error.
    end.
end.

viRemoveCount = viComponentLimit / 5 + 1.
if viComponentCount > viComponentLimit
then for each bsCPool where
              bsCPool.tlIsInUse = no and
              bsCPool.tlIsInMemory = yes
           by bsCPool.tiRequestCount
           by bsCPool.tiComponentSize:
    <M-3 run RemoveComponent  (input  rowid(bsCPool) (irCPoolRowid)) in ComponentPool>
    viRemoveCount = viRemoveCount - 1.
    if viRemoveCount < 1 then leave.
end.

if oiReturnStatus = -98
then oiReturnStatus = 0.