Http Utils2 Synchronous Asynchronous or just plain Krazy ? !

CharlesIPTI

Active Member
Licensed User
Longtime User
I don't have a GOOD concrete example but could someone please attempt to educate me ... :sign0163:

With this CallSubDelayed method now in HttpUtils2 I find that the tasks (calls) are going by so swiftly that method calls I have blocked out in my Activity create by boolean flags are actually being called before the boolean flags have been set to allow entry into the code portion of Activity_Create that invokes the Calls to HttpUtil2..

How do I adequately describe this...

This isnt the offending section but it will adequately assist my description..
theres a code section ( most of these examples are in activity_Create ) above this first example that fills a list from repeated calls to a HttpUtil2's call to a web service. As you all know this lands in job_done and the job_Done sub calls a related XML Sax parser to truly fill my list object. ( you you guessed it a Global Uggg) :eek:

I had to introduce this counter because the boolean flag was being set before the list was completely filled .. allowing entry into the UI creation portion which you can imagine is a NIGHTMARE... views atop views atop more views. all now mis labled and chaos-'ed up .... in another section [My current concern] I had to create a Map and throw id's into the Map and check if they were there already to prevent their re creation from the redundant Perhaps too fast re entry into a call to the HttpUtil2 to again fill some list...

C'mon people help me out here.. I honestly understand async & sync. I understand polling and callbacks but this is killing me forcing me to write code I'm assuredly not fond of let alone proud of.. for a RAD tool Rapid application development - Wikipedia, the free encyclopedia its becoming quite laborious and frustrating. Assuredly this could be my lack of understanding some basic concept in this use of the tool and its add ons..(HttpUtils2) Please advise ASAP!!!! :sign0085: :sign0104:

B4X:
#Region----------------------{ User Interface creation }--------------------------
'-----------{ xyz }-  ----Left   Top   Width   Height-------   ' 1280 x 800Reference


   If  bBeginUiCreation Then                   
            subSpecificCounter = subSpecificCounter + 1   
            
                     If subSpecificCounter < 2 Then    
                     
         '                  Msgbox("Number of Loops Through UI Creation Block: " & subSpecificCounter, "COUNT UI Loops ")
         '                  If bPreventReCleanUI = False Then
         '                     CleanHouse
         '                     End If
         '                  

                     #Region---------------------{  Create header }--------------------
                                          
                                          
                                          bPreventReCleanUI = True
                                          panHeader.Initialize("")      
                                          panHeader = uiLogic.InitHeaderBlock(panHeader)      
                                          Activity.AddView(panHeader,0%x,0%y,1280dip,80dip)

                     #End Region


B4X:
'#3    Get Order Assignments If MapList has been obtained 
                  If mapLocList.Size > 1  AND bOrderAssignmentListCreated = False Then                                                                                                               
                     FetchOrderAssignments    ' Fills lstOrderAssignments sets flag 'CallToHttpUtil2 inside of this method
                     mapDuplicatePrevention.Initialize
                  End If 
'

B4X:
#Region ---------------------------{   OrderAssignments  EXIST  }----------------------


         If bOrderAssignmentListCreated AND iOrdAssignmentListSize > 0 Then        'OAssignment list created and OAList has content / Count                 
               
               If bOrderAssignmentsToMainLst = False Then                                                         'Process of adding assignments to MAIN Source List hasnt been completed                                                                                                  
               
                        
                        AssimilateOrderAssignments   'CallToHttpUtil2 inside of method that this calls

                  
                  
                  'bOrderAssignmentsToMainLst = true its been completed                                  
              Else                                                         
                  If iRemainderBins >  0 Then                                                                                         'slots remain for scan based acquisition                                                                                           
                           If bMapLocScanCompleted = False Then                                                      ' Force ScanCurrentLoc to Fill Remining Bins                                          
                                 Activity.LoadLayout("lo_ScanLocation")                                                   
                                 Return ' Break out of this                                                                                              
                           End If
                                          ' next loop when bMapLocScanCompleted = true
                           If  bLocationScanValidated = False Then
                               ValidateScannedMapLocation  'CallToHttpUtil2
                           End If                                                                                                    
                                       ' next loop when bLocationScanValidated = true
                           If bMapLocOrderListCreated = False Then                                                   ' Boolean Toggle True When iRemainderBins decremented to 0                                                                                 AssimililateOrders 'CallToHttpUtil2 inside of method that this calls
                                                                                 'GetNext Order & Assign Order to Cart --> into recall Activity_Create(False)
                           End If
                  Else
                           bMapLocOrderListCreated = True
                           bBeginUiCreation = True
                        'CalculateNextAvailablePosition
                  End If                                                                                                                  
            End If
         End If
#End Region

B4X:
Sub AssimilateOrderAssignments


'bins to create = Max - SizeOf OAlst


      If iOrdAssignmentListSize <= MAX_BIN_COUNT Then         
         iRemainderBins = MAX_BIN_COUNT - iOrdAssignmentListSize
      End If 
                                                                                                                  
   If iordAssignmentsToMainListCounter < MAX_BIN_COUNT Then
   
            If iordAssignmentsToMainListCounter < iOrdAssignmentListSize      Then   
               
               lclOrdAssign = lstOrderAssignments.Get(iordAssignmentsToMainListCounter)               
               m_CartPosition = lclOrdAssign.pos      
               
               m_cartState.orderID = lclOrdAssign.ordId    

               If mapDuplicatePrevention.ContainsKey(lclOrdAssign.ordId) = False Then
                     mapDuplicatePrevention.Put(lclOrdAssign.ordId,lclOrdAssign)                     
                                                                                                                           'Msgbox("OrderId Sent To Method: " &    m_cartState.orderID , "FetchOrderByID")                        
               FetchOrderByID  'CallToHttpUtil2 looped - JobDone calls Activity_Create
               Else 
               ' DO NOTHING  Assuredly not add the Duplicate 
               Msgbox("Preventing Duplication : " & m_cartState.orderID, "FetchOrderByID")
               End If
               
               'DoEvents
                              
            End If
   Else   
         If iordAssignmentsToMainListCounter = MAX_BIN_COUNT Then
               bBeginUiCreation = True               
         End If
   End If   

   End Sub




Check this out,,,,,, that last call to FetchOrderByID returns and calls itself again with the same ID before its Job Done can complete...heck even before job done is called
for earlier tasks not to mention even before job done is called using the first orderId, its already trying to do it again with the same orderid which if I recall correctly is called by a counter / incrementer----> List.Get(counter/incrementer) which is incremented when the results are added to the list ... Yea I checked the incrementeer is in the job_done versus the parser not like it mattered where I placed it
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
As I previously wrote you I don't recommend you to call Activity_Create yourself.
CallSubDelayed will start the activity and create it if needed.

Unless your are using Agrahams Threading library, your code always runs in the same thread, the main thread. The asynchronous behavior of HttpClient library means that you send a request and when the request is ready you handle the event. The main thread doesn't block while the request is handled.
 
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Response

Thank you .. so again please help me understand this more thoroughly..

If I Call GoGetMeSomeData which itself uses HttpUtils no-where in any of the subs, relate to this process of calls GoGetMeSomeData , its Job_Done nor its parser should I call Activity_Create. I understand you have made this clear.

So how to accomplish the task then?

Then in the activity_Create where I am Calling GoGetMeSomeData should it then be inclosed in a do while or something to "pause" [if you will] the progress of code in activity_create since the remainder of the sub Activity_Create requires the results of the call to GoGetMeSomeData ...
and so on and so on.... there's a dependent chain here of data acquisition required to build the UI ...

even in a do while -- the code of course just keeps processing past this section and on to the next section
in activity_Create which doesnt have its results from the previous call out to a Sub that uses HttpUtils2
to continue its portion of the task

Again some other section will now require the results of GoGetMeSomeData in order to again go do some more HttpUtil2 work.. ultimately so the UI Views can be dynamically generated based upon this data...


How do I guarantee I get back

SetA
then SetB
then SetC

so they can be sequentially assembled to create the resulting UI elements..


This is a VERY important question for my design .... :confused:

Thank You So much for your time and assistance I earnestly appreciate it
 
Last edited:
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Thank you

That helped a little for a specific scenario.. but I have another situation where I am making several repeated calls to Http Util2.

But These several calls operate on the contents of a list one element at a time.

But two or three manipulations are done to each object. -- THATS Three seperate Calls to Three Separate HttpUtil2 methods per object in sequence
And again these must be done in order..

example I have a list of Wiggles, each Wiggle must be painted, stamped and renumbered with a special tag.

I have to process each Wiggle from my lstWiggles and send each one through THREE separate Calls to HttpUtils2..

Of course as it is presently structured the job_done isn't finished for the paint method callwhen its already trying to do the stamped and renumbered method calls to HttpUtils2..etc etc..

Please advise


thank you .. Heres my failed attempts in code as I have tried the Job done as well as a sub to house all the calls as they are called from the Activity_Create all to no avail Thank you


B4X:
' sub AssimililateOrders  is called conditionally from Activity_create
'when I need to harvest orders based upon a scan from an handheld scanner---   
' next loop when bLocationScanValidated = true
If bMapLocOrderListCreated = False Then   
' Boolean Toggle True When iRemainderBins decremented to 0         
AssimililateOrders   'GetNext Order & Assign Order to Cart --> into recall Activity_Create(False)
End If
Else
bMapLocOrderListCreated = True




Sub AssimililateOrders()
 
    intCurrentBinNo = lstOrders.Size

'    If intCurrentBinNo < MAX_BIN_COUNT Then
      
      
      If  lstOrders.Size  > 0 Then
               If iRemainderBins > 0 Then

                                    DoEvents
                              GetNextOrder  'cycle this until  MAX_BIN_COUNT         
                                    DoEvents
                              CalculateNextAvailablePosition                      
                                    DoEvents
                              AssignOrderToCart
                                    DoEvents 
                     
             End If
      End If

End Sub


B4X:
' section of job done in select case statement 


#Region------------{ GetNextOrder  }--------------------

                  Case "GetNextOrder"         
                  
                  iStream = Job.GetInputStream()      'PostGetNextOrder
                  GetNextOrderParser.Initialize         
                              
                  If iStream.BytesAvailable > 0 Then                                       
                        GetNextOrderParser.Parse(iStream, "GetNextOrderParser")            '                                                                                                                                                               
                  Else   
                        Msgbox("Http GetNextOrderParser ERROR: " & CRLF &  LastException.Message,  "GetNextOrderParser")                                          
                  End If                                                
                                          
                     DoEvents
                     'DebugInfo                                                               
'                      CalculateNextAvailablePosition                      
'                     AssignOrderToCart
'                                                
         'Activity_Create(False)   'Multi Process GetNext Then AddToCart no activity_Create here

#End Region
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You need to somehow organize your objects and HttpJobs in a way that can be simple to track.

Maybe each "wiggie" object should have 3 different HttpJobs. You can also modify HttpJob class and add a Next HttpJob field. This way in JobDone you can check whether Next IsInitialized and then automatically submit the next job (like a linked list).
 
Upvote 0
Top