Skip to content

Repository files navigation

saqua

Simple Android Queue ( Useful for Async )

What is it

This is Android/Java library with simple Queue interface and it persistent implementation used build in Android SQLite. It help perform async exchange with remote servers in case of unstable network connection.

Naming

Originally saqua - a fancy alcohol drink from Endmond Hamilton's cosmic opera "The Star Kings". "A cursed good drink!" as main person say about it. So, why not.

Example usage

Initializing

publicclassAppextendsApplication {
...
// Init DB Queue factory, must be performed before obtained first queue SimpleDBQueueFactory.initFactory(getApplicationContext());
...
}

Produce messages

publicvoidstoreDocument(DocumentdocToStore) {
SimpleDBQueuebackupQueue = SimpleDBQueueFactory.getQueue("backup_documents");
backupQueue.push(docToStore, ImmutableMap.of("collection", backupCollection));
SimpleDBQueuedocsQueue = SimpleDBQueueFactory.getQueue("documents");
docsQueue.push(docToStore); }

Consume messages

publicclassBackupDocumentsServiceextendsAsyncTask {
@OverrideprotectedObjectdoInBackground(Object[] params) {
SimpleDBQueuequeue = SimpleDBQueueFactory.getQueue("backup_documents");
while (!queue.isEmpty()) {
SimpleQueueMessagemessage = queue.pull();
StringbackupCollection = message.getHeaders().get("backup_collection");
if (backupCollection == null) {
queue.Ack(); // wrong record, skip
} else {
objectToStore = message.getBody();
if (RemoteService.storeBackupObject(backupCollection, objectToStore)) {
queue.Ack();
} else {
queue.NAck();
}
}
}
returnnull;
}
}

About

Simple Android Queue ( Useful for Async )

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages