2
votes

I have a question regarding Cloudant.

Basically, we have an application which aims to coordinate a common time for people to meet up when they are free, which will be indicated by their "voting" on the app.

So here's the thing, we've figured out how to start Pull Replication from Cloudant, and any changes will then be updated in our database. Let's call this method onReceiveUpdate().

Our current approach is to encase this onReceiveUpdate() method in an infinite loop, within a service, as so:

@Override
protected Void doInBackground(Void... params) {
    while (true) {
        onReceiveUpdate();
    }
return null;
}

Obviously, this is a bad design, which I realized when my phone started overheating. I decided to read more, and came across Cloudant's Eventbus/Event

However, I wasn't sure if this would allow me to be notified when there are changes made to Cloundant's database. So I went and research more and found Google Cloud Messaging.

My approach now is:

  1. Set up documents for each users.
  2. Any changes relevant to the user, will result in their corresponding documents being modified.
  3. Cloudant will then notify Google Cloud Messaging of the fact that a document has been modified. And hence it should send a notification to Google Cloud Messaging ,tagged with the relevant registration ID.
  4. Google Cloud Messaging should then inform the relevant user (through the registration ID) of updates, which will then finally result in the actual user calling onReceiveUpdate().

Question: How do I implement step 3? That is to say, how do I ensure that Cloudant will send a "send properly formatted requests to the GCM connection server" (from here), if and when there are changes made? I read through their documentation, but I didn't catch anything yet.

Otherwise, is there any other less battery-intensive alternative to pull replication from Cloudant?

1
is this while loop on server side? why is your client hitting up? If not just query the app server and only when there's an update pass to CCS (GCM server) that way the client is drained unnecessarily. - Kay_N
@KayAnn It's a while loop on the client-side. Yes, I realised that, although I'm not sure about how to go about ensuring that the App Server (Cloudant) can send information to GCM only when there are changes made. - fer

1 Answers

1
votes

Cloudant won't tell GCM that changes have been made. The best way to know if changes have been made to the database is using the changes feed. As you receive the changes, your server code will need to decide which client (if any) needs to be told via GCM to replicate with the server.