deepstreamIO / deepstream.io-client-java

The Java/Android Client for deepstream.io
Other
35 stars 37 forks source link

Optimize socket reconnect strategy #100

Closed nephdev closed 7 years ago

nephdev commented 7 years ago

Right now connection reconnect strategy is implemented to repeatedly (3 times be default) try reconnection and then drop it. This is sufficient enough for local desktop apps which are connected to internet almost always but when working on Android device can lost network connectivity for many reasons. I have implemented global connection state variable which indicates whether network connection is available or not. To use it correctly you must call setGlobalConnectivityState(GlobalConnectivityState globalConnectivityState) as soon as you know network state after initialization. This defaults to DISCONNECTED and it blocks any reconnect attempts.

It would be much better to implement Android networkStateListener directyl into deepstream library but since this is java/android client I don't want to narrow it to Android only client.

yasserf commented 7 years ago

This looks really good thanks.

Would you be okay with signing our CLA?

Also will make a couple small suggestions, but otherwise happy to merge!

nephdev commented 7 years ago

CLA signed. I have added new comit which replaces NO_NETWORK_CONENCTIVITY with CLOSED state. There was no reason to implement NO_NETWORK_CONNECTIVITY and it was causing strange behaviour on app close. For example when app goes offline during runtime and then it was closed sockets were not properly closed. With this version sockets are closed properly.

yasserf commented 7 years ago

Looks good, many thanks!

Build is actually passing, its trying to deploy it that seems to not work (which is fine).