Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Fully Multi-threaded DataManager #154
This is the pull request you've been waiting for.
All events in the datamanager are multi-threaded on background worker threads. We are now using Callbacks to extract results where we need them in activities. I've gone through the activities and set all the callbacks to null. If the callback on a data manager method is null, the datamanager method runs just as before, and still blocks the UI thread. If you set the callbacks, then the datamanager request you like runs in the background.
I have also fixed the large elephant in the room: How does stuff from the phone move to the Internet? Before we had a local datastore and a remote datastore. The local store is still around for cached things. Now, however, there is an EventBus that stores events. These events are XXXPushDelayedEvents. The EventBus maintains a queue of events. Right now there is a method in datamanager called completeQueuedEvents(). Call this, and all the queued events will be popped off the queue, and "tried again". If they again fail to be pushed to the internet, then the worker thread will put them back onto the eventbus. We just need a worker thread to be calling this method in the background every now and then (when we have internet access preferably), and our datamanager will be fully pushing the latest user's content to the internet.
If you're writing in the datastores and need multi-threaded functions, you have the choice of instantiating a Task object (within the data.threading package) and simply passing a callback. Beware that these are wrapped in the datamanager to update the recentVisited list and other lists. Only instantiate the tasks if you're absolutely sure you know what you're doing and don't want sideeffects of updating lists the user may see.
If you're in an activity and need the datamanager to do something, you can "rough in" those method calls with a null callback and it behaves just as before. You can gradually re-write your activity calls to the datamanager to create callback inner classes, get results from them, etc to get full multi-threading.
I am not completely sure on this but I thought if we author a post it gets saved to local datastore regardless of whether or not we have internet access. If this is true we do not save to local datastore if there is internet access. Other than that it looks very nifty :)
Sorting by favorites is broken (NPE on favQ.get.....). A cursory look at sorting shows that some of them work.
If the team is interested in pulling this sooner rather than later, I think it is now okay to be pulled. It only has very minor bugs. Pretty much the entire code-base has been touched at some point.