CMPUT301F14T14/Project — pull request #154 by linster (2014-11-19 06:20:30+00:00)
Title: Fully Multi-threaded DataManager

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.