Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Cherry-pick to release agua #10633

Merged
merged 7 commits into from
Dec 6, 2017
Merged

Cherry-pick to release agua #10633

merged 7 commits into from
Dec 6, 2017

Conversation

tobrun
Copy link
Member

@tobrun tobrun commented Dec 5, 2017

@tobrun tobrun added the Android Mapbox Maps SDK for Android label Dec 5, 2017
@tobrun tobrun added this to the android-v5.2.1 milestone Dec 5, 2017
@tobrun tobrun self-assigned this Dec 5, 2017
private final List<OnCameraMoveCanceledListener> onCameraMoveCanceledListenerList = new ArrayList<>();
private final List<OnCameraMoveListener> onCameraMoveListenerList = new ArrayList<>();
private final List<OnCameraIdleListener> onCameraIdleListenerList = new ArrayList<>();
private final CopyOnWriteArrayList<OnCameraMoveStartedListener> onCameraMoveStarted = new CopyOnWriteArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tobrun Adding CopyOnWriteArrayList makes it thread-safe, but may result in a rare scenario when user unregisters the listener, yet still gets the callback. Do you think we should add synchronization?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't ran into any issues with that or haven't heard about any reports. The reason why I don't perceive this as an issue is that the interactions with this list allows occurs on the main thread.
The reason why we have a CopyOnWriteArrayList is to allow to remove the listener as part of it's callback to avoid a ConcurrentModificationException. Imo your remark is a tradeoff of this, happy to look more into this if there is a use-case for it.

Copy link
Contributor

@LukasPaczos LukasPaczos Dec 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem arises when you'd like to register/unregister on a separate thread (which in my scenario would have thrown ConcurrentModificationException before and now will just execute the callback). Since your use-case is concrete and the problem was there before anyway, just in a different form, I think we're good here.

The reason why I don't perceive this as an issue is that the interactions with this list allows occurs on the main thread.

Maybe adding @UiThread annotation when registering in MapboxMap would be nice if we expect users to register/unregister on the main thread?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We annotate the class with @UiThread, which is the equivalent to adding the annotation to each method of the class. Would love to see if we can improve the implementation in future iterations ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We annotate the class with @UiThread

Missed that, totally makes sense :)

tobrun and others added 2 commits December 6, 2017 11:55
… handle multiple deactivate scenario in FileSource (#10556)
Because a message we queue from the foreground may cause the background to complete, exit, and tear down the AsyncTask, we have to block queue processing until we've finished our call to AsyncTask::send().
Broadening the scope of a mutex is scary, but I audited the code of our four implementations of AsyncTask and I don't see any way this could cause a deadlock.
@tobrun tobrun merged commit 966b6a5 into release-agua Dec 6, 2017
@tobrun tobrun deleted the tvn-cherry-pick-latest branch December 6, 2017 11:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants