B4J Question SOLVED [ABMaterial] Timers and Jetty time out

alienhunter

Active Member
Licensed User
Longtime User
Hi
I am a bit puzzled ,why in ABM 4.03 when i work with a timer update some values in the
CustomGauges i will get Jetty timeouts after a while .
It worked before in a earlier version of ABM for about more then 2 year no problem.
The timer just calls the Mysql and updates the gauge value and refreshes the gauge. I rewrote the app 6 times different
ways now without luck.
Everything works perfect without a timer , i can press 1000 times the reload page does not loose the connection .
I am missing something ...:(..
Any one had something like this ?

here is the code

B4X:
Sub timerx_Tick
    loadusersx
End Sub

Sub loadusersx
timerx.Enabled=False

Dim SQLCOMP As SQL = DBM.GetSQL

Dim users As List=DBM.SQLSelect(SQLCOMP, sb, Null)
    For i = 0 To users.Size-1
        Dim userx As Map= users.Get(i)
          
        Dim xx As String=userx.Get("servidn")
        Dim x1 As Double=userx.Get("totali")
        Dim x2 As Int=userx.Get("totalu")
        
        If xx.EndsWith("90") Then
            custGauge1.myValue = x2
            custGauge1.maxval = x1
            custGauge1.ABMComp.Refresh
        Else If xx.EndsWith("91") Then
            custGauge2.myValue = x2
            custGauge2.maxval = x1
            custGauge2.ABMComp.Refresh
        Else If xx.EndsWith("92") Then
            custGauge3.myValue = x2
            custGauge3.maxval = x1
            custGauge3.ABMComp.Refresh
        Else If xx.EndsWith("93") Then
            custGauge4.myValue = x2
            custGauge4.maxval = x1
            custGauge4.ABMComp.Refresh
        Else If xx.EndsWith("95") Then
            custGauge5.myValue = x2
            custGauge5.maxval = x1
            custGauge5.ABMComp.Refresh
        Else If xx.EndsWith("68") Then
            custGauge6.myValue = x2
            custGauge6.maxval = x1
            custGauge6.ABMComp.Refresh
        Else If xx.EndsWith("09") Then
            custGauge7.myValue = x2
            custGauge7.maxval = x1
            custGauge7.ABMComp.Refresh
        End If
    
    Next

    DBM.CloseSQL(SQLCOMP)
timerx.Enabled=True
    page.Refresh
        
End Sub



thanks AH
 

mindful

Active Member
Licensed User
It would of help if you posted the actual error ...

Also setting the timerx.Enabled at the begining and end of the sub doesn't do anything because subs or code from timers won't run twice or overlap.

As you are using timers are you disabling them in websocket_disconnect ?

Also I think it's safe to close the sql right after you execute the select query because the result set is copied to a list of maps (i am not using DBM).

Also another important thing would be at what interval is the timer set?
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
the sub doesn't do anything because subs or code from timers won't run twice or overlap

Is this true? I was under the impression that the timer would fire the code regardless...
As per AH, I disable - then re-enable the timer to prevent long running methods from stomping the next call from a timer running each second...

As you are using timers are you disabling them in websocket_disconnect ?

As like in Android Pause, timers should be disabled ( ? ) in this method. Enable on connect - disable upon disconnect seems logical.

I also await a resolve since I update a page using very similar design.

Thanks
 
Upvote 0

alienhunter

Active Member
Licensed User
Longtime User
It would of help if you posted the actual error ...

Also setting the timerx.Enabled at the begining and end of the sub doesn't do anything because subs or code from timers won't run twice or overlap.

As you are using timers are you disabling them in websocket_disconnect ?

Also I think it's safe to close the sql right after you execute the select query because the result set is copied to a list of maps (i am not using DBM).

Also another important thing would be at what interval is the timer set?


hi
thanks for the reply

as harris i was under the impression the timers will stop and fire
and yes i disable the timer in disconnect an the timer is set for one minute
the dbm.close is there because i have 24 different calls to the database so i do not open and close each time, the code here is just a part of all.
as i said it worked this way in version ABM 3.0 for almost 1 year or so that is the reason why i do not understand what is wrong . the skeleton of the app is
from the feedback app now just to avoid old code errors , which works until i run timers.
i upgraded to the 161 java , maybe there is something wrong with that . i am stumped why i get ws disconected when running the sub


preparing for url refresh
Disconnected
Connected
Waiting for value (101 ms)
Saving the first instance
Waiting for value (100 ms)
Websocket first connection
Waiting for value (100 ms)
ABM_TEBISMAIN667fcb99-ac9b-454f-8ba5-82e7367fa706
preparing for url refresh
Disconnected
Connected
Saving the first instance
Error occurred on line: 0
java.lang.RuntimeException: org.eclipse.jetty.websocket.api.WebSocketException: RemoteEndpoint unavailable, current state [CLOSED], expecting [OPEN or CONNECTED]
at anywheresoftware.b4j.object.WebSocket.get(WebSocket.java:120)
at anywheresoftware.b4j.object.WebSocket.RunFunctionWithResult(WebSocket.java:308)
at com.ab.abmaterial.ABMPage.WebsocketReconnected(Unknown Source)
at abmfeedback.ab.com.abm_tebismain._websocket_connected(abm_tebismain.java:1498)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:188)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:30)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:26)
at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:114)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:148)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:303)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
 
Last edited:
Upvote 0

alienhunter

Active Member
Licensed User
Longtime User
Hi thanks for all , it was chrome spitting in my soup for some reason
and ABM.EnablePassiveEventListeners=False it helped a lot , now it works perfect .
thanks AH
 
Upvote 0
Top