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

Fully Multi-threaded DataManager #154

Merged
merged 25 commits into from Nov 20, 2014

Conversation

Projects
None yet
3 participants
@linster
Copy link
Contributor

linster commented Nov 19, 2014

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.

linster added some commits Nov 18, 2014

Removed username stuff from DataManager
Now in ClientData only. Fixed bugs.
Moved all favorite stuff in ClientData
Ripped it out of data manager.
REFACTORED ReadLater into ClientData.
Ripped it out of DataManager. Fixed some lovely wtfs.
Fixing Tests.
Still have DataManagerTests to write.
GetQuestion sorta done
Changed it to a void. Callbacks should manually fetch the question they
need out of the thread.

Lots of breaking. Will fix.
GetAnswer is now complete in the DM.
Changed to return Void. Lots of breakage expected all throughout the
app. Will fix.
Sprinkled some comments about null callbacks
Null callbacks cause datamanager methods to act in UI blocking mode. We
can incrementally write callbacks in the rest of the app to gradually
get us into multithreading.
GetQuestionComment now multithreaded.
When I added the Callback parameter, nothing broke. Someone needs to
make sure we are actually calling this in the app.
GetAnswerComment now multithreaded
Nothing broke when I changed the function signature. Need to make sure
it's actually being called.
getCommentList now multithreaded.
Again, changing the function signature didn't break things.
GetCommentList (Question) now multithreaded
Once again, function signatures didn't break things.
@linster

This comment has been minimized.

Copy link
Contributor Author

linster commented Nov 19, 2014

For some reason eclipse didn't give errors for mismatched argument lengths in the dialog fragments.

linster added some commits Nov 19, 2014

Fixed build errors
DialogFragments weren't updated with null callbacks
@sdwowk

This comment has been minimized.

Copy link
Contributor

sdwowk commented Nov 19, 2014

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 :)

@linster

This comment has been minimized.

Copy link
Contributor Author

linster commented Nov 19, 2014

Apparently AsyncTasks can't spawn sub-AsyncTasks as they are in the same thread pool. Don't merge this PR yet.

linster added some commits Nov 19, 2014

Changed null callback behavior
AsyncTasks cannot be nested. Created a blockingRun() method in the
AbstractDataManagerTask class that runs doInBackground() and just gets
that result in the currenthread.
Adding a Question works again.
AddQuestionTask wasn't storing to LocalDataStore for some reason.

Still need to fix varargs on most stuff in DataManager.
More features working
Comments to questions, favoriting questions, upvoting questions.
Mostly feature complete.
Tested everything except sorting.
Remove gross hack
Woops, left this in for testing.
@linster

This comment has been minimized.

Copy link
Contributor Author

linster commented Nov 20, 2014

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.

@sdwowk

This comment has been minimized.

Copy link
Contributor

sdwowk commented Nov 20, 2014

I can fix the sorting stuff

@Kopo101

This comment has been minimized.

Copy link
Contributor

Kopo101 commented Nov 20, 2014

I believe in you Scott

linster added a commit that referenced this pull request Nov 20, 2014

Merge pull request #154 from linster/callbackdm
Fully Multi-threaded DataManager

@linster linster merged commit f29746e into CMPUT301F14T14:master Nov 20, 2014

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment