-
Notifications
You must be signed in to change notification settings - Fork 549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HandlerThread for reconnecting AWSIoTMqttManager #619
HandlerThread for reconnecting AWSIoTMqttManager #619
Conversation
Merged source into fork
Merged source into branch
# Conflicts: # aws-android-sdk-iot/src/main/java/com/amazonaws/mobileconnectors/iot/AWSIotMqttManager.java
Hi @rvp-thunderbuild , How does this pull request differ from #601 which creates and disposes of the handler thread when execution is completed? |
Pull request #601 merely cleans up the handler thread after reconnecting. My proposed changes make use of a single handler thread instead of instantiating a new one each reconnect attempt. And also use this thread for publishing queued messages after a successful reconnect attempt instead of running these on the main thread. |
@rvp-thunderbuild Sorry for the delayed response. Can you rebase the changes with the current master and update the PR? |
public void run() { | ||
if (!mqttMessageQueue.isEmpty()) { | ||
if (connectionState == MqttManagerConnectionState.Connected) { | ||
if (mReconnectHandlerThread != null && mReconnectHandler != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice a difference here: The HandlerThread you created uses its looper whereas the existing code here uses the looper from the main thread. Do you have any reasoning behind this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe that the main thread should be responsible for publishing messages from the Queue since this is network related. Originally the first message was published by the reconnecting thread, while all successive messages where published by the main thread. I changed this so that all queued message will be published by the reconnecting thread instead.
This makes more sense to me since either there is no connection and that thread is being used te reestablish it or there is a connection and that thread can be used to publish queued messages.
# Conflicts: # aws-android-sdk-iot/src/main/java/com/amazonaws/mobileconnectors/iot/AWSIotMqttManager.java
@rvp-thunderbuild Sorry for the delayed response. Can you rebase the changes with the latest changes from master and remove the changes in .idea/ files? |
@kvasukib I merged the master branch into this one and updated the .idea/ files |
@rvp-thunderbuild Sorry for the delayed response. I see that the following 4 unit tests failed. Can you take a look at them if you have some cycles?
The tests are located here: https://github.com/aws-amplify/aws-sdk-android/blob/master/aws-android-sdk-iot/src/test/java/com/amazonaws/mobileconnectors/iot/AWSIotMqttManagerTest.java |
@kvasukib Those unit tests seem to fail because the |
@rvp-thunderbuild We will work on to update our unit tests to accommodate the changes you have made in this PR. Your effort is much appreciated! |
1008b5d
to
13a2264
Compare
This PR unfortunately has gone stale before it could be addressed. Will close for now. Please re-open if it can be updated. |
Added a separate HandlerThread for reconnect attempts and publishing of queued messages.
This way the former doesn't need to happen on a newly created thread each time, and the latter no longer runs on the Main thread (since that is really not the best place).
This issue was mentioned before:
#532