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
UploaderService is now a thing. #180
Created a Service. Refactored the completeQueuedTasks() to use polymorphism. Switching on a type was evil, so I created a retry() method in each task. The tasks that need to be retried implement the abstract method.
Little more refactoring in each task so that instead of calling EventBus directly, they call a method in AbstractDataManagerTask to tryPushLater(). This has the effect of calling DataManager.startUploaderService().
Please, don't start UploaderService yourself. I have no idea what happens if two of them are running at once. Use DataManager.startUploaderService() if you really have to (but you shouldn't).
Also, did a bunch of magic with concurrent collections so that it should work. Used a BlockingQueue instead of an ArrayList in the EventBus. Synchronized keywords abound. Also, some neat queue stuff in UploaderService so we don't have an infinite loop trying to upload stuff while offline.
Loads and loads of comments everywhere explaining magic things I think were a good idea at the time :P.
@stephenjust should look at how I check network connectivity in remoteDataStore using the hasAccess() method. It may make sense to replace what I put in there with a dummy call to ElasticSearch and see if it works.
I don't necessarily agree that the network connectivity check belongs in RemoteDataStore as it doesn't actually tell you if you can access the datastore or not. The server could be down, you could have a network connection, but no access to the internet, etc. This is why I never used hasAccess (and I think I removed it at least once).
As you have also identified, polling is probably not ideal. Take a look at this Stack Overflow question: http://stackoverflow.com/questions/1783117/network-listener-android - this means that every time the network state changes, you can actually have the system notify your app rather than you asking the system.